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

Array::push and Array.from unbox native types #233

Closed
jcubic opened this issue Dec 12, 2022 · 2 comments
Closed

Array::push and Array.from unbox native types #233

jcubic opened this issue Dec 12, 2022 · 2 comments
Labels
bug Something isn't working resolved

Comments

@jcubic
Copy link
Collaborator

jcubic commented Dec 12, 2022

This is really problematic:

(let ((x (vector)))
  (x.push #\x)
  x)
;; ==> #("x")

This prevents adding:

LString.prototype[Symbol.iterator] = function*() {
    const chars = Array.from(this.__string__);
    for (const char of chars) {
        yield LCharacter(char);
    }
};

because they got unboxed.

Another issue is that:

(Array.from "hello")

doesn't trigger LString iterator, because string is unboxed.

@jcubic jcubic added the bug Something isn't working label Dec 12, 2022
@jcubic
Copy link
Collaborator Author

jcubic commented Dec 12, 2022

Possible solutions:

  • Adding a marker to native types to prevent them unboxed for a single native method.
  • Add wrappers for common Array methods
  • Make LCharacter unboxable, it will break when using char with JavaScript libraries but it's good because they will be not compatible.

@jcubic
Copy link
Collaborator Author

jcubic commented Jan 19, 2023

this code still doesn't work:

(Array.from "hello")
;; ==> #("h" "e" "l" "l" "o")

Because the string is unboxed before getting the iterator:

(let ((i (. "hello" Symbol.iterator)))
  (Array.from (i)))
;; ==> #(#\h #\e #\l #\l #\o)

Strings have to be unboxed.

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