Unexpected behaviuor with closures

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Unexpected behaviuor with closures

Pavel
Hi, folks!

I have a piece of code, which I cannot make running. Please take a look:

"Here we have an ordered collection of closures checking the integer
argument complies some properties."
a := OrderedCollection new.
a add: [:i | i \\ 2 = 0 ].
a add: [:i | i \\ 3 = 0 ].
a add: [:i | i > 6 ].

"I seem there should be returned a closure with 1 argument checking whether
an argument is a product of 3 and 2, which value is larger than 6."
b := a inject: [:i | true ] into: [ :accumValue :item | [:i | ( accumValue
value: i ) and: [item value: i] ] ].

"We dont need the collection anymore, because it's elements are now
referenced from inside b."
a := nil.

"Why stack overflows?"
b value: 6.
b value: 12.

Thanks in advance.

Pavel.
PS :I'm trying in  DVE5.


Reply | Threaded
Open this post in threaded view
|

Re: Unexpected behaviuor with closures

Chris Uppal-3
Pavel wrote:

> "Why stack overflows?"
> b value: 6.
> b value: 12.
[...]
> PS :I'm trying in  DVE5.

Because you are using DVE5 ;-)

Dolphin, before D6, didn't have blocks which were "full closures", and so
sometimes the semantics could differ from what you might expect.  Seach the
archives for more details.

In D6 blocks have a new implementation with the more general semantics. And
your two test expressions answer false and true respectively.  I don't know
whether that's the answer you'd expect, but that's what you get ;-)

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: Unexpected behaviuor with closures

Pavel
Cris Tnx, for reply!
"Chris Uppal" <[hidden email]> wrote in message
news:43eb448a$1$1176
> Because you are using DVE5 ;-)

Yes, in DCE6 thats work fine, as I expected.

Pavel.