Output

How to use

  1. Pick an Example from the dropdown, or edit the program in the text area above.
  2. Choose an Evaluation strategy (lazy is the default; parallel examples need lazy).
  3. Click (Re-)Load to parse the program and reset evaluation.
  4. Click Run for automatic step-by-step reduction, or Step for one step at a time.

Evaluation strategies: Call-by-value usually does not terminate on recursive programs (e.g. fibonacci) — the expression keeps growing instead of reducing to a result. Use lazy or call-by-name for those examples. Parallel examples require lazy.

Canvas: drag to pan; click a subterm to focus evaluation (call-by-name and call-by-value only). The red label marks the subexpression reduced next.

Output: put writes numbers to the Output panel below the canvas (space-separated).

Sound: turn up Volume to hear each reduction; enable precise audio timing when using Run with sound.

Back to controls

Language reference

T =
    x                       names ([a-z]+) like x, y, abc, foo, bar, baz
    @ T T                   application
    \ x . T                 abstraction
    Y x . T                 recursion
    123                     number
    + T T                   operators: + - * / % ^ < <= <> > >= ==
    if T then T else T      conditional
    : T T                   cons (pair constructor)
    car T                   left/first/addressregister cons field
    cdr T                   right/second/dataregister cons field
    iscons T                test for cons
    bind T T                binds a return to a function after evaluating the content of return
    return T                wraps a term to avoid evaluation

    not T
    log T
    sqrt T
    ceil T
    floor T
    round T
    put T                   output to Output panel (will be wrapped inside a return)
    alert T                 output to alert window (will be wrapped inside a return)

    random                  get random number (will be wrapped inside a return)
    get                     get number from prompt dialog window (will be wrapped inside a return)

    par T T                 parallel evaluation, result is second term. note: works only with lazy evaluation
                            the first expression will be evaluated seperately; it will vanish as soon as it is evaluated.
                            if the main expression of the program is evaluated, all other (parallel) evaluations stop.

syntactic sugar:

    let x = T1 in T2        ==>  @ (\x.T2) T1
    letrec x = T1 in T2     ==>  @ (\x.T2) (Yx.T1)

Back to controls