rslt ← pvec ##.lsys axiom                   ⍝ Lindenmayer L-system expansion.

Inspired by a workshop at the Dublin Functional Kats Meetup group:

[pvec] is a vector of "production" pairs.  [axiom]  is  a  starting  string  and
[rslt] is the corresponding vector after substitution of all productions.

[lsys] will typically be applied under the power operator ⍣ to produce ⍵⍵ "iter-
ations" of the substitutions.

Ref: https://en.wikipedia.org/wiki/L-system

[lsys] may be used in conjunction with →turtle← to display fractal images.

Examples:

    algae ← ('A' 'AB')('B' 'A')             ⍝ Algae: A→AB, B→A

    algae lsys ⊢'A'                         ⍝ rewrite of axiom 'A'
AB
    algae lsys⍣2 ⊢'A'                       ⍝ 2nd iteration: A→AB→ABA
ABA
    algae lsys⍣7 ⊢'A'                       ⍝ 7th iteration
ABAABABAABAABABAABABAABAABABAABAAB

    dragon ← ('X' 'X+YF+')('Y' '-FX-Y')     ⍝ Dragon curve: X→X+YF+, Y→-FX-Y
    dragon lsys⍣3 ⊢'FX'                     ⍝ 3rd iteration, starting from FX
FX+YF++-FX-YF++-FX+YF+--FX-YF+

See also: turtle

Back to: contents

Back to: Workspaces