News for hackers. Stuff that matters.
Re:The Bipolar Lisp Programmer by kragen on Friday August 11, 2023 @01:33PM (#37091398)
> If I type a defun into a REPL, is there a good way to get source code back out again?

this used to be the normal way of programming in lisp repls (like in 01980) but maybe this is good enough

    * (defun tri (n) (loop for i from 1 to n summing n))
    TRI
    * (describe 'tri)
    COMMON-LISP-USER::TRI
      [symbol]

    TRI names a compiled function:
      Lambda-list: (N)
      Derived type: (FUNCTION (T) (VALUES NUMBER &OPTIONAL))
      Source form:
        (LAMBDA (N)
          (BLOCK TRI
            (LOOP FOR I FROM 1 TO N
                  SUMMING N)))
> When I go to load my code back in, I get errors, because oops I was actually still calling that deleted function somewhere -- it "worked" before because the old function was still hanging out in the image.

so a thing you can do in that case is to delete it from the image at the same time

well, you can't really delete it from the image, but you can remove the function binding of the symbol, and since normally in common lisp implementations function calls indirect through the symbol (which is why you can replace the definition with a newer one) deleting the function binding is enough

    * (defun tri0 (n) (tri (1+ n)))
    TRI0
    * (tri0 4)
    25
    * (tri0 5)
    36
    * (fmakunbound 'tri)
    TRI
    * (tri0 5)

    debugger invoked on a UNDEFINED-FUNCTION @52A00674 in thread
    #<THREAD "main thread" RUNNING {1001348003}>:
      The function COMMON-LISP-USER::TRI is undefined.

    Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

    restarts (invokable by number or by possibly-abbreviated name):
      0: [CONTINUE      ] Retry calling TRI.
      1: [USE-VALUE     ] Call specified function.
      2: [RETURN-VALUE  ] Return specified values.
      3: [RETURN-NOTHING] Return zero values.
      4: [ABORT         ] Exit debugger, returning to top level.

    ("undefined function" 6)
    0] 
as rainer pointed out, slime has a command for this (i barely use cl myself, you know much more than i do)

There are no comments on this comment yet.