This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: proposed support for lazy values


On Jun 7, 2011, at 2:50 PM, Per Bothner wrote:

On 06/06/2011 07:28 AM, Jamison Hope wrote:
On Jun 4, 2011, at 3:15 AM, Per Bothner wrote:

Could you try the attached patch? A review would be appreciated as well.

That works for me. Good catch with initializing result to something other than null. I suppose someone could still write a promise that evaluates to Location.UNBOUND, but that's probably unlikely enough to ignore. There's still a minor deficiency in print():

#|kawa:1|# (define my-promise (delay (throw (java.lang.Exception))))
#|kawa:2|# my-promise
#<promise - not forced yet>
#|kawa:3|# (force my-promise)
java.lang.Exception

I would argue that the print at line 4 should say something like
"#<promise - force threw a java.lang.Exception>" instead. How about the
attached update to your patch?

I took your suggestion, but added synchronization. See the attachment.

Looks good to me.


Note I also changed force to add an extra check after the apply0 call, to
match RnRS semantics for "nested" forcing.

I presume by "RnRS semantics" you're referring to the sample implementation
of make-promise in the R5RS and R6RS reports?


Note also that after the grand plan calls for auto-force by display and the REPL;
at that point the change to print will primarily affect calls to write.

Right. When that happens, then we'll see output like this, right?


#|kawa:1|# (define a (delay 1))
#|kawa:2|# (define b (delay 2))
#|kawa:3|# (define c (delay 3))
#|kawa:4|# (write a) ; no implicit force
#<promise - not forced yet>
#|kawa:5|# (display b) ; implicit force
2
#|kawa:6|# c ; implicit display, which does implicit force
3


Calls to format will also implicitly force, right? The documentation for the
~A directive says "Any (print as display does)." So,
(format #f "~A~%" (delay 4)) => "4"




--
Jamison Hope
The PTR Group
www.theptrgroup.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]