Learn R Programming

lambda.r (version 1.1.0-3)

introspection: Introspection for lambda.r

Description

These tools are used for debugging and provide a means of examining the evaluation order of the function definitions as well as provide a lambda.r compatible debugger.

Usage

describe(...)
debug.lr(x)
undebug.lr(x)
## S3 method for class 'lambdar.fun':
print(x, \dots)
## S3 method for class 'lambdar.type':
print(x, \dots)

Arguments

x
The function
...
Additional arguments

Value

  • The defined functions are invisibly returned.

Details

For a basic description of the function it is easiest to just type the function name in the shell. This will call the print methods and print a clean output of the function definition. The definition is organized based on each function clause. If a type constraint exists, this precedes the clause signature including guards. To reduce clutter, the actual body of the function clause is not printed. To view a clause body, each clause is prefixed with an index number, which can be used in the describe function to get a full listing of the function.

describe(fn, idx)

The 'debug.lr' and 'undebug.lr' functions are replacements for the built-in debug and undebug functions. They provide a mechanism to debug a complete function, which is compatible with the dispatching in lambda.r. The semantics is identical to the built-ins.

Examples

Run this code
# Type constraints are optional and include the return type
reciprocal(x) %::% numeric : numeric
reciprocal(x) %when% {
  # Guard statements can be added in succession
  x != 0
} %as% {
  # The function body follows
  1 / x
}

reciprocal(x) %::% character : numeric
reciprocal(x) %as% {
  reciprocal(as.numeric(x))
}

seal(reciprocal)
describe(reciprocal, 2)

Run the code above in your browser using DataLab