小编Sma*_*isp的帖子

在普通的lisp中使用&allow-other-keys

我想制作最通用的函数,并决定使用键作为参数.我想使用,allow-other-keys因为我想使用任何键的功能.

让我演示给你看:

(defun myfunc (a &rest rest &key b &allow-other-keys)
  ;; Print A
  (format t "A = ~a~%" a)

  ;; Print B if defined
  (when b
    (format t "B = ~a~%" b))

  ;; Here ... I want to print C or D or any other keys
  ;; ?? 
)

(myfunc "Value of A")
(myfunc "Value of A" :b "Value of B")
(myfunc "Value of A" :b "Value of B" :c "Value of C" :d "Value of D")
Run Code Online (Sandbox Code Playgroud)

我知道这 …

common-lisp

6
推荐指数
1
解决办法
738
查看次数

使用变量作为公共 lisp 中的值创建关联列表

我正在寻找创建一个以变量作为值的关联列表(common lisp)。

让我用(虚拟)代码更好地解释:

(defun mylist-create (val1 val2)
  (setq alist '((key1    . val1)
                (key2     . val2)))
  ;; do other things here
  ;; and return the list 
  alist)

(format t "~a~%" (mylist-create "toto" "tata"))
Run Code Online (Sandbox Code Playgroud)

这里的问题是“val1”和“val2”不被视为变量,因为列表不是用它们的值创建的,而是用它们的名称创建的。

如何在列表创建中提取它们的价值?“setf and assoc”是添加键/值对的唯一解决方案吗?

lisp list common-lisp

3
推荐指数
1
解决办法
735
查看次数

标签 统计

common-lisp ×2

lisp ×1

list ×1