picrin-scheme / picrin

lightweight scheme interpreter
MIT License
414 stars 35 forks source link

fix promise bugs on corner cases (first one) #340

Closed stibear closed 8 years ago

stibear commented 8 years ago

Ref: #339

KeenS commented 8 years ago

It seems that all the call of make-promise% followed by box so why don't you define the combination as an procedure?

nyuichi commented 8 years ago

@stibear

Can you split the patch into two things, one for the first bug and the other for the second one? I can merge the second one immediately, while the first needs more discussion, I think.

nyuichi commented 8 years ago

Can we implement delay-force just like the following instead of using boxes?:

  (define-syntax delay-force
    (syntax-rules ()
      ((_ expr)
       (letrec ((p (make-promise% #f (lambda ()
                                       (let ((v (begin expr)))
                                         (set-promise-done! p #t)
                                         p)))))
         p))))

I'm not sure if this works. And there are maybe more elegant solutions anyway.

nyuichi commented 8 years ago

@stibear

I made an alternative implementation using tri-state rather than boxes: https://github.com/picrin-scheme/picrin/tree/stibear-lazy

stibear commented 8 years ago

@nyuichi It looks no problem. I tested it and it passed all tests.