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

Object literals should use values from scope when using short syntax #237

Closed
jcubic opened this issue Jan 24, 2023 · 4 comments
Closed

Object literals should use values from scope when using short syntax #237

jcubic opened this issue Jan 24, 2023 · 4 comments
Labels
bug Something isn't working resolved

Comments

@jcubic
Copy link
Collaborator

jcubic commented Jan 24, 2023

According to the documentation:

lips> (let ((foo 10) (bar 20)) &(:foo :bar))
&(:foo #<undefined> :bar #<undefined>)

this should reutnr &(:foo 10 :bar 20)

Another issue is that prism highlighting doesn't support shorthand syntax.

@jcubic jcubic added the bug Something isn't working label Jan 24, 2023
jcubic added a commit that referenced this issue Jan 24, 2023
@jcubic
Copy link
Collaborator Author

jcubic commented Jan 24, 2023

this works now:

(let ((foo 10) (bar 20))
  (object :foo :bar))

But &(:foo :bar) doesn't work, maybe because syntax extensions run at parse time.

Need to investigate.

@jcubic
Copy link
Collaborator Author

jcubic commented Jan 24, 2023

That's right there is a bit of inconsistency here:

lips> (lips.parse "&(:foo 10)")
#(&(:foo 10))
lips> (lips.parse "`(foo bar)")
#((quasiquote (foo bar)))

The first expression should evaluate into:

#((object-literal :foo 10))

To solve this issue default syntax extensions should be just simple mappers:

(define (object-literal-map x)
  `(object-literal ,@x))

(set-special! "&" 'object-literal-map)

(let ((foo 10)) &(:foo))
;; ==> &(:foo 10)

Real macros can be left to reader macros tracked in #150

@jcubic
Copy link
Collaborator Author

jcubic commented Jan 24, 2023

This breaks tests and because of this object literals don't work anymore as vectors:

(let ((x 10)) `&(:foo ,x))
;; ==> (object-literal :foo 10)
(let ((x 10)) `#(1 2 ,x))
;; ==> #(1 2 10)

but now object literals works as a quotation:

`'(foo)
;; ==> (quote (foo))

I think that it will be better to update tests.

jcubic added a commit that referenced this issue Jan 24, 2023
@jcubic
Copy link
Collaborator Author

jcubic commented Jan 24, 2023

Found old commented-out unit tests that define how this should work, so restored the old behavior:

lips> (let ((foo 10) (bar 20)) &(:foo :bar))
&(:foo #<undefined> :bar #<undefined>)

But also added read-only properties. The below code will throw an error:

(let ((x &(:foo :bar 10)))
  (set! x.bar 20))

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

No branches or pull requests

1 participant