After 20+ years of Smalltalking, I stumbled on this basic block
behavior that surprised me. What would you expect this expression to return? | myBlock | myBlock := [ : arg1 : arg2 | ]. myBlock value: 'hello' value: 'there' |
>> | myBlock | >> myBlock := [ : arg1 : arg2 | ]. >> myBlock value: 'hello' value: 'there' nil Because the block isn't returning a value and the last line is calling the block. |
I think I remember it was either the first or last parameter that was returned in old implementation It's a known problem: http://bugs.squeak.org/view.php?id=5793 but I would have thought that this was fixed with Eliot's closure... 2014-05-12 17:58 GMT+02:00 blake <[hidden email]>:
|
On Mon, May 12, 2014 at 10:05 AM, Nicolas Cellier <[hidden email]> wrote:
the last. ([:a :b|] value: #first value: #last) == #last
I kept the old semantics, trying to rock the boat as little as possible. I just checked the draft standard. The end of 3.4.4 "blocks" reads
"If a block has no <block body> or no <statements> in its <block body> then the value of the block is undefined." I've found the returning the last value bizarre for a while. If others feel strongly we could fix it for 4.6/5.0. But I'd want agreement with Pharo. Marcus what does Opal do with:
[:a :b|] value: #first value: #last ? Squeak & VW answer #last.
best, Eliot
|
> just checked the draft standard. The end of 3.4.4 "blocks" reads
> > "If a block has no <block body> or no <statements> in its <block body> then > the value of the block is undefined." Heh, which is somewhat ambiguous coming from the same book that introduces us to UndefinedObject... |
In reply to this post by Eliot Miranda-2
2014-05-12 19:17 GMT+02:00 Eliot Miranda <[hidden email]>:
As I reported in the bug tracker, the NewCompiler (former nick name for Opal) answers nil. This can be considered as an extension of [] value...
|
In reply to this post by Chris Muller-4
I would expect nil. When I check VA Smalltalk, nil it is.
Lou >After 20+ years of Smalltalking, I stumbled on this basic block >behavior that surprised me. What would you expect this expression to >return? > >| myBlock | >myBlock := [ : arg1 : arg2 | ]. >myBlock value: 'hello' value: 'there' > ----------------------------------------------------------- Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:[hidden email] http://www.Keystone-Software.com |
Free forum by Nabble | Edit this page |