[R] understanding recursive functions
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Dec 19 01:36:02 CET 2008
Peter Dalgaard wrote:
> Wacek Kusnierczyk wrote:
>>
>>>
>>> " The operators '<<-' and '->>' cause a search to made through the
>>> environment for an existing definition of the variable being
>>> assigned. If such a variable is found (and its binding is not
>>> locked) then its value is redefined, otherwise assignment takes
>>> place in the global environment. Note that their semantics differ
>>> from that in the S language, but are useful in conjunction with
>>> the scoping rules of R. See 'The R Language Definition' manual
>>> for further details and examples."
>>>
>>>
>>
>> the description is further imprecise as to what happens if such a
>> variable is found but is locked:
>>
>> foo = function() {
>> x = 0
>> lockBinding("x", environment())
>> (function() x <<- 1)()
>> unlockBinding("x", environment())
>> }
>>
>> foo()
>> # error
>>
>> if analysed logically (IF (found AND not locked THEN assign) ELSE assign
>> globally), the description is wrong.
>
> Yes.
>
> If such a variable is found then its value is redefined (unless its
> binding is locked), otherwise assignment take place in the global
> environment.
>
it might help the help to be have the help say that if the variable is
found but locked then an error is raised.
vQ
More information about the R-help
mailing list