Description Usage Arguments Functions Examples
Where cases
evaluates expressions based on pattern matches,
this function creates a long if-else expression that tests patterns in turn
and evaluate the expression for a matching pattern. This function is intended
for meta-programming rather than usual pattern matching.
1 2 3 | cases_expr_(expr, ...)
cases_expr(expr, ...)
|
expr |
The expression to test against. This is usually a bare symbol. |
... |
Pattern matching rules as in |
cases_expr_
: Version that expects expr
to be quoted.
cases_expr
: Version that quotes expr
itself.
1 2 3 4 5 6 7 8 9 10 | linked_list := NIL | CONS(car, cdr : linked_list)
length_body <- cases_expr(
lst,
NIL -> acc,
CONS(car, cdr) -> ll_length(cdr, acc + 1))
length_body
ll_length <- rlang::new_function(alist(lst=, acc = 0), length_body)
ll_length(CONS(1, CONS(2, CONS(3, CONS(4, NIL)))))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.