Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#1094 closed defect (notabug)

self-modified function doesn't behave correctly

Reported by: hasarkinn Owned by:
Priority: normal Milestone:
Component: IDE Version: trunk
Keywords: Cc:


(defun f () (setf (symbol-function 'f) (lambda () 1)) (f))

Such a function will cause an infinite loop when it is call at first time but when interupting and calling (f) again, it has been modified to (lambda () 1) I have tried several CL implementation and they all behave correctly, they return 1 and do not cause an infinite loop.

Change History (2)

comment:1 Changed 7 years ago by rme

  • Resolution set to notabug
  • Status changed from new to closed

You need to add a (declare (notinline f)) to get that to behave as you desire.

The compiler is allowed to assume that functional references to f within the body of (defun f ...) refer to the function being defined. This allows it to omit the implicit call to symbol-function on self-calls. Declaring the function notinline forbids the compiler from making that assumption.

This same issue affects tracing recursive functions, since trace works by changing what symbol-function returns. See also

comment:2 Changed 7 years ago by rme

Here is the part of the spec that talks about this: (in particular, see the fourth bullet item).

Note: See TracTickets for help on using tickets.