Skip to content
Prev 167979 / 398502 Next

how to get a primitive function object

Duncan Murdoch wrote:
you might want to specify what 'completely unrecoverable' means, and
what approaches are allowed.

for the former, i guess that:
- 'incompletely recoverable' means that there is at least one function
name in the global environment such that its value has been redefined
and it's not possible, within the session, to revert the binding to the
original value;
- 'completely unrecoverable' means that if there are any function names
with redefined bindings in the global environment, it is not possible,
within the session, to revert the binding for any of them.

you might also mean the extreme situation where there is no function
name that has not been redefined and it is not possible to recover the
original binding for any function name, but i guess this is not what you
mean.  (if you do, then i think the answer is negative, what should be
fairly easy to prove.)

the two cases are effectively equivalent:
- if we are in a completely unrecoverable situation, then there is at
least one function name that cannot be reverted to the original value,
hence the situation is also incompletely recoverable (for those
logically inclined, there is one obvious completely unrecoverable
situation, one in which no function name has been redefined;  i'll
ignore this void case);
- conversely, if we are in an incompletely recoverable situation with n
function names redefined of which m are recoverable, recovering those m
leads to a completely unrecoverable situation. 

note, 'unrecoverable' does not necessarily mean useless.

for the latter above (allowed approaches), i hope that using 'assign' is
ok.  you have already hinted a solution;  i believe, naively, that it
satisfies the requirement:

for (f in strsplit('remove rm :: .Primitive .Internal', split=' ')[[1]])
    assign(f, function() 'roobisch')

as far as i can see, this renders a completely unrecoverable, but still
pretty useful session.


vQ