有人可以解释以下表达式吗
> (+)
0
> (+ 1)
1
> (- 1)
-1
> (/ 1)
1
> (/ 2)
1/2
> (/ 3)
1/3
Run Code Online (Sandbox Code Playgroud)
如果默认参数为 1,为什么(+ 1)return 1while (/ 2)return 1/2?
不应该(+ 1)回来2吗?
我最近一直在尝试学习 Common Lisp,这是我使用过的任何编程语言中最痛苦和最缓慢的学习过程。真的很烦我。即使 Notepad++ 显示括号对应什么,它仍然很痛苦。
我一直在尝试编写一个模拟库数据库的程序。我一直被告知"SYSTEM::%EXPAND-FORM: (NULL L) should be a lambda expression"- 我在 Stack Overflow 上读过其他帖子,说这与使用太多括号有关,但是在使用语法一个多小时后,没有任何效果。我希望你们中一些更有经验的 LISP 程序员能够看到我希望是新手的错误。谢谢你。代码如下。
(setq library nil)
(defun add_book(bookref title author publisher)
(setf (get bookref 'title) title)
(setf (get bookref 'author) author)
(setf (get bookref 'publisher) publisher)
(setq library (cons bookref library))
bookref)
(defun retrieve_by (property my_value)
(setq result nil)
(do ((L library (cdr L)))
(cond
((NULL L) result)
(equal (get (car L) property) my_value)
(cons (car L) result))))
Run Code Online (Sandbox Code Playgroud) 我&rest对普通 lisp 的作用感到困惑。这可能是一个代表我的意思的例子:
(defmacro switch (value &rest pairs)
....
)
Run Code Online (Sandbox Code Playgroud)
&rest 和pairs 到底是什么意思?
我正在尝试在 LISP 中定义一个宏,例如在不同文件中的这个调用函数
(set_name name My name is Timmy)
(set_name occupation I am a doctor )
(defmacro set_name (list)
(print list)
)
Run Code Online (Sandbox Code Playgroud) (defun interleave (x y)
(cond ((and (null x)(null y)) nil)
(t (cons (car x) (cons (car y) (interleave (cdr x) (cdr y)))))
Run Code Online (Sandbox Code Playgroud)
想知道上面的代码做什么?
在我的 shell 中,我正在尝试一些东西,并注意到并在我的let语句开头添加了换行符。
[86]> (setf A 5)
5
[87]> (let () (print 'hello) (print 'there) A )
;; this blank line right here
HELLO
THERE
5
Run Code Online (Sandbox Code Playgroud)
有没有删除额外的换行符?
我想从 Lisp 的文件夹中读取所有文本文件?当我使用shell脚本时,就像c中的“文件夹名/*.txt”一样。
我正在寻找一些内置函数或 Common Lisp 中的一些运算符,当输入为假布尔表达式时将返回“0”,当它为真时返回“1”。一个例子是:
(setq a 3)
(setq b (+ (bool-to-int (< 0 a)) 2)
(print "b should be 1 + 2 = 3")
Run Code Online (Sandbox Code Playgroud)
有没有办法在不定义自定义函数的情况下使用 Common Lisp 做到这一点?
我需要检查给定的流是否是终端流。例如,使用*standard-output*I do (equal (synonym-stream-symbol *standard-output*) *terminal-io*),但它返回 nil。
这很奇怪,因为(synonym-stream-symbol *standard-output*)返回*terminal-io*.
有任何想法吗?感谢您的任何建议。
如果我在没有自定义包的 REPL 中运行它,以下来自 Paul G 的OnLisp 的代码工作正常。当我定义一个包并与它一起使用时(in-package :mypackage)它不起作用——它总是t在case语句中采用这种情况:
(defun run-node (name)
(let ((n (gethash name *nodes*)))
(cond ((node-yes n)
(format t "~A~%>> " (node-contents n))
(case (read)
(yes (run-node (node-yes n))) ; never hits this in package
(t (run-node (node-no n)))))
(t (node-contents n)))))
Run Code Online (Sandbox Code Playgroud)