4 ms·
Leaving wrong explanation for posterity and to keep thread understandable. See everything after [edit] for corrected explantion This is an important distinct
by aidenn0 4y ago
Leaving wrong explanation for posterity and to keep thread understandable. See everything after [edit] for corrected explantion
This is an important distinction between (funcall #'foo ...) and (funcall 'foo ...) in Common Lisp as well. #'foo evaluates to the function named by the symbol foo, while 'foo evaluates to the symbol foo itself. So if you redefine the function named by the symbol foo any already compiled forms like (funcall #'foo) will still use the old version but (funcall 'foo) will use the new version.
[edit]
The above explanation is wrong; whenever #'foo is evaluated it will resolve to the current function slot for the symbol foo. Since the form (funcall #'foo) evaluates #'foo each time, it will naturally be affected by changes to the function-slot for foo. If you bind a variable to #'foo (like e.g. a route in a routing library as TFA does for clojure) then the evaluation happens when you bind the variable. See my reply to throwaway1x31 for a full example showing the difference.
- throwaway1x31 4y agoIn sbcl those two work the same.
- juki 4y agoThey don't. What aidenn0 said applies to all CL implementations, although with a small correction that it's not "any already compiled forms", but rather any variables/objects that already hold the value of `#'foo` that will keep pointing to the old definition. Compiled code calling `(funcall #'foo ...)` will get the new definition normally (unless `foo` is inlined).
- aidenn0 4y agoDerp, of course it does because (funcall #'foo) evaluates "#'foo" every time it runs. You need to bind (or assign) the value for it to actually show the difference: (defun bar () 3) (defvar *the-fn* #'bar) (defvar *the-sym* 'bar) (defun foo () (funcall *the-fn*)) (defun baz () (funcall *the-sym*)) Then at the REPL: CL-USER> (values (baz) (foo)) 3 3 CL-USER> (defun bar () 2) WARNING: redefining COMMON-LISP-USER::BAR in DEFUN BAR CL-USER> (values (baz) (foo)) 2 3