[Pharo-project] Cannot assign a parameter

laurent laffont laurent.laffont at gmail.com
Sun Nov 28 13:53:43 CET 2010


Indeed if I rewrite

TempVariableNode>>assignmentCheck: encoder at: location
^(self isBlockArg and: [Parser allowBlockArgumentAssignment not])
 ifTrue: [location]
ifFalse: [-1]


then

foo: n
  ^[:i| n := n+i. ]

works. But I don't know the impact....

Laurent



On Sun, Nov 28, 2010 at 11:41 AM, Max Leske <maxleske at gmail.com> wrote:

> +1
>
>
> On 28.11.2010, at 11:26, laurent laffont wrote:
>
> I would like to know whether it's a design choice or a technical obstacle.
>
> I've seen:
>
> Parser>>assignment: varNode
> " var ':=' expression => AssignmentNode."
>  | loc start |
> (loc := varNode assignmentCheck: encoder at: prevMark + requestorOffset) >=
> 0
>  ifTrue: [^self notify: 'Cannot store into' at: loc].
>         .....
>
>
> TempVariableNode>>assignmentCheck: encoder at: location
>  ^((self isBlockArg and: [Parser allowBlockArgumentAssignment not])
>     or: [self isMethodArg])
>                  "<-- not allowed !"
>  ifTrue: [location]
> ifFalse: [-1]
>
> But no explanation :(
>
>
> Laurent
>
>
>
> On Sun, Nov 28, 2010 at 10:59 AM, Max Leske <maxleske at gmail.com> wrote:
>
>> Yeah, that's true, I've noticed that too. I guess it's on purpose but I
>> have no idea. AFAIK you can't assign a new value to a parameter anywhere in
>> the method not only when using blocks. Maybe it's not possible because there
>> is not really a 'variable' but only a reference. So assigning a new value to
>> the parameter would effectively override the reference. But don't trust me
>> on this....
>>
>> Cheers,
>> Max
>>
>>
>> On 28.11.2010, at 10:54, laurent laffont wrote:
>>
>> Sorry
>>
>> foo: n
>>   ^[:i| n := n+i. ]
>>
>> vs
>>
>> foo: n
>>   |s|
>>   s := n.
>>   ^[:i| s := s+i. ]
>>
>>
>> Laurent
>>
>> On Sun, Nov 28, 2010 at 10:51 AM, Max Leske <maxleske at gmail.com> wrote:
>>
>>> In the first example you didn't declare 's':
>>>
>>> foo:n
>>> ^ [ :i || s | s:= s+i ]
>>>
>>> Or did I misunderstand the question?
>>>
>>> Cheers,
>>> Max
>>>
>>>
>>> On 28.11.2010, at 10:30, laurent laffont wrote:
>>>
>>> Hi,
>>>
>>> I can't write
>>>
>>> foo: n
>>>   ^[:i| s := s+i. ]
>>>
>>> but
>>>
>>> foo: n
>>>   |s|
>>>   s := n.
>>>   ^[:i| s := s+i. ]
>>>
>>>
>>> Why ?
>>>
>>>
>>> Cheers,
>>>
>>> Laurent Laffont
>>>
>>> Pharo Smalltalk Screencasts: http://www.pharocasts.com/
>>> Blog: http://magaloma.blogspot.com/
>>>
>>>
>>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gforge.inria.fr/pipermail/pharo-project/attachments/20101128/af8e0a8b/attachment.htm>


More information about the Pharo-project mailing list