Path: utzoo!attcan!uunet!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.edu!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.lang.lisp Subject: Re: Self-modifying function Message-ID: <1991Feb28.053846.1858@Think.COM> Date: 28 Feb 91 05:38:46 GMT References: <11609@jpl-devvax.JPL.NASA.GOV> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 32 In article <11609@jpl-devvax.JPL.NASA.GOV> charest@ai-cyclops.jpl.nasa.gov writes: >More specifically, is it safe to modify the contents >of a symbols' function cell even as the contents are being executed? I believe it is, but there are some rules. CLtL doesn't address these problems, but the X3J13 Compiler Committee did some work to tighten up this area. Here are relevant excerpts from the proposal that was approved: (b) The compiler may assume that, within a named function, a recursive call to a function of the same name refers to the same function, unless that function has been declared NOTINLINE. (c) COMPILE-FILE may assume that, in the absence of NOTINLINE declarations, a call within the file being compiled to a named function which is defined in that file refers to that function. (This permits "block compilation" of files.) The behavior of the program is unspecified if functions are redefined individually at runtime. Point (b) is not directly applicable to your example, but it would be to a modified version that ends with a recursive call to the function. However, point (c) is applicable if there are calls to the function in other parts of the file. In both cases, preceding the definition with a (proclaim '(notinline mutate)) should make things safe. -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar