programlibs/Tags/demos/turtle.xtl

A turtle on a grid: its heading is one of four choices, its state a tagged tuple of a position, a heading and a count of steps -- parts of different types, used by name. e_num< names the choices, p_arts< the parts; both write plain definitions when the program is compiled. Turns and moves are tables indexed by the heading, not branches. Run with "just demo Tags turtle".

source · imports tg: libs/Tags/src/Tags.xtlm

NORTH : Int

value · line 10
@ ᵗᵍe̲num< "Heading: north east south west"
ᵗᵍe̲num< expands to
NORTH ← 1
EAST ← 2
SOUTH ← 3
WEST ← 4
HEADING ← "north" "east" "south" "west"
Used in: RIGHT, LEFT, start

EAST : Int

value · line 10
@ ᵗᵍe̲num< "Heading: north east south west"
ᵗᵍe̲num< expands to
NORTH ← 1
EAST ← 2
SOUTH ← 3
WEST ← 4
HEADING ← "north" "east" "south" "west"
Used in: RIGHT, LEFT

SOUTH : Int

value · line 10
@ ᵗᵍe̲num< "Heading: north east south west"
ᵗᵍe̲num< expands to
NORTH ← 1
EAST ← 2
SOUTH ← 3
WEST ← 4
HEADING ← "north" "east" "south" "west"
Used in: RIGHT, LEFT

WEST : Int

value · line 10
@ ᵗᵍe̲num< "Heading: north east south west"
ᵗᵍe̲num< expands to
NORTH ← 1
EAST ← 2
SOUTH ← 3
WEST ← 4
HEADING ← "north" "east" "south" "west"
Used in: RIGHT, LEFT

HEADING : Box Char

value · line 10
@ ᵗᵍe̲num< "Heading: north east south west"
ᵗᵍe̲num< expands to
NORTH ← 1
EAST ← 2
SOUTH ← 3
WEST ← 4
HEADING ← "north" "east" "south" "west"

TURTLE : Char

