Skip to content
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

Unexpected behaviour with nested backquotes #362

Closed
mayerrobert opened this issue May 20, 2024 · 6 comments
Closed

Unexpected behaviour with nested backquotes #362

mayerrobert opened this issue May 20, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@mayerrobert
Copy link

mayerrobert commented May 20, 2024

When experimenting with nested backquote edgecases the following forms entered into the REPL at https://lips.js.org/ seem to give wrong results:

(define x '(1 2 3))
(define y '(11 22 33))
(define l '(x y))

(eval ``(,@,@l)) 
; => (1 2 3 11 22 33)
; correct


(eval ``(,@,@l ,@,@l))
; => error message:
Cannot read properties of undefined (reading 'use_dynamic')
Call (stack-trace) to see the stack
Thrown exception is in global exception variable,
use (display exception.stack) to display JS stack trace


; (press F5 to reload LIPS)
(define x '(1 2 3))
(define y '(11 22 33))
(define l '(x y))

(eval ``(,@,@l ,@,@l))
; => (1 2 3 11 22 33)
; IMO this should be (1 2 3 11 22 33 1 2 3 11 22 33)


(eval ``(foo ,@,@l ,@,@l ,@,@l xyxxy))
; => (foo 1 2 3 11 22 33)
; should be (foo 1 2 3 11 22 33 1 2 3 11 22 33 1 2 3 11 22 33 xyxxy)

The "should be" results were verified using Gauche v0.9.10 at https://www.tutorialspoint.com/execute_scheme_online.php

@jcubic
Copy link
Collaborator

jcubic commented May 20, 2024

Thanks for the report. I didn't check quasiquote for quite a while, I was sure it was correct.

I based the implementation on the paper "Quasiquotation in Lisp" by Alan Bawden. I need to investigate what is happening.

@jcubic jcubic added the bug Something isn't working label May 20, 2024
@jcubic
Copy link
Collaborator

jcubic commented May 20, 2024

There are two issues here, second call to eval throws exception in REPL and stuff after splice-splice are ignored.

@jcubic
Copy link
Collaborator

jcubic commented May 20, 2024

LIPS returns:

``(,@,@l ,@,@l)
(quasiquote ((unquote-splicing x y)))

It should be:

(quasiquote ((unquote-splicing x y) (unquote-splicing x y)))

@jcubic
Copy link
Collaborator

jcubic commented May 20, 2024

And there is also another bug the x list from your code is mutated to include the y.

(define x '(1 2 3))
(define y '(11 22 33))
(define l '(x y))

(eval ``(,@,@l)) 
; => (1 2 3 11 22 33)
x
(1 2 3 11 22 33)

@jcubic
Copy link
Collaborator

jcubic commented May 20, 2024

So the actual error is StackOverflow because it creates a weird cycle. But there is also an error in display-error function that is thrown when attempting to print stack overflow error.

(print x)
(1 2 3 . #0=(11 22 33 . #0#))

jcubic added a commit that referenced this issue May 26, 2024
jcubic added a commit that referenced this issue May 26, 2024
@jcubic
Copy link
Collaborator

jcubic commented May 27, 2024

The issue is fixed on devel branch. It will be released in next beta version

@jcubic jcubic closed this as completed May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants