ifNotNil: perceived strangeness ;)

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

ifNotNil: perceived strangeness ;)

Brian Brown-2
Looking at ProtoObject>>ifNotNil: ifNotNilBlock
        "Evaluate the block, unless I'm == nil (q.v.)"

        ^ ifNotNilBlock valueWithPossibleArgs: {self}ifNotNil:


... which is invoked if the receiver is not nil, I would expect the  
following to work:

5 ifNotNil: [:e |  e] to return 5, but what I get is:
       
        argument of ifNotNil: must be a 0-argument block
       
       
However, if first store the block in a temp:

        ab := [:e | e]

5 ifNotNil: ab.


returns 5

I don't understand what the difference is between these; could some  
kind soul enlighten me as what is happening?


Cheers,

Brian


Reply | Threaded
Open this post in threaded view
|

RE: ifNotNil: perceived strangeness ;)

Ramon Leon-5
> Looking at ProtoObject>>ifNotNil: ifNotNilBlock
> "Evaluate the block, unless I'm == nil (q.v.)"
>
> ^ ifNotNilBlock valueWithPossibleArgs: {self}ifNotNil:
>
>
> ... which is invoked if the receiver is not nil, I would
> expect the following to work:
>
> 5 ifNotNil: [:e |  e] to return 5, but what I get is:
>
> argument of ifNotNil: must be a 0-argument block
>
>
> However, if first store the block in a temp:
>
> ab := [:e | e]
>
> 5 ifNotNil: ab.
>
>
> returns 5
>
> I don't understand what the difference is between these;
> could some kind soul enlighten me as what is happening?
>
>
> Cheers,
>
> Brian

You're looking for ifNotNilDo:[:it | ], ifNotNil:[] does not take an
argument, I believe it's optimized away by the compiler.

Ramon Leon
http://onsmalltalk.com 


Reply | Threaded
Open this post in threaded view
|

Re: ifNotNil: perceived strangeness ;)

Boris.Gaertner
In reply to this post by Brian Brown-2
"Brian Brown" <[hidden email]> wrote:


> Looking at ProtoObject>>ifNotNil: ifNotNilBlock
> "Evaluate the block, unless I'm == nil (q.v.)"
>
> ^ ifNotNilBlock valueWithPossibleArgs: {self}ifNotNil:
>
>
> ... which is invoked if the receiver is not nil, I would expect the  
> following to work:
>
> 5 ifNotNil: [:e |  e] to return 5, but what I get is:
>
> argument of ifNotNil: must be a 0-argument block
>
>
> However, if first store the block in a temp:
>
> ab := [:e | e]
>
> 5 ifNotNil: ab.
>
>
> returns 5
>
> I don't understand what the difference is between these; could some  
> kind soul enlighten me as what is happening?
>
>
Very interesting. There  should be no difference between the two
statements you mention and the very fact that there is should be
understood as a hint thatwe may have a new compilation bug.

In Squeak 3.7 the two statements of your example are both
erroneous, forthefirst one the compiler gives a message,
thesecond one brings up the debugger.

In Squeak 3.7 the definition of ifNotNil:  was:

ifNotNil: ifNotNilBlock
 "Evaluate the block, unless I'm == nil (q.v.)"

 ^ ifNotNilBlock value

The difference to newer version is that in 3.7 no support
for optional block arguments was present. In 3.9 it is
present and in my opinion the compiler was not
appropriately adapted.

Class MessageNode has two class variables that are relevant for
that problem:
MacroSelectors
  an array of message selectors that are inlined or otherwise
  transformed.
MacroTransformers
  an array of message selectors for messages in MethodMode that
  implement the code optimization.

These class variables and others are initialized in
MethodNode class>initialize
and I think a change there would fix the problem.

The really important question is however:
Was the introduction of optional arguments for  ifNotNil:
(and others) a good change when that change requires
the removal of a code transformation?

Comments from our compiler specialists are of course
welcome.

For me it is quite clear that we have a compiler bug here,
but I hesitate to propose a fix. Shall me modify thecompiler
or shall we go back to an earlier definition of  ifNotNil: ?

Hope this will help
Boris
 

Reply | Threaded
Open this post in threaded view
|

Re: ifNotNil: perceived strangeness ;)

Nicolas Cellier-3
Please take a look at http://bugs.squeak.org/view.php?id=6426

Boris.Gaertner a écrit :

> "Brian Brown" <[hidden email]> wrote:
>
>
>> Looking at ProtoObject>>ifNotNil: ifNotNilBlock
>> "Evaluate the block, unless I'm == nil (q.v.)"
>>
>> ^ ifNotNilBlock valueWithPossibleArgs: {self}ifNotNil:
>>
>>
>> ... which is invoked if the receiver is not nil, I would expect the  
>> following to work:
>>
>> 5 ifNotNil: [:e |  e] to return 5, but what I get is:
>>
>> argument of ifNotNil: must be a 0-argument block
>>
>>
>> However, if first store the block in a temp:
>>
>> ab := [:e | e]
>>
>> 5 ifNotNil: ab.
>>
>>
>> returns 5
>>
>> I don't understand what the difference is between these; could some  
>> kind soul enlighten me as what is happening?
>>
>>
> Very interesting. There  should be no difference between the two
> statements you mention and the very fact that there is should be
> understood as a hint thatwe may have a new compilation bug.
>
> In Squeak 3.7 the two statements of your example are both
> erroneous, forthefirst one the compiler gives a message,
> thesecond one brings up the debugger.
>
> In Squeak 3.7 the definition of ifNotNil:  was:
>
> ifNotNil: ifNotNilBlock
> "Evaluate the block, unless I'm == nil (q.v.)"
>
> ^ ifNotNilBlock value
>
> The difference to newer version is that in 3.7 no support
> for optional block arguments was present. In 3.9 it is
> present and in my opinion the compiler was not appropriately adapted.
>
> Class MessageNode has two class variables that are relevant for
> that problem:
> MacroSelectors  an array of message selectors that are inlined or otherwise
>  transformed.
> MacroTransformers
>  an array of message selectors for messages in MethodMode that
>  implement the code optimization.
>
> These class variables and others are initialized in MethodNode
> class>initialize
> and I think a change there would fix the problem.
> The really important question is however:
> Was the introduction of optional arguments for  ifNotNil:
> (and others) a good change when that change requires
> the removal of a code transformation?
>
> Comments from our compiler specialists are of course
> welcome.
>
> For me it is quite clear that we have a compiler bug here,
> but I hesitate to propose a fix. Shall me modify thecompiler
> or shall we go back to an earlier definition of  ifNotNil: ?
>
> Hope this will help
> Boris
>
>


Reply | Threaded
Open this post in threaded view
|

Re: ifNotNil: perceived strangeness ;)

Zulq Alam-2
In reply to this post by Brian Brown-2
This seems related to:
       
http://www.nabble.com/argument-of-ifNotNil:-must-be-a-0-argument-block-t2205353.html
http://bugs.squeak.org/view.php?id=4867

Regards,
Zulq.

Brian Brown wrote:

> Looking at ProtoObject>>ifNotNil: ifNotNilBlock
>     "Evaluate the block, unless I'm == nil (q.v.)"
>
>     ^ ifNotNilBlock valueWithPossibleArgs: {self}ifNotNil:
>
>
> .... which is invoked if the receiver is not nil, I would expect the
> following to work:
>
> 5 ifNotNil: [:e |  e] to return 5, but what I get is:
>    
>     argument of ifNotNil: must be a 0-argument block
>    
>    
> However, if first store the block in a temp:
>
>     ab := [:e | e]
>
> 5 ifNotNil: ab.
>
>
> returns 5
>
> I don't understand what the difference is between these; could some kind
> soul enlighten me as what is happening?
>
>
> Cheers,
>
> Brian
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: ifNotNil: perceived strangeness ;)

David T. Lewis
On Wed, Oct 03, 2007 at 11:01:04PM +0100, Zulq Alam wrote:
> This seems related to:
>
> http://www.nabble.com/argument-of-ifNotNil:-must-be-a-0-argument-block-t2205353.html
> http://bugs.squeak.org/view.php?id=4867
>

These two Mantis entries are both (duplicate) reports documenting the bug, and both
have discussion and proposed fixes:

http://bugs.squeak.org/view.php?id=4867
http://bugs.squeak.org/view.php?id=6426

Dave


Reply | Threaded
Open this post in threaded view
|

Re: ifNotNil: perceived strangeness ;)

Chris Muller-3
I hope ProtoObject>>#ifNotNil: will be moved down to Object too!

On 10/3/07, David T. Lewis <[hidden email]> wrote:

> On Wed, Oct 03, 2007 at 11:01:04PM +0100, Zulq Alam wrote:
> > This seems related to:
> >
> > http://www.nabble.com/argument-of-ifNotNil:-must-be-a-0-argument-block-t2205353.html
> > http://bugs.squeak.org/view.php?id=4867
> >
>
> These two Mantis entries are both (duplicate) reports documenting the bug, and both
> have discussion and proposed fixes:
>
> http://bugs.squeak.org/view.php?id=4867
> http://bugs.squeak.org/view.php?id=6426
>
> Dave
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: ifNotNil: perceived strangeness ;)

Jason Johnson-5
+1.  Why was it on Proto?

On 10/4/07, Chris Muller <[hidden email]> wrote:

> I hope ProtoObject>>#ifNotNil: will be moved down to Object too!
>
> On 10/3/07, David T. Lewis <[hidden email]> wrote:
> > On Wed, Oct 03, 2007 at 11:01:04PM +0100, Zulq Alam wrote:
> > > This seems related to:
> > >
> > > http://www.nabble.com/argument-of-ifNotNil:-must-be-a-0-argument-block-t2205353.html
> > > http://bugs.squeak.org/view.php?id=4867
> > >
> >
> > These two Mantis entries are both (duplicate) reports documenting the bug, and both
> > have discussion and proposed fixes:
> >
> > http://bugs.squeak.org/view.php?id=4867
> > http://bugs.squeak.org/view.php?id=6426
> >
> > Dave
> >
> >
> >
>
>