cases_expr: Create an expression that tests patterns against an...

Description Usage Arguments Functions Examples

View source: R/cases.R

Description

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.

Usage

1
2
3
cases_expr_(expr, ...)

cases_expr(expr, ...)

Arguments

expr

The expression to test against. This is usually a bare symbol.

...

Pattern matching rules as in cases.

Functions

Examples

 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)))))

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