So are these "specials" being parsed by a grammar?
Would be interesting to see how the interpreter works actually...
I would guess it checks what `defun` is, which is a macro...then expands it, and the expansion should ultimately result in an s-expression, which is then parses? Is this right?
I would guess it checks what `defun` is, which is a macro...then expands it, and the expansion should ultimately result in an s-expression, which is then parses? Is this right?
Yes, but macros (like special forms, but macros can be user implementable) have some "special" powers regarding controlling the evaluation of the code they produce.
(defun foo (a) (+ a 1)) is a s-expression. For evaluation Lisp expands the DEFUN macro then and this returns a new s-expression. Which then is evaluated.
So are these "specials" being parsed by a grammar?
Every special operator (and there are only a limited amount and this is not user extensible) needs to be implemented by a Lisp source interpreter or a Lisp compiler. Other tools like a code walker also need to know the syntax.
Comments
(quote a b c) does not exist in Lisp. QUOTE takes exactly one argument, the object to quote. It's a special operator.
> defun = special formDEFUN is not really a form in the standard. It's a operator. It's even not a special operator. It's a macro operator.
A form is something meant to be evaluated. One could evaluate the symbol DEFUN, but by default it has no value.
So are these "specials" being parsed by a grammar?
Would be interesting to see how the interpreter works actually...
I would guess it checks what `defun` is, which is a macro...then expands it, and the expansion should ultimately result in an s-expression, which is then parses? Is this right?
It's quite easy to see, there are interpeters for Lisp in like 20 lines or so.
Here's a good one:
https://norvig.com/lispy.html
(It has the full code in a link towards the bottom)
There's also this:
https://github.com/kanaka/mal
Yes, but macros (like special forms, but macros can be user implementable) have some "special" powers regarding controlling the evaluation of the code they produce.
Here's some more discussion with examples:
https://stackoverflow.com/questions/42470940/how-is-the-defu...
Thanks! Lisp is so damn cool.
(defun foo (a) (+ a 1)) is a s-expression. For evaluation Lisp expands the DEFUN macro then and this returns a new s-expression. Which then is evaluated.
Every special operator (and there are only a limited amount and this is not user extensible) needs to be implemented by a Lisp source interpreter or a Lisp compiler. Other tools like a code walker also need to know the syntax.
oops, I shouldn't post drunk