-
Notifications
You must be signed in to change notification settings - Fork 0
is quasiquotation correct? #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I can put something together for you, probably tomorrow. |
Have you implemented , (comma) and @ too? |
I did all 3 reader macros ( Once I know that quasiquotes work, I'm going to try to add macros. Do you think this kind of thing would be something you would want to add to uLisp in a new version (maybe not available for arduino uno and low-flash platforms)? |
pending test suite (#3) it looks to work okay
I couldn't get Dave Astel's code to give sensible results, so I didn't get very far with that.
Definitely! |
Here are some tests:
The function |
Also, here's an example to show why it would be nice to have macros in uLisp. By the way, the usual term in Lisp is backquote rather than quasiquote. A C programmer would like to extend Lisp with a for-loop construct so they could write something like:
Here's the Lisp macro that would achieve this:
It could also be written slightly less elegantly without backquote like this:
Just to clarify: the above code doesn't currently work in uLisp! |
Another couple of interesting ones:
|
They all pass! 👏
These two fail. The first one winds up with
I do plan to implement macros! |
Another fun one (it passes): (aeq :quine
'(let ((let '`(let ((let ',let)) ,let))) `(let ((let ',let)) ,let))
(let ((let '`(let ((let ',let)) ,let))) `(let ((let ',let)) ,let))
) I got this from https://3e8.org/pub/scheme/doc/Quasiquotation%20in%20Lisp%20(Bawden).pdf. |
Going to close this now, backquotes appears to be working good enough to call them done. Macros would be a separate issue. |
Look forward to playing with your macros! |
Unfortunately they don't work quite yet... here's the current state of the macros:
Not sure what the hangup in macroexpand is... |
Yes, you should get this:
|
Macros are sorta working now as of dd0f3f8. I got this to expand properly:
Destructuring lambda params aren't supported so I used this definition: (defmacro for (ici &rest body)
(unless (= 3 (length ici)) (error "(for) header must be 3 elements (init condition increment)"))
`(let (,(car ici))
(loop
(unless ,(cadr ici) (return))
,@body
,(caddr ici)))) However, they are behaving a little strange:
That was expected.
Super weird error. I was just expecting it to hang. Maybe it has something to do with the GCStack? |
Cool! I'll take a look at it. |
By the way, the GCStack is only needed to prevent corruption during a garbage collection. If the problem still occurs when no garbage collection has happened it's something else. To test it uncomment:
and comment out this line in repl():
Do a manual (gc) before starting. If you've got enough workspace you should be able to test everything without a gc occurring. |
macroexpand1() calls closure() and eval(), which may invoke the garbage collector. As of the latest commit I did add some GCStack protections around the calls to eval in the macro-expanding functions, but I still got the weird "'cons' too many arguments" error nonetheless. Also, the macro expansion code isn't properly tail-recursive. In macroexpand1() it eval's the result before returning it, which blows up the stack even on tail-calls of macros. I used the macro |
Unless you are explicitly calling gc() in your C code, the garbage collector will not get called unless you're running low on workspace. |
I implemented quasiquotation using the MAL tutorial, which is based off of Clojure... Clojure is most definitely not Common Lisp... are the behavior of nested quasiquotes correct/compliant with Common Lisp?
@technoblogy if you have a quasiquote test suite I'd be happy to try it out.
The text was updated successfully, but these errors were encountered: