Re: Difference between method and block - with examples
Steve Dekorte <[email protected]>
| Newsgroups | gmane.comp.lang.io |
|---|---|
| Message-ID | <[email protected]> |
On 2011-06-12 Sun, at 11:01 AM, Shashank Date wrote: >> blocks retain the stack which they reference - so only use them if that's what you want. > > I am afraid I do not understand what you mean by "blocks retain the stack which they refer"\ Each stack frame referencing it's calling stack frame and a block references the stack frame it was instantiated in (this is the block's scope). So a block's scope and all the stack frames preceding it will not be released by the garbage collector while the block itself is still referenced. > > >> Though it's terser to do: >> if(foo, x := 1) > > It may be terser but does not seem to be equivalent. While as > "foo ifTrue(block(x := 1))" will not make x available to the outer context, the expression "if(foo, x:= 1)" will! Right, and the block also has much more performance overhead.