• KDallas_Multipass@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    10 months ago

    Not sure if you’re the author of the linked article, but a description of how the difference between defvar and defparameter is important in a language with a long running modifiable runtime would be useful to audiences not familiar with the topic.

    For inside, if you have a script that wants to keep track of the number of widgets made per hour, and you also need a place to define the rate of processing, picking defvar for the former and defparameter for the latter allows you to reload the script in the running instance without losing track of important state. You probably don’t want to reset the value of the widget count when you reload the script, but you might want the value set in the parameter to change

  • monkoose@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    10 months ago

    Second, redefining the F function will update its association (or binding) to the F symbol, but the previous function will still be available if it has been referenced somewhere before the update. For example:

    (setf (symbol-function 'foo) #'1+)
    (let ((old-foo #'foo))
      (setf (symbol-function 'foo) #'1-)
      (funcall old-foo 42))
    

    It still return 41 on sbcl

    • SlowValue@alien.topB
      link
      fedilink
      English
      arrow-up
      1
      ·
      10 months ago
      (lisp-implementation-type)
      ;; ⇒ "SBCL"
      (lisp-implementation-version)
      ;; ⇒ "2.3.10"
      (setf (symbol-function 'foo) #'1+)
      ;; ⇒ #
      (let ((old-foo #'foo))
        (setf (symbol-function 'foo) #'1-)
        (funcall old-foo 42))
      ;; ⇒ 43 (6 bits, #x2B, #o53, #b101011)