3 ms·
If you don't know the syntax of let, then you might find yourself writing (let (x 5) (* x x)) where you should have written (let ((x 5)) (* x x)) That
by munch117 4y ago
If you don't know the syntax of let, then you might find yourself writing
(let (x 5) (* x x))
where you should have written
(let ((x 5)) (* x x))
That is syntax.
Let me ask you a question: Are these two expressions equivalent?
(f (g x))
and
(let ((y (g x))) (f y))
In the absence of macros, the answer is yes. In the presence of macros, there's no way of knowing until you've seen the definition of f: If f is a macro, they might not be. You need to know the syntax of the f macro to answer the question.
CL has a core language with a simple syntax. It also has a lot of macros in its standard library.
- kazinator 4y agoEven though (let (x 5) (* x x)) is wrong, it parses. We know that it has an operator, followed by two arguments, and the first argument is made up of two things. Because it parses, I don't have to correct the author's punctuation, just their understanding of the necessary shape . The wrong shape they wrote has a coherent syntax, and we can discuss the problem in terms of differences in syntax, rather than differences between gibberish and valid syntax. This is why your question is able to be, "are these expressions equivalent" and not "are these two token sequences equivalent". I can write a TDD test case for a new macro that doesn't exist yet, which won't bring down the program. E.g. (test (my:let (x 5) (+ x x)) 10) This will catch the error that foo is not defined and report that the test case failed instead of returning the expected 42 value. The next test case in the same file can execute. You couldn't have a test for new C++ or Java syntax, in a C++ or Java file being processed by a compiler that wasn't maintained in order to recognize the syntax. The file will blow up at parse time, not allowing any of the test cases in it to proceed. > You need to know the syntax of the f macro to answer the question. But I can see what that syntax is: it's (f (g x)) right there: i.e. /\ f /\ /\ () g /\ x () g and x are clumped together, so they have a closer relationship of some kind than either one has with f, at least syntactically. From looking at the use, I don't know whether it is valid shape for f, or if so, what other shapes are valid. And I don't know the semantics at all. I'm not struggling with syntax, though, just connecting it with a meaning.
- munch117 4y ago> Even though (let (x 5) (* x x)) is wrong, it parses. That's not the definition of syntax. If you're implementing a compiler, then you might use "syntax" as a shorthand for those parts of the syntax that are processed in a particular "syntax checking" stage of the compiler. But that's not all it is. > From looking at the use, I don't know whether it is valid shape for f That, on the other hand, is close to a definition of syntax: The rules for what has a valid shape and what doesn't.
- deleted 4y ago[deleted]