Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!jpl-devvax!charest From: charest@ai-cyclops.jpl.nasa.gov Newsgroups: comp.lang.lisp Subject: Self-modifying function Message-ID: <11609@jpl-devvax.JPL.NASA.GOV> Date: 27 Feb 91 23:01:27 GMT Sender: news@jpl-devvax.JPL.NASA.GOV Organization: NASA/Jet Propulsion Lab Lines: 27 I want to define a function that performs a certain computation on its first invocation and performs a different computation on all subsequent invocations. Consider the trivial (but representative) example below: (defun mutate (list) (let ((len (length list))) (prog1 list (compile 'mutate `(lambda () ,len))))) 1> (mutate '(a b c)) => (a b c) 2> (mutate '(a b c)) => Error: too many arguments to function mutate. 3> (mutate) => 3 My question is, Will this function behave as expected (i.e., as described above) in any Common LISP? More specifically, is it safe to modify the contents of a symbols' function cell even as the contents are being executed? I can find nothing in CLtL2 that addresses this. I welcome all opinions, learned or otherwise. -Len Charest charest@ai-cyclops.jpl.nasa.gov