3 ms·
Your article is confused between code walking (recognition of forms) and evaluation order. Code is generally walked top down for the purposes of expansion of ma
by kazinator 8y ago
Your article is confused between code walking (recognition of forms) and evaluation order. Code is generally walked top down for the purposes of expansion of macros, compilation or interpretation. Evaluation of nested expressions is generally bottom-up, and in well-behaved Lisp dialects, left-to-right.
You cannot simply let your eyes randomly land on some (a b c) in Lisp code and assume that a is a function being called with arguments b c. You have to read the whole sentences and phrases, so to speak.
No language is immune to this. Can you assume that * X is a pointer dereference? No, it could be a declarator. Or a fragment of a multiplicative expression. Or the interior of a comment as in /* X.
(a, b) could be a comma expression, or the argument list of a function call.
I can't think of any language in which I can extract any substring of a sentence that could be a syntactic unit on its own, and correctly understand its meaning without knowing the rest of the sentence.
Lisp has to be scanned from the outside in: we have a defun, which encloses a let, and so on.
When you're familiar with the piece of code you're working on, you can then take considerable shortcuts. You know you're in the middle of a function, even though the defun is off the screen. You know you're in the middle of the progn-like body of some construct (a loop, or let or whatever), so all the lines of code you see are evaluated forms.
- heinrichhartman 8y ago> Your article is confused between code walking (recognition of forms) and evaluation order. Yes, to some extend. > Can you assume that * X is a pointer dereference? [Aside: The C declaration syntax is particularly terrible. In a declaration 'star' means "address of", elsewhere it means "dereference". https://books.google.de/books?id=bXGhBAAAQBAJ&printsec=frontcover&dq=21st+century+C+pointer+declaration+syntax&hl=en&sa=X&ved=0ahUKEwjil_ShpYTeAhWNiKYKHfZ5CAYQ6AEIJzAA#v=onepage&q=21st%20century%20C%20pointer%20declaration%20syntax&f=false https://books.google.de/books?id=bXGhBAAAQBAJ&printsec=front...] > I can't think of any language in which I can extract any substring of a sentence that could be a syntactic unit on its own, and correctly understand its meaning without knowing the rest of the sentence. Well, most languages have expressions/statements that roughly correspond to source lines. When I read a line of python like this: self.raw_requestline = self.rfile.readline(65537) https://github.com/django/django/blob/master/django/core/servers/basehttp.py#L139 https://github.com/django/django/blob/master/django/core/ser... I can be 100% sure that: - `self` is an object with an attribute rfile - `=` is the assignment operator - there is a method `readline` that get's called with an integer argument 65537. All this without checking any enclosing socpes. A random line of lisp: (setcdr current (list :args (cdr current))) https://github.com/emacs-mirror/emacs/blob/master/lisp/wid-edit.el#L742 https://github.com/emacs-mirror/emacs/blob/master/lisp/wid-e... could mean anything depending on the enclosing scopes. Pretty sure setcdr,list,cdr are function calls but who knows. You don't have enough information to decide this from the snippet provided.
- kbp 8y ago> I can be 100% sure that: `self` is an object with an attribute rfile, `=` is the assignment operator, there is a method `readline` that get's called with an integer argument 65537. I think this is overstating things, eg, the class `self` belongs to might have defined __getattribute__, __setattr__, etc, so the things you know for 100% certain about that line of code in isolation don't really tell you anything about what it does (self does not definitely have that attribute, and that might not be assignment, at least); most of that you assume based on common sense, conventions, figuring the code is "normal", etc, the same as in Lisp. And that's ignoring a trivial case like if the previous line was `f('''`, where f may or may or not call eval.