Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm not familiar with Logo. How are you supposed to know where parentheses are implicitly opened and closed?


If you know the valence (argument count) of a given word, you know how many following expressions to read, recursively. Parens in s-exprs simply make the valence an explicit syntactic feature of each evaluation. Some dialects of Logo have procedures which permit a variable number of arguments, and in those cases you might be required to include parens.

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.


Oh, that makes sense. Your explanation made me realize I was assuming a few things about the language that apparently aren't true. Thank you.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: