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

You can't define iterator with LIPS data types #328

Closed
jcubic opened this issue Mar 5, 2024 · 0 comments
Closed

You can't define iterator with LIPS data types #328

jcubic opened this issue Mar 5, 2024 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@jcubic
Copy link
Collaborator

jcubic commented Mar 5, 2024

This is code that use iteration protocol.

(let ((obj (object))
      (max 10))
  (set-obj! obj Symbol.iterator
        (lambda ()
          (let ((i 0))
            (object :next (lambda ()
                            (set! i (+ i 1))
                            (if (> i max)
                                `&(:done #t)
                                `&(:done #f :value ,(/ 1 i))))))))
  (print (iterator->array obj))
  (print (Array.from (iterator->array obj))))

The problem is that the output array/vector contain JavaScript float numbers instead of LIPS rational numbers.

#(1 0.5 0.3333333333333333 0.25 0.2 0.16666666666666666 0.14285714285714285 0.125 0.1111111111111111 0.1)

It seems that the problem is array::push that unbox the value:

(let ((x (vector))) (x.push 1/2) x)
;; ==> #(0.5)
@jcubic jcubic added the bug Something isn't working label Mar 5, 2024
@jcubic jcubic added this to the 1.0 milestone Mar 5, 2024
jcubic added a commit that referenced this issue Mar 5, 2024
@jcubic jcubic closed this as completed Mar 5, 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

1 participant