by RodgerTheGreat · 5y ago · 0 comments
item random size :list :list
(item (random (size :list)) :list)
It poses challenges for making parse-trees, though, especially since Logo traditionally has dynamic scope: you can't actually know the valence of a function until it is evaluated!In the places where you need a list (or block), square brackets are used. for example, a classic turtle-graphics phrase:
repeat 4 [forward 10 right 90]
The primitive `repeat` takes a number and a list, and evaluates the list. The list consists of the primitive `forward`, which takes a number, and then the primitive `right` which takes a number.As for how you parse Logo expressions into a tree form, the strategy I've taken in my interpreters is "don't". Parse everything into flat lists of words, and then at interpretation time peel off words one at a time, measure their valence, and recur.