gpt4 book ai didi

common-lisp - 普通口齿不清 : what is the return value of prog2?

转载 作者:行者123 更新时间:2023-12-02 18:24:45 25 4
gpt4 key购买 nike

人们会期望 prog2 在返回计算第二个表达式的结果时与 prog1progn 有所不同分别代替第一个最后。然而,HyperSpec说了一些不同的话(强调我的):

prog2 evaluates first-form, then second-form, and then forms, yielding as its only value the primary value yielded by first-form.

这意味着 prog2 将返回与 prog1 相同的内容(事实上,行为也很相似)!

有趣的是,HyperSpec 中的示例证实了预期而不是指定行为:

(setq temp 1) =>  1
(prog2 (incf temp) (incf temp) (incf temp)) => 3
temp => 4
(prog2 1 (values 2 3 4) 5) => 2

这是标准中的拼写错误还是我错过了更深层次的内容?

最佳答案

这似乎是 known issue符合 ANSI 标准(完整列表可在 CLiki 上找到)。

我已经使用 SBCL 2.0.1 以及最新版本的 Allegro 对其进行了测试,在这两种情况下,它的行为都符合预期(而不是指定的):

CL-USER> (prog2
(print "1st")
(print "2nd")
(print "3rd"))

"1st"
"2nd"
"3rd"
"2nd"

想想看,即使是缩进似乎也表明了这一点。

关于common-lisp - 普通口齿不清 : what is the return value of prog2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70391918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com