scheme - 为什么方案中的 `and` 运算符不是内置过程

标签 scheme lisp

我使用 chicken Scheme 解释器,当我输入 not 时, 它返回 #<procedure (not x295)> , 但当我尝试 andor , 它返回 Error: unbound variable: and .

似乎 and运算符不是内置过程,为什么它不同于 not

如果这是真的,那么(and #t #f)又如何呢?评价?

最佳答案

andor 是“短路运算符”——它们不会计算超过形成结果所必需的值,就像 ifcond。例如:

(and #f (display "foo"))

不会显示任何东西,这也不会:

(or #t (display "foo"))

使用过程不可能做到这一点,因为对过程的调用将在进入过程之前评估所有参数:

(define (proc-or x y) (if x #t (if y #t #f)))
(proc-or #t (display "foo"))
; displays "foo" anyway

if(或者,实际上,or)这样的特殊形式可以决定它希望评估哪些参数。请参阅任何有关条件运算符或更一般的特殊形式(例如 MIT SchemeRacket ...)的 Scheme 手册

更具体地说,orand 要么是原始形式(如 if),要么是将运算符转换为一系列的宏原始形式。

关于scheme - 为什么方案中的 `and` 运算符不是内置过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26902224/

相关文章:

recursion - 使用递归辅助函数检查素数

scheme - SICP 练习 1.3 征求意见

list - 循环列表的神秘方案程序

scala - Lisp是REPL唯一的语言吗?

list - 如何在 Lisp 中打印嵌套列表中的最大值和最小值

functional-programming - AutoLISP:如何解决无函数定义错误?

lisp - 实现同时绑定(bind)

macros - 如何在 lisp 中用 if 形式定义递归 cond 宏?

clojure - 等价于 'lein swank' 到其他带有 emacs/slime 的 Lisp/Scheme 实现

parsing - 使用 flex/bison 构建类似 Lisp/Scheme 的解析树