News for hackers. Stuff that matters.
Re:What is a programmable programming language? (2019) by lispm on Monday June 06, 2022 @05:25AM (#31638541)
A Lisp macro sees the actual source it encloses and this source does not need to adhere to any pre-defined syntax.

For example: we may want a macro which outputs the source it encloses, before execution:

  CL-USER 12 > (defmacro my-loop (&body things)
                `(progn
                   (pprint (list :doing-loop-with ',things))
                   (loop ,@things)))
  MY-LOOP

  CL-USER 13 > (my-loop for i from 1 upto 3 sum
                (my-loop for j upto 3
                  sum (* i j)))

  (:DOING-LOOP-WITH
   (FOR I FROM 1 UPTO 3 SUM (MY-LOOP FOR J UPTO 3 SUM (* I J))))
  (:DOING-LOOP-WITH (FOR J UPTO 3 SUM (* I J)))
  (:DOING-LOOP-WITH (FOR J UPTO 3 SUM (* I J)))
  (:DOING-LOOP-WITH (FOR J UPTO 3 SUM (* I J)))
  36
A normal function can't do that, since it does not get source as an argument, but just sees the arguments values.

Since a macro sees source, it can not only print it, but also simplify, transform, mutate, etc. the source.

There are no comments on this comment yet.