Oddly, no-one has mentioned Lisp
. Lisp is the original self-modifying programming language. Sometimes it's elegant, sometimes it's just dirty
. Lisp code is just data, so you could store the text of a function in a variable, and modify it as needed, then redefine the definition of the function in the global context if you want, or keep the compiled version of the function as a variable, and call that (As ever in Common Lisp, other options probably exist). Alternatively, to access the text of a function foo, you could do:
If you define a function:
(lambda (x) (foo x))
Then you change the definition of foo, then the above function will call the new version of foo. This still works if the function is compiled.
All behaviour tested under Corman Lisp version 1.42
The standard for Common Lisp allows function-lambda-expression to return nil whenever it wants.