Description Usage Arguments Value See Also Examples

Given an expression of a type defined by the `:=`

operator,
`cases`

matches it against patterns until it find one that has the same
structure as `expr`

. When it does, it evaluates the expression the
pattern is associated with. During matching, any symbol that is not
quasi-quoted will be considered a variable, and matching values will be bound
to such variables and be available when an expression is evaluated.

1 |

`expr` |
The value the patterns will be matched against. |

`...` |
A list of |

The value of the expression associated with the first matching pattern.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ```
linked_list := NIL | CONS(car, cdr : linked_list)
lst <- CONS(1, CONS(2, CONS(3, NIL)))
len <- function(lst, acc = 0) {
cases(lst,
NIL -> acc,
CONS(car,cdr) -> len(cdr, acc + 1))
}
len(lst)
list_sum <- function(lst, acc = 0) {
cases(lst,
NIL -> acc,
CONS(car,cdr) -> list_sum(cdr, acc + car))
}
list_sum(lst)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.