简体   繁体   English

如何将代码`cons [A; B]`放入一个repl中,运行它,然后查看输出`(A。B)`?

[英]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接受两个原子作为输入参数AB ,并输出一个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的数学定义,其中AB是元变量:对于所有值ABconsAB上的应用是一个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的最佳起点。您可以尝试以下方法:

Please consult Cliki , the Common Lisp wiki. 请查阅Common Lisp Wiki Cliki

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Lisp中格式化REPL输出的数字精度? - How do I format the digit precision of my REPL output in Lisp? Lisp之间的区别(cons'a(cons'b'c))和(cons'a'(bc)) - Lisp difference between (cons 'a (cons 'b 'c)) and (cons 'a '(b.c)) 我想了解每行如何删除列表中的重复项,因此这是列表(abaaacc)给出(ab) - I would like to understand each line how this code removes duplicates in a list , so this is the list (a b a a a c c) gives (a b) 可以使用 cons 来做 ((a. b). (c. d)) 吗?如果不是,任何其他方式或点对不能有这样的第二个元素? - Can one use cons to do ((a . b) . (c . d)) and if not any other means or dot pair cannot have 2nd element like this? 如何在LFE REPL中显示长结果? - How do I display long results in LFE REPL? 如何在Slim中运行Lisp缓冲区并在emacs中查看其输出? - How can I run a lisp buffer in slime and see its output in emacs? 怎么做((A.B)。(C.D))在lisp中 - How to do ((A.B).(C.D)) in lisp 如何在Common Lisp REPL中查看docstrings和其他符号信息? - How to see docstrings and other symbol information in Common Lisp REPL? cons()的意外输出 - Unexpected output with cons() 如何仅使用缺点将值附加到现有列表中? - How do I append values in order to an existing list using only cons?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM