LIPS-scheme / lips

Scheme based powerful lisp interpreter in JavaScript
https://lips.js.org
Other
423 stars 35 forks source link

Class with LIPS types as props #411

Open jcubic opened 2 days ago

jcubic commented 2 days ago

Investigate this problem:

(define Person (class Object (constructor (lambda (self name age)
                                            (set! self.name name)
                                            (set! self.age age)))))

(define jack (new Person 'Jack 27))
jack.name
;; ==> "Jack"
(define jack (new Person 'Jack 27+i))
jack.age
;; ==> #(27 1)

The same problems is with records

(define-record-type <point>
  (make-point x y)
  point?
  (x get-x set-x!)
  (y get-y set-y!))

(define p (make-point +10i +20i))
(get-x p)
;; ==> #(0 10)

LIPS types are unboxed, but the should not. If the user wants to share a class with JavaScript it's his responsibility to not use native types.

jcubic commented 2 days ago

The problem is with new operator that unbox the arguments:

lips> (new (lambda (x) (print x)) 10+10i)
#(10 10)

I think that it's ok for the class to do this, but it should not happen with records.