2 ms·
Parsing s-expressions requires on-the-fly allocation of memory and something resembling recursion. Parsing any code requires on-the-fly allocation of memory be
by phoe-krk 9y ago
Parsing s-expressions requires on-the-fly allocation of memory and something resembling recursion.
Parsing any code requires on-the-fly allocation of memory because your function can contain 10 or 100 or 1000 lines of code and, when you are at the beginning, you don't know how long the whole function is.
Parsing any code requires something resembling recursion because your function can contain 3 or 10 or 20 nested scopes and, when you are at the beginning, you don't know how deep the whole function is.
Of course that you can say that you can pre-read the code and compute how much memory you need beforehand, but that applies to Lisp as much as it applies to any other language.
- bsder 9y ago> Parsing any code requires on-the-fly allocation of memory because your function can contain 10 or 100 or 1000 lines of code and, when you are at the beginning, you don't know how long the whole function is. This is not necessarily true. Parsing a language can be bounded by the grammar. If you don't have indefinitely nested structures (like arithmetic open parentheses), your parsing is linear and you can bound the memory (ie. your parsing memory cannot be longer than your input string, for example). I believe that Tcl and Microsoft Basic fell into this category. (I believe that Ousterhout used to actually generate code in the input buffer behind the current parsing point precisely because Tcl was designed to do this). > Parsing any code requires something resembling recursion because your function can contain 3 or 10 or 20 nested scopes and, when you are at the beginning, you don't know how deep the whole function is. Indefinitely nested lexical scoping is not a requirement for a language. Famously Javascript screws up all manner of programmers because they expect that to be true, but it is not. And many languages start out with a single global scope and grow lexical scoping only after they gain some complexity.
- pubby 9y agoI'm a little confused at where you're coming from. Do you program microcontrollers or something? Since when has recursion or the ability to allocate memory been an issue? 30 years ago, maybe? I understand lisp isn't trivial to implement if all you have is assembly with no OS or libraries, but beyond that it's pretty damn easy. Even in C it only takes a few dozen lines. > Javascript I'm not a JS programmer, but I think JS has had infinite lexical scope at function-level since the beginning. It does not have scope at block-level, which is the confusing part.
- tripzilch 9y agoHow is this relevant? Nobody said that "Parsing any code is super easy".