how can i reimplement backquote in common lisp?

牧云@^-^@ 提交于 2019-12-11 04:52:14

问题


I have to remake backquote (with unquote and unquote-splicing) without using the builtins reader macros `,@ The behaviour expected is:

> (BACKQUOTE (A B (LIST ‘C ‘D) (COMA (LIST ‘E ‘F)
                               (COMA-AT (LIST ‘G ‘H)))
(A B (LIST ‘C ‘D) (E F) G H)

I try to do it with a macro but the results are no the expected.

Many thanks!!!

Any hints of what could be done?


回答1:


http://lib.store.yahoo.net/lib/paulgraham/glsbq.lisp has an example




回答2:


For Those Who well settle for a simple and incorrect solution but it works, while trying to understand the paul graham code:

(defmacro backquote (expr)
  (labels
      ((step (p n)
             (append p
                     (if (atom n) (list n)
                       (case (car n)
                         ('comma (list (eval (cadr n))))
                         ('comma-at (eval (cadr n))))))))
    (list 'quote (reduce #'step (cons () expr)))))

corrections and suggestions to improve it are welcome!



来源:https://stackoverflow.com/questions/4575993/how-can-i-reimplement-backquote-in-common-lisp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!