gpt4 book ai didi

lisp - 如何将代码 `cons[A;B]` 放入 repl,运行它并查看输出 `(A . B)` ?

转载 作者:太空宇宙 更新时间:2023-11-03 18:53:20 24 4
gpt4 key购买 nike

我找到了一个 LISP 1.5 Manual里面有一些代码。

这个来自第 1.2 节

Examples

cons[A;B]=(A . B)

通过阅读手册,函数 cons 似乎将两个原子作为输入参数,AB,并输出一个S 表达式,(A . B)

问题:

如何将代码 cons[A;B] 放入 repl 中,运行它并查看输出 (A . B)

我希望做这样的事情:

~ $ lisp1.5
> cons[A;B]
=> (A . B)

例如,如果我去 https://www.ruby-lang.org/en/看到一些代码,我会复制它,在我的 shell 中输入 irb 并粘贴它。

enter image description here

~ $ irb
irb(main):001:0> puts "Hello World!"
Hello World!
=> nil

最佳答案

手册1.2节说明这只是一个符号,用来帮助读者区分函数和S表达式(重点是我的)。

We shall introduce some elementary functions of S-expressions. To distinguish the functions from the S-expressions themselves, we shall write function names in I lower case letters, since atomic symbols consist of only upper case letters. Furthermore, the arguments of functions will be grouped in square brackets rather than parentheses. As a separator or punctuation mark we shall use the semicolon.

后面是一个例子:

cons[A ; B] = (A . B)

手册介绍了Lisp、其评估模型、编译器等。以上是cons的数学定义,其中AB是元变量:对于所有值ABconsAB上的应用是一个cons-cell,其中CAR部分是 A 和 CDR 部分 B。如果有人开发了一种指称语义来表达 Ruby 的求值模型,你就会有相同类型的定义。您可以根据需要转换此表示法,即您编写 (cons 1 2) 来具体测试它。但是 1.5 手册可以说不是学习 Common Lisp 的最佳起点,它自 1994 年以来就已标准化。您可以尝试以下手册:

请咨询Cliki , Common Lisp 维基。

关于lisp - 如何将代码 `cons[A;B]` 放入 repl,运行它并查看输出 `(A . B)` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49080128/

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