R/cases.R
This function is used when you want to test for more than one pattern in parallel.
..(...)
... | The patterns/expressions to combine |
---|
If you want to test two or more patterns against the same number of values,
then you can use this function to combine the values and expressions
in a cases()
(or related) function.
llist := NIL | CONS(car, cdr : llist) compare_llists <- function(l1, l2) { cases(..(l1, l2), ..(NIL, NIL) -> TRUE, ..(NIL, .) -> FALSE, ..(., NIL) -> FALSE, ..(CONS(car1,cdr1), CONS(car2,cdr2)) -> car1 == car2 && compare_llists(cdr1, cdr2) ) } compare_llists(NIL, NIL)#> [1] TRUEcompare_llists(CONS(1, NIL), CONS(1, NIL))#> [1] TRUEcompare_llists(CONS(1, NIL), NIL)#> [1] FALSEcompare_llists(CONS(1, NIL), CONS(2, NIL))#> [1] FALSE