dotdot: Function for specifying a sequence of patterns/expressions

Description Usage Arguments Details Examples

Description

This function is used when you want to test for more than one pattern in parallel.

Usage

1

Arguments

...

The patterns/expressions to combine

Details

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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)
compare_llists(CONS(1, NIL), CONS(1, NIL))
compare_llists(CONS(1, NIL), NIL)
compare_llists(CONS(1, NIL), CONS(2, NIL))

pmatch documentation built on Oct. 19, 2018, 5:04 p.m.