> 1. A few chapters from now, when Lox supports first-class functions and dynamic
dispatch, we technically won’t need branching statements built into the
language. Show how conditional execution can be implemented in terms of those.
Name a language that uses this technique for its control flow.
Smalltalk? Lox doesn't have dictionaries, but in Ruby:
```ruby
def if_(cond, t, f)
{ true => t, false => f }[cond].()
end
```
> 2. Likewise, looping can be implemented using those same tools, provided our
interpreter supports an important optimization. What is it, and why is it
necessary? Name a language that uses this technique for iteration.
Tail recursion, Lisp?
FossilOrigin-Name: aec62b2632ecda95e950b0ea1a2cc7605db12f28cbbaf579f62519a4d5679aa4
Too lazy to look into how to keep individual commits with unrelated histories
FossilOrigin-Name: 0d3362887de6be5ddf4d357073e35a38c897485f97b796930bbe49ac1f58cbba
> The lexical grammars of Python and Haskell are not regular. What does that
> mean, and why aren’t they?
Regular languages can be parsed with an FSM, but Python and Haskell's grammars
more context than that to be determined.
> Aside from separating tokens—distinguishing `print foo` from
> `printfoo`—spaces aren’t used for much in most languages. However, in a
> couple of dark corners, a space does affect how code is parsed in
> CoffeeScript, Ruby, and the C preprocessor. Where and what effect does it
> have in each of those languages?
Spaces do matter for the closing of heredocs in Ruby...
> Our scanner here, like most, discards comments and whitespace since those
> aren’t needed by the parser. Why might you want to write a scanner that does
> not discard those? What would it be useful for?
Formatting or documentation generation?
FossilOrigin-Name: 5738a38b8f15d1aca61212966ff990de59a03502f183a7400bf4f2ea14ae5af6
> 2. This informal introduction leaves a lot unspecified. List several open
> questions you have about the language’s syntax and semantics. What do you
> think the answers should be?
- String escaping, Unicode?
- Interaction with the system (i.e., exit status code)?
- What are the built-in errors?
- What happens when we all a function with the wrong number of arguments? It
would be cool if it were curried...
- Multiple inheritance?
> 3. Lox is a pretty tiny language. What features do you think it is missing
> that would make it annoying to use for real programs? (Aside from the
> standard library, of course.)
No way to interact with the outside world, whether that's files, stdin, or
networking. No parallelization. Somewhat reminiscent of Lua, really.
FossilOrigin-Name: 394141a0b92ff762adcc54b53e4a04786a5374ad42fe312be5c20b6666dbb3f5