Confusing issue with blocks
J J
azreal1977 at hotmail.com
Tue Dec 12 17:51:08 UTC 2006
Hi all,
I am having a strange problem with anonymous blocks. I have been trying to
impliment a Reccurrence rule engine. After trying different implimentations
I didn't like, I found that the best solution involved an infinite list. So
I set out to impliment lazy evaluation in smalltalk. What I have now works
like:
((LazyElement enumerateFrom: 2006 with: [:e| e + 2]) collectAndFlatten: [:y|
(LazyElement fromArray: #(1 8 12)) collectAndFlatten: [:m|
(LazyElement fromArray: #(1 15 27)) collect: [:d|
Date year: y month: m day: d
]
]
]) take: 500
And this part works perfectly. I have gone up to 2k dates and I noticed no
delay at all (though I haven't timed it). I then changed the List creation
parts to be methods, which is what my final solution will need. If I change
the month function to return different months depending on the year and it
works perfectly. But if I have a year for which no months apply and return
an empty list, I get "error: Attempt to evaluate a block that is already
evaluated."
I have done a parralell implimentation in Ocaml (because it also requires me
to manually build the Lazy List operations) and everything worked as
expected, so I am really baffelled on this one. Nothing should be happening
in the empty list case that doesn't already happen in the case of 1 or more
in the list.
I read on the list that the solution to this problem is to copy or clone the
block. I have put a clone on every place I use a block and it didn't help.
Nor did copy.
I have enclosed the file out of the Lazy list classes (it's not a lot of
code), I would appreciate any help anyone could give me.
Thanks,
Jason
_________________________________________________________________
View Athletes Collections with Live Search
http://sportmaps.live.com/index.html?source=hmemailtaglinenov06&FORM=MGAC01
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LazyElement.st
Type: application/octet-stream
Size: 3920 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20061212/87e5adda/LazyElement.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LazyNil.st
Type: application/octet-stream
Size: 1527 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20061212/87e5adda/LazyNil.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LazyTest.st
Type: application/octet-stream
Size: 1076 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20061212/87e5adda/LazyTest.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LazyValue.st
Type: application/octet-stream
Size: 1120 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20061212/87e5adda/LazyValue.obj
More information about the Squeak-dev
mailing list
|