Hacker News new | ask | show | jobs
by jlarocco 2377 days ago
That's not true, though.

When running in the REPL (the most common way to interface with Lisp) the compile time and runtime Lisps are the same.

For example, here's a copy/paste from a REPL session that defines a macro that defines a function. The macro (at "compile time") prints information about the function (just its argument count) to stdout before using defun (itself a macro) to actually define the function.

Next I call the new function and print out a disassembly, just to show the function is in fact compiled

"CL-USER> " is the prompt in the REPL I use:

    CL-USER> (defmacro my-defun (name arguments &body body)
               (format t "Defining ~a, taking ~a arguments~%" name (length arguments))
               `(defun ,name ,arguments ,@body))
    MY-DEFUN
    CL-USER> (my-defun omg-2 (value) (* value value))
    Defining OMG-2, taking 1 arguments
    OMG-2
    CL-USER> (omg-2 34)
    1156
    CL-USER> (disassemble #'omg-2)
    ; disassembly for OMG-2
    ; Size: 33 bytes. Origin: #x52ED2714                          ; OMG-2
    ; 14:       498B5D10         MOV RBX, [R13+16]                ; thread.binding-stack-pointer
    ; 18:       48895DF8         MOV [RBP-8], RBX
    ; 1C:       488BD6           MOV RDX, RSI
    ; 1F:       488BFE           MOV RDI, RSI
    ; 22:       FF1425C0001052   CALL QWORD PTR [#x521000C0]      ; GENERIC-*
    ; 29:       488B75F0         MOV RSI, [RBP-16]
    ; 2D:       488BE5           MOV RSP, RBP
    ; 30:       F8               CLC
    ; 31:       5D               POP RBP
    ; 32:       C3               RET
    ; 33:       CC10             INT3 16                          ; Invalid argument count trap
    NIL
    CL-USER>

It is also possible to compile a Lisp program to an executable (or byte code or whatever) and run it, and not use the dynamic aspect of it.
1 comments

The code gets compiled (and macro expanded), before it is running. That's a definition of compile-time in Lisp.

In an interpreter version of Lisp, the interpreter may expand the macros at runtime.