The less-familiar parts of Lisp for beginners — symbol-macrolet

Our next obscure Lisp feature is the symbol-macrolet special operator.  This operator produces a context in which one or more symbols can be rewritten prior to evaluation.  While let, and similar operators, can shadow it, outside of that exception, the symbols are substituted according to the expansions supplied.

Here is some code to demonstrate the behaviour:

(defun demonstrate ()
  (let ((replacement-1 'my-new-fcn-1))
        ((my-fcn-1 replacement-1)
         (my-fcn-2 'rpl-2))
      (format t 
              "(my-fcn-1 my-fcn-2): ~A~%"
              (list my-fcn-1 my-fcn-2))
      (format t "Now, binding to shadow my-fcn-2~%")
      (multiple-value-bind (result my-fcn-2)
          (floor 10.4 1.2)
        (format t 
                "(my-fcn-1 my-fcn-2): ~A~%"
                (list my-fcn-1 my-fcn-2))))))

with output:
*slime-repl sbcl*
CL-USER> (demonstrate)
(my-fcn-1 my-fcn-2): (MY-NEW-FCN-1 RPL-2)
Now, binding to shadow my-fcn-2
(my-fcn-1 my-fcn-2): (MY-NEW-FCN-1 0.79999924)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


反垃圾邮件 / Anti-spam question * Time limit is exhausted. Please reload CAPTCHA.