value · line 11
@ ᵗᵍp̲arts< "Turtle: at heading steps"
ᵗᵍp̲arts< expands to
TURTLE ← "Turtle"
ᵘt̲urtle ← { (at, heading, steps) → (TURTLE, at, heading, steps) }
ᵘt̲urtle? ← { (g1:tag, _, _, _) → g1:tag m̲atch TURTLE }
ᵘt̲urtleAt ← { (g1:tag, g2:part, _, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleHeading ← { (g1:tag, _, g2:part, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleSteps ← { (g1:tag, _, _, g2:part) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘs̲etTurtleAt ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch at
  (g1:tag, g3:new, heading, steps)
}
ᵘs̲etTurtleHeading ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch heading
  (g1:tag, at, g3:new, steps)
}
ᵘs̲etTurtleSteps ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch steps
  (g1:tag, at, heading, g3:new)
}
ᵘt̲urtleRows ← { g4:which (g1:tag, at, heading, steps) → (g1:tag, g4:which s̲elect at, g4:which s̲elect heading, g4:which s̲elect steps) }
Used in: TURTLE

ᵘt̲urtle : (Any a, Any b, Any c) => (a, b, c) -> (Char, a, b, c)

function · line 11
@ ᵗᵍp̲arts< "Turtle: at heading steps"
ᵗᵍp̲arts< expands to
TURTLE ← "Turtle"
ᵘt̲urtle ← { (at, heading, steps) → (TURTLE, at, heading, steps) }
ᵘt̲urtle? ← { (g1:tag, _, _, _) → g1:tag m̲atch TURTLE }
ᵘt̲urtleAt ← { (g1:tag, g2:part, _, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleHeading ← { (g1:tag, _, g2:part, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleSteps ← { (g1:tag, _, _, g2:part) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘs̲etTurtleAt ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch at
  (g1:tag, g3:new, heading, steps)
}
ᵘs̲etTurtleHeading ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch heading
  (g1:tag, at, g3:new, steps)
}
ᵘs̲etTurtleSteps ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch steps
  (g1:tag, at, heading, g3:new)
}
ᵘt̲urtleRows ← { g4:which (g1:tag, at, heading, steps) → (g1:tag, g4:which s̲elect at, g4:which s̲elect heading, g4:which s̲elect steps) }
Used in: start

ᵘt̲urtle? : (Any a, Any b, Any c, Truthy d) => (Char, a, b, c) -> d

function · line 11
@ ᵗᵍp̲arts< "Turtle: at heading steps"
ᵗᵍp̲arts< expands to
TURTLE ← "Turtle"
ᵘt̲urtle ← { (at, heading, steps) → (TURTLE, at, heading, steps) }
ᵘt̲urtle? ← { (g1:tag, _, _, _) → g1:tag m̲atch TURTLE }
ᵘt̲urtleAt ← { (g1:tag, g2:part, _, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleHeading ← { (g1:tag, _, g2:part, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleSteps ← { (g1:tag, _, _, g2:part) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘs̲etTurtleAt ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch at
  (g1:tag, g3:new, heading, steps)
}
ᵘs̲etTurtleHeading ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch heading
  (g1:tag, at, g3:new, steps)
}
ᵘs̲etTurtleSteps ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch steps
  (g1:tag, at, heading, g3:new)
}
ᵘt̲urtleRows ← { g4:which (g1:tag, at, heading, steps) → (g1:tag, g4:which s̲elect at, g4:which s̲elect heading, g4:which s̲elect steps) }

ᵘt̲urtleAt : (Any a, Any b, Any c) => (Char, a, b, c) -> a

function · line 11
@ ᵗᵍp̲arts< "Turtle: at heading steps"
ᵗᵍp̲arts< expands to
TURTLE ← "Turtle"
ᵘt̲urtle ← { (at, heading, steps) → (TURTLE, at, heading, steps) }
ᵘt̲urtle? ← { (g1:tag, _, _, _) → g1:tag m̲atch TURTLE }
ᵘt̲urtleAt ← { (g1:tag, g2:part, _, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleHeading ← { (g1:tag, _, g2:part, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleSteps ← { (g1:tag, _, _, g2:part) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘs̲etTurtleAt ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch at
  (g1:tag, g3:new, heading, steps)
}
ᵘs̲etTurtleHeading ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch heading
  (g1:tag, at, g3:new, steps)
}
ᵘs̲etTurtleSteps ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch steps
  (g1:tag, at, heading, g3:new)
}
ᵘt̲urtleRows ← { g4:which (g1:tag, at, heading, steps) → (g1:tag, g4:which s̲elect at, g4:which s̲elect heading, g4:which s̲elect steps) }

ᵘt̲urtleHeading : (Any a, Any b, Any c) => (Char, a, b, c) -> b

function · line 11
@ ᵗᵍp̲arts< "Turtle: at heading steps"
ᵗᵍp̲arts< expands to
TURTLE ← "Turtle"
ᵘt̲urtle ← { (at, heading, steps) → (TURTLE, at, heading, steps) }
ᵘt̲urtle? ← { (g1:tag, _, _, _) → g1:tag m̲atch TURTLE }
ᵘt̲urtleAt ← { (g1:tag, g2:part, _, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleHeading ← { (g1:tag, _, g2:part, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleSteps ← { (g1:tag, _, _, g2:part) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘs̲etTurtleAt ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch at
  (g1:tag, g3:new, heading, steps)
}
ᵘs̲etTurtleHeading ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch heading
  (g1:tag, at, g3:new, steps)
}
ᵘs̲etTurtleSteps ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch steps
  (g1:tag, at, heading, g3:new)
}
ᵘt̲urtleRows ← { g4:which (g1:tag, at, heading, steps) → (g1:tag, g4:which s̲elect at, g4:which s̲elect heading, g4:which s̲elect steps) }

ᵘt̲urtleSteps : (Any a, Any b, Any c) => (Char, a, b, c) -> c

function · line 11
@ ᵗᵍp̲arts< "Turtle: at heading steps"
ᵗᵍp̲arts< expands to
TURTLE ← "Turtle"
ᵘt̲urtle ← { (at, heading, steps) → (TURTLE, at, heading, steps) }
ᵘt̲urtle? ← { (g1:tag, _, _, _) → g1:tag m̲atch TURTLE }
ᵘt̲urtleAt ← { (g1:tag, g2:part, _, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleHeading ← { (g1:tag, _, g2:part, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleSteps ← { (g1:tag, _, _, g2:part) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘs̲etTurtleAt ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch at
  (g1:tag, g3:new, heading, steps)
}
ᵘs̲etTurtleHeading ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch heading
  (g1:tag, at, g3:new, steps)
}
ᵘs̲etTurtleSteps ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch steps
  (g1:tag, at, heading, g3:new)
}
ᵘt̲urtleRows ← { g4:which (g1:tag, at, heading, steps) → (g1:tag, g4:which s̲elect at, g4:which s̲elect heading, g4:which s̲elect steps) }

ᵘs̲etTurtleAt : (Match a, Any b, Any c) => a -> (Char, a, b, c) -> (Char, a, b, c)

function · line 11
@ ᵗᵍp̲arts< "Turtle: at heading steps"
ᵗᵍp̲arts< expands to
TURTLE ← "Turtle"
ᵘt̲urtle ← { (at, heading, steps) → (TURTLE, at, heading, steps) }
ᵘt̲urtle? ← { (g1:tag, _, _, _) → g1:tag m̲atch TURTLE }
ᵘt̲urtleAt ← { (g1:tag, g2:part, _, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleHeading ← { (g1:tag, _, g2:part, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleSteps ← { (g1:tag, _, _, g2:part) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘs̲etTurtleAt ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch at
  (g1:tag, g3:new, heading, steps)
}
ᵘs̲etTurtleHeading ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch heading
  (g1:tag, at, g3:new, steps)
}
ᵘs̲etTurtleSteps ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch steps
  (g1:tag, at, heading, g3:new)
}
ᵘt̲urtleRows ← { g4:which (g1:tag, at, heading, steps) → (g1:tag, g4:which s̲elect at, g4:which s̲elect heading, g4:which s̲elect steps) }
Used in: ᵘf̲orward

ᵘs̲etTurtleHeading : (Match a, Any b, Any c) => a -> (Char, b, a, c) -> (Char, b, a, c)

function · line 11
@ ᵗᵍp̲arts< "Turtle: at heading steps"
ᵗᵍp̲arts< expands to
TURTLE ← "Turtle"
ᵘt̲urtle ← { (at, heading, steps) → (TURTLE, at, heading, steps) }
ᵘt̲urtle? ← { (g1:tag, _, _, _) → g1:tag m̲atch TURTLE }
ᵘt̲urtleAt ← { (g1:tag, g2:part, _, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleHeading ← { (g1:tag, _, g2:part, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleSteps ← { (g1:tag, _, _, g2:part) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘs̲etTurtleAt ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch at
  (g1:tag, g3:new, heading, steps)
}
ᵘs̲etTurtleHeading ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch heading
  (g1:tag, at, g3:new, steps)
}
ᵘs̲etTurtleSteps ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch steps
  (g1:tag, at, heading, g3:new)
}
ᵘt̲urtleRows ← { g4:which (g1:tag, at, heading, steps) → (g1:tag, g4:which s̲elect at, g4:which s̲elect heading, g4:which s̲elect steps) }

ᵘs̲etTurtleSteps : (Match a, Any b, Any c) => a -> (Char, b, c, a) -> (Char, b, c, a)

function · line 11
@ ᵗᵍp̲arts< "Turtle: at heading steps"
ᵗᵍp̲arts< expands to
TURTLE ← "Turtle"
ᵘt̲urtle ← { (at, heading, steps) → (TURTLE, at, heading, steps) }
ᵘt̲urtle? ← { (g1:tag, _, _, _) → g1:tag m̲atch TURTLE }
ᵘt̲urtleAt ← { (g1:tag, g2:part, _, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleHeading ← { (g1:tag, _, g2:part, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleSteps ← { (g1:tag, _, _, g2:part) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘs̲etTurtleAt ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch at
  (g1:tag, g3:new, heading, steps)
}
ᵘs̲etTurtleHeading ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch heading
  (g1:tag, at, g3:new, steps)
}
ᵘs̲etTurtleSteps ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch steps
  (g1:tag, at, heading, g3:new)
}
ᵘt̲urtleRows ← { g4:which (g1:tag, at, heading, steps) → (g1:tag, g4:which s̲elect at, g4:which s̲elect heading, g4:which s̲elect steps) }
Used in: ᵘf̲orward

ᵘt̲urtleRows : Any a => Int -> (a, b, c, d) -> (a, b, c, d)

function · line 11
@ ᵗᵍp̲arts< "Turtle: at heading steps"
ᵗᵍp̲arts< expands to
TURTLE ← "Turtle"
ᵘt̲urtle ← { (at, heading, steps) → (TURTLE, at, heading, steps) }
ᵘt̲urtle? ← { (g1:tag, _, _, _) → g1:tag m̲atch TURTLE }
ᵘt̲urtleAt ← { (g1:tag, g2:part, _, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleHeading ← { (g1:tag, _, g2:part, _) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘt̲urtleSteps ← { (g1:tag, _, _, g2:part) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  g2:part
}
ᵘs̲etTurtleAt ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch at
  (g1:tag, g3:new, heading, steps)
}
ᵘs̲etTurtleHeading ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch heading
  (g1:tag, at, g3:new, steps)
}
ᵘs̲etTurtleSteps ← { g3:new (g1:tag, at, heading, steps) →
  n̲ot g1:tag m̲atch TURTLE ? "wrong-kind" ⎕S̲IGNAL "expected a Turtle"
  _ ← g3:new m̲atch steps
  (g1:tag, at, heading, g3:new)
}
ᵘt̲urtleRows ← { g4:which (g1:tag, at, heading, steps) → (g1:tag, g4:which s̲elect at, g4:which s̲elect heading, g4:which s̲elect steps) }

LEFT : Int

value · line 13
LEFT ← WEST c̲at NORTH c̲at EAST c̲at SOUTH
Used in: ᵘl̲eft

MOVE : Int

value · line 14
MOVE ← 4 2 r̲eshape 0 1 1 0 0 -1 -1 0               ⍝ a step's x and y, by heading
Used in: ᵘf̲orward

ᵘf̲orward : Num a => (Char, Int, Int, a) -> (Char, Int, Int, a)

function · line 16

u:f_orward s: one step the way the turtle faces, counted.

ᵘf̲orward ← { s →
  next ← (ᵘt̲urtleAt s) + (ᵘt̲urtleHeading s) s̲elect MOVE
  next ᵘs̲etTurtleAt (1 + ᵘt̲urtleSteps s) ᵘs̲etTurtleSteps s
}
Used in: up, over, back

ᵘr̲ight : (Any a, Any b) => (Char, a, Int, b) -> (Char, a, Int, b)

function · line 21

u:r_ight s and u:l_eft s: a quarter turn, by table.

ᵘr̲ight ← { s → ((ᵘt̲urtleHeading s) s̲elect RIGHT) ᵘs̲etTurtleHeading s }
Used in: over

ᵘl̲eft : (Any a, Any b) => (Char, a, Int, b) -> (Char, a, Int, b)

function · line 22
ᵘl̲eft ← { s → ((ᵘt̲urtleHeading s) s̲elect LEFT) ᵘs̲etTurtleHeading s }
Used in: back

start : (Char, Int, Int, Int)

value · line 23
start ← ᵘt̲urtle (0 0, NORTH, 0)

up : (Char, Int, Int, Int)

value · line 25
up ← 3 'ᵘf̲orward p̲ower start                       ⍝ three steps north
Used in: over

over : (Char, Int, Int, Int)

value · line 26
over ← 2 'ᵘf̲orward p̲ower ᵘr̲ight up                  ⍝ right, two steps east
Used in: back

back : (Char, Int, Int, Int)

value · line 27
back ← ᵘf̲orward ᵘl̲eft ᵘl̲eft over                    ⍝ about turn, one step west