宏:值不是LIST类型

Gui*_*rme 2 lisp macros sbcl common-lisp

我正在尝试编写一个可以同时进行eazygnuplot:plot多个系列的宏.理想情况下,我想写的东西一样(plotlists lists),这里lists看起来是这样的:

'(((57 91)) ((83 1) (90 8) (78 18)) ((42 19)))
Run Code Online (Sandbox Code Playgroud)

也就是说,lists是一k对列表的列表(更具体地说,这是一个平面上的点列表,在用k均值聚类之后).我提到的宏应该扩展成类似的东西:

(eazy-gnuplot:plot (lambda ()
                     (dolist (p l1)
                       (format t "~&~A ~A" (first p) (second p)))))
(eazy-gnuplot:plot (lambda ()
                     (dolist (p l2)
                       (format t "~&~A ~A" (first p) (second p)))))
Run Code Online (Sandbox Code Playgroud)

......等等.我的想法是写这样的东西:

(defmacro plotlists (lists)
  `(progn ,@(mapcar #'(lambda (ll)
                        '(eazy-gnuplot:plot
                             (lambda ()
                                (dolist (p ll)
                                  (format t "~&~A ~A" (first p) (second p))))))
                    lists)))
Run Code Online (Sandbox Code Playgroud)

该宏由这样的函数调用scatter:

(defun scatter (lists)
  (eazy-gnuplot:with-plots (*standard-output* :debug t)
    (eazy-gnuplot:gp-setup :terminal '(:qt))
    (plotlists lists)
    (format t "~&pause mouse button1;~%")))
Run Code Online (Sandbox Code Playgroud)

但是,在SBCL上编译函数会产生一些警告和错误("变量LISTS已定义但从未使用 - 如何??";以及"LISTS值不是LIST类型").另外,根据编译器,由于某种原因,该"~&pause mouse button1;~%"部分是"无法访问的代码"并在编译时被删除.怎么会?

我对Lisp知之甚少,但这对我来说非常令人费解.有人有任何想法吗?

Gui*_*rme 5

所以,显然我接近这完全错了.没有必要使用宏,就像MACROEXPAND-1在表达式上运行一样明显.值LISTS不是类型,LIST因为它只是一个SYMBOL,这是宏扩展时唯一可用的东西.我只是用另一个替换了宏DOLIST:

(defun scatter (lists)
  (eazy-gnuplot:with-plots (*standard-output* :debug t)
    (eazy-gnuplot:gp-setup :terminal '(:qt))
    (dolist (cluster lists)
      (eazy-gnuplot:plot (lambda ()
                           (dolist (point cluster)
                             (format t "~&~A ~A" (first point) (second point))))))
    (format t "~&pause mouse button1;~%")))
Run Code Online (Sandbox Code Playgroud)