Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "loop"

Index

Functions

Const defLoop

  • Higher order word. Takes a test and body stack program. Applies test to copy of TOS and executes body. Repeats while test is truthy.

    ( -- ? )

    example
    run([loop([dup, ispos], [dup, print, dec])], [[3]])
    // 3
    // 2
    // 1
    // [ true, [ 0 ], undefined ]

    Parameters

    Returns (Anonymous function)

Const dotimes

  • Executes given body word/quotation n times. In each iteration pushes current counter on d-stack prior to executing body.

    example
    pf.run([3, ["i=", pf.swap, pf.add, pf.print], pf.dotimes])
    // i=0
    // i=1
    // i=2

    With empty body acts as finite range generator 0 .. n:

    // range gen
    pf.run([3, [], pf.dotimes])
    [ [ 0, 1, 2 ], [], {} ]
    
    // range gen (collect results as array)
    pf.runU([3, pf.cpdr, [], pf.dotimes, pf.movrd, pf.collect])
    // [ 0, 1, 2 ]

    ( n body -- ? )

    Parameters

    Returns StackContext

Const loopq

Generated using TypeDoc