Plaster
New
List
Login
common-lisp
default
anonymous
2023.12.09 19:17:33
;;;; Different results observed depending on whether FUNCTION or SYMBOL-FUNCTION is used. ;;;; In both cases it's expected that FF will be bound to the original value of F, thus ;;;; returning 1. However, using FUNCTION the evaluation of DEFUN changes the value of ;;;; FF, effectively setting it to the function produced by evaluating the DEFUN form. ;;;; This happens with SBCL 2.3.10. ;;;; CLISP 2.49.93+, on the other hand, produces expected results. (defun f () 1) (format t "Using FUNCTION~%") (let ((ff (function f))) (format t "Before DEFUN: F -> ~a, FF -> ~a~%" (f) (funcall ff)) (defun f () 2) (format t "After DEFUN: F -> ~a, FF -> ~a~%" (f) (funcall ff)) (setf (symbol-function 'f) ff) (format t "After rebinding the old function: F -> ~a, FF -> ~a~%" (f) (funcall ff))) ;;; --------------------------------------------- (defun f () 1) (format t "~%Using SYMBOL-FUNCTION~%") (let ((ff (symbol-function 'f))) (format t "Before DEFUN: F -> ~a, FF -> ~a~%" (f) (funcall ff)) (defun f () 2) (format t "After DEFUN: F -> ~a, FF -> ~a~%" (f) (funcall ff)) (setf (symbol-function 'f) ff) (format t "After rebinding the old function: F -> ~a, FF -> ~a~%" (f) (funcall ff)))
Raw
Annotate
Repaste
Edit