如何并排打印LISP列表?

时间:2018-09-07 05:27:40

标签: lisp common-lisp

我有两个清单

(defvar product-list (list "apple" "banana") )
(defvar price-list (list 5 10) )

我想将此打印为

  

苹果:5

     

香蕉:10

如何执行此操作?

2 个答案:

答案 0 :(得分:5)

您可以使用循环,例如:

(defvar product-list (list "apple" "banana") )
(defvar price-list (list 5 10) )

(loop for product in product-list
      for price in price-list
      do (format t "~A : ~A~%"
                 product
                 price))

答案 1 :(得分:4)

loop

(format nil "~{~{~A~T:~T~A~}~^~%~}"
        (mapcar
         (function list)
         (list "apple" "banana")
         (list 5 10)))

返回:

"apple : 5
banana : 10"

参考:

一些格式食谱:http://www.gigamonkeys.com/book/a-few-format-recipes.html