News for hackers. Stuff that matters.
Re:Ask HN: Guide for Implementing Common Lisp by lispm on Friday February 02, 2024 @03:17AM (#39226371)
reader macros create Lisp data.

The compiler/interpreter gets as input Lisp data. Let's use READ, DESCRIBE and EVAL to see that working:

    CL-USER 17 > (defun example (&aux input result)
                   (terpri)                    ; newline
                   (write-string "Input> ")
                   (finish-output)
                   (terpri)
                   (setf input (read))         ; reading from input stream
                   (terpri)
                   (describe input)            ; what did we read?
                   (terpri)
                   (write-string "Output>")
                   (setf result (eval input))  ; evaluation
                   (terpri)
                   (write-string "Result>")
                   (print result)              ; printing the result
                   (values))                   ; return nothing
    EXAMPLE

    CL-USER 18 > (example)

    Input> 
    (progn
      (print (+ 1 3))
      (print 'done))

    (PROGN (PRINT (+ 1 3)) (PRINT (QUOTE DONE))) is a LIST
    0      PROGN
    1      (PRINT (+ 1 3))
    2      (PRINT (QUOTE DONE))
    Output>
    4 
    DONE 
    Result>
    DONE
As you can see READ in actual Lisp takes input from the keyboard and returns a list as data.

EVAL is then taking code as a list and evaluates it to a value, as side effects there might be printed output of the program.

There are no comments on this comment yet.