[英]How do I put the code `cons[A;B]` in a repl, run it, and see the output `(A . B)`?
I found a LISP 1.5 Manual with some code in it. 我找到了LISP 1.5手册 ,其中包含一些代码。
This one is from Section 1.2 这是来自第1.2节
Examples
cons[A;B]=(A . B)
From reading through the manual it looks like the function cons
is taking two atoms as input arguments, A
and B
, and outputting an S-expression, (A . B)
. 通过阅读手册,看起来功能
cons
接受两个原子作为输入参数A
和B
,并输出一个S表达式(A . B)
。
Question: 题:
How do I put the code cons[A;B]
in a repl, run it, and see the output (A . B)
? 如何将代码
cons[A;B]
放入一个repl中,运行它,然后查看输出(A . B)
A。B (A . B)
?
I'm expecting to do something like: 我期望做类似的事情:
~ $ lisp1.5
> cons[A;B]
=> (A . B)
For example, if I went to https://www.ruby-lang.org/en/ and saw some code, I would copy it, type irb
into my shell and paste it. 例如,如果我去https://www.ruby-lang.org/en/看到一些代码,我将其复制,在外壳中键入
irb
并将其粘贴。
~ $ irb
irb(main):001:0> puts "Hello World!"
Hello World!
=> nil
Section 1.2 of the manual explains that this is only a notation, used to help readers distinguish between functions and S-expressions (emphasis mine). 手册的第1.2节解释说,这只是一种表示法,用于帮助读者区分函数和S表达式(强调我的意思)。
We shall introduce some elementary functions of S-expressions.
我们将介绍S表达式的一些基本功能。 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.
为了将函数与S表达式本身区分开 ,我们将函数名用小写字母I编写,因为原子符号仅由大写字母组成。 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.
作为分隔符或标点符号,我们将使用分号。
It is followed by an example: 下面是一个示例:
cons[A ; B] = (A . B)
The manual introduces Lisp, its evaluation model, the compiler, etc. The above is the mathematical definition of cons
, where A
and B
are metavariables: for all values A
and B
, the application of cons
on A
and B
is a cons-cell where the CAR part is A
and the CDR part B
. 手册介绍了Lisp,其评估模型,编译器等。上面是
cons
的数学定义,其中A
和B
是元变量:对于所有值A
和B
, cons
在A
和B
上的应用是一个cons单元。其中CAR部分为A
而CDR部分为B
If someone developed a denotational semantics to express Ruby's evaluation model, you would have the same kind of definitions. 如果有人开发了指称语义来表达Ruby的评估模型,那么您将具有相同的定义。 You can convert this notation if you want, ie you write
(cons 1 2)
to test it concretely. 您可以根据需要转换此表示法,即编写
(cons 1 2)
对其进行具体测试。 But the 1.5 manual is arguably not the best starting point for learning Common Lisp, as standardized since 1994. You could try the following ones, instead: 但是,自1994年以来,标准化的1.5手册可能并不是学习Common Lisp的最佳起点。您可以尝试以下方法:
Practical Common Lisp , Peter Seibel 实用普通口述 ,彼得·塞贝尔
Paradigms of Artificial Intelligence Programming , Peter Norvig 人工智能编程范例 ,彼得·诺维格
Please consult Cliki , the Common Lisp wiki. 请查阅Common Lisp Wiki Cliki 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.