假设我要调用function foo,它需要2个参数a和b。(foo a b)。
在某些用例中,这些参数的值相互依赖,如下所示:
(let (a
b)
(if (something-p)
(progn
(setq a 'a1)
(setq b 'b1))
(progn
(setq a 'a2)
(setq b 'b2)))
(foo a b))
Run Code Online (Sandbox Code Playgroud)
是否有(lisp)模式用于此类问题?(还是我需要为此编写自己的宏?)
有时我喜欢用(format t ..).
为了防止源代码中出现长时间不可读的格式字符串,并使输出易于对齐,我使用(format t (concatenate 'string ....).
例子:
(format t (concatenate 'string
"some output~%"
" error-msg: ~a~%"
" uiop-cwd: ~a~%"
" uiop-file-exists: ~a~%")
"error foo"
(uiop:getcwd)
(uiop:file-exists-p "hello_world.bmp"))
Run Code Online (Sandbox Code Playgroud)
在 Common Lisp 中是否有更惯用的和编译时的方式来做同样的事情?