last block arg as implicit return value?

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

last block arg as implicit return value?

Chris Muller-4
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'

Reply | Threaded
Open this post in threaded view
|

Re: last block arg as implicit return value?

blake watson
>> | 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.


Reply | Threaded
Open this post in threaded view
|

Re: last block arg as implicit return value?

Nicolas Cellier
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]>:
>> | 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.






Reply | Threaded
Open this post in threaded view
|

Re: last block arg as implicit return value?

Eliot Miranda-2



On Mon, May 12, 2014 at 10:05 AM, Nicolas Cellier <[hidden email]> wrote:
I think I remember it was either the first or last parameter that was returned in old implementation

the last. ([:a :b|] value: #first value: #last) == #last
 

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...

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.




2014-05-12 17:58 GMT+02:00 blake <[hidden email]>:

>> | 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.










--
best,
Eliot


Reply | Threaded
Open this post in threaded view
|

Re: last block arg as implicit return value?

Chris Muller-3
> 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...

Reply | Threaded
Open this post in threaded view
|

Re: last block arg as implicit return value?

Nicolas Cellier
In reply to this post by Eliot Miranda-2



2014-05-12 19:17 GMT+02:00 Eliot Miranda <[hidden email]>:



On Mon, May 12, 2014 at 10:05 AM, Nicolas Cellier <[hidden email]> wrote:
I think I remember it was either the first or last parameter that was returned in old implementation

the last. ([:a :b|] value: #first value: #last) == #last
 

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...

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

?


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...
 
Squeak & VW answer #last.




2014-05-12 17:58 GMT+02:00 blake <[hidden email]>:

>> | 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.










--
best,
Eliot






Reply | Threaded
Open this post in threaded view
|

last block arg as implicit return value?

Louis LaBrunda
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