3 ms·
Not only can you redefine classes and functions at runtime in CL, my understanding is that all references to them will automatically be updated to the new code
by apgwoz 4y ago
Not only can you redefine classes and functions at runtime in CL, my understanding is that all references to them will automatically be updated to the new code (I think unless it’s compiled?). It was already mentioned that Python’s classes come up short here, and I bet there are lots of cases where functions, too, miss the mark.
- gumby 4y agoAll implementations can update the function because all function calls are resolved at runtime (e.g. the symbol is examined). I don’t know what happens with inlines and macros though — don’t know if any implementations recompile those.
- thelopa 4y agoIn most implementations, redefining an inline function or macro just means you may have some callers using the old code. SBCL warns if you redefine an inline function but doesn’t re-compile old code. Do note that the language has a different view on the matter though. In its list of assumptions compilers are allowed to make about the code they receive, we can see… > The definition of a function that is defined and declared inline in the compilation environment must be the same at run time. > Within a function named F, the compiler may (but is not required to) assume that an apparent recursive call to a function named F refers to the same definition of F, unless that function has been declared notinline. The consequences of redefining such a recursively defined function F while it is executing are undefined. > A call within a file to a named function that is defined in the same file refers to that function, unless that function has been declared notinline. The consequences are unspecified if functions are redefined individually at run time or multiply defined in the same file. http://clhs.lisp.se/Body/03_bbc.htm http://clhs.lisp.se/Body/03_bbc.htm So, technically the compiler is allowed to remove runtime function call indirection for functions defined in the same file and/or recursive calls (unless you use a NOTINLINE declaration). In practice, you probably won’t see that happen unless you crank up the optimizations when compiling. You are right that the language explicitly allows redefining functions in general > Except in the situations explicitly listed above, a function defined in the evaluation environment is permitted to have a different definition or a different signature at run time, and the run-time definition prevails.
- whartung 4y agoThe thing is the CLOS has specific support for updating existing class instances at runtime. Many languages do not. I don't know if Python does that.