[Prev][Next][Index][Thread]

Re: lazy.dylan 0.1 -- add ML/Scheme-style lazy evaluation to Dylan



In article <slrn85glb7.8kj.neelk@brick.cswv.com>, neelk@alum.mit.edu wrote:

> I've written a tiny little module to do SML/NJ or SICP-style lazy
> evaluation with Dylan.

I see where the results of several prior threads just got used... :-)


I've got a weenie micro-optomisation style question (I don't have a real
opinion but I'd like to know what others think)...

In ...

define class <suspension> (<object>)
  slot memoized? :: <boolean>,
    init-value: #f;
  slot expression :: <method>,
    required-init-keyword: expression:;
  slot vals :: <sequence>;
end class <suspension>;

... are "memoized?" and "vals" declared optimally?  Since "vals" doesn't
have a required initializer it is going to have to have a reserved value
to indicate "not initialized" somehow, which will take up space and always
have a runtime check that slows down access to the slot value.  And yet
slot-initialized?(vals) will always have exactly the same value as
"memoized?".

Do you think you should dump the "memoized?" slot, and just test
slot-initialized?(vals) in the force() method?  If you want mnemonic value
then you could always implement "memoized?" as a method that tests
slot-initialized?.

Alternatively, you could explicitly initialize "vals" to a globally-unique
object that is an instance of <sequence> that serves as a "null" value. 
In which case you still don't need "memoized?" :-)

-- Bruce



References: