简体   繁体   English

方案:列表的CAR和CDR

[英]Scheme: CAR and CDR of a list

I am confused as to how car and cdr work on lists. 我很困惑,如何carcdr上列出的工作。 Here is an example of what I have tried: 这是我尝试过的一个例子:

(define sample (read))
(display sample)
(display (car sample))
(display (cdr sample))
(display (car (cadr sample)))
(display (cdr (cdr sample)))

On entering the value '(ABCDEF) , here is what I get: 在输入值'(ABCDEF) ,我得到的是:

'(a b c d e f)
quote
((a b c d e f))
a
()

I am not able to understand that how quote can be the car of sample . 我无法理解quote如何成为sample car Also, why does (cdr sample) output ((abcdef)) ? 另外,为什么(cdr sample)输出((abcdef))

Language: DrScheme - R5RS - Scheme 语言:DrScheme - R5RS - Scheme

If you wanted to simply type the list (abcdef) , you should just type (abcdef) . 如果你只想输入列表(abcdef) ,你应该输入(abcdef) What you typed, instead, was (quote (abcdef)) because the ' operator is short for (quote ...) . 而你输入的是(quote (abcdef))因为'运算符是(quote ...)缩写。

Your list literally has the first element quote and the second element (abcdef) . 你的列表字面上有第一个元素quote和第二个元素(abcdef) Of course, when you're writing source code, you need the quote to prevent the S-expressions from being executed. 当然,在编写源代码时,需要使用quote来防止执行S表达式。

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

相关问题 在scheme / lisp中列出用car和cdr进行呼叫 - List calling with car and cdr in scheme/lisp 计划中的汽车和Cdr - Car and Cdr in Scheme 如何在Scheme中使用Car和Cdr打破(11(12 13)) - How to break (11 (12 13)) using Car and Cdr in Scheme 方案:返回可以使用car和cdr的任意组合获得的表达式的所有元素 - Scheme: Return all elements of an expression that can be obtained using any combination of car and cdr 如何仅使用 car、cdr、cons 和其他函数拆分列表 (python) - How to split a list only using car, cdr, cons and other functions (python) 如何使用 car cdr caar caddr 等访问 raket 中的嵌套列表? - How do I access nested list in raket using car cdr caar caddr etc.? CDR,CAR和REST,FIRST和可能的实施之间的区别? - Difference between CDR, CAR and REST, FIRST and possible implementation? 反转方案语言中的列表。 错误:汽车:违反合同预期:对? 给定:一个 - Invert list in Scheme Language. Mistake: car: contract violation expected: pair? given: a LISP:采用任意的S表达式并递归地反转每个cons节点(节点的car和cdr) - LISP: take an arbitrary s-expression and reverse every cons node (car and cdr of a node) recursively 优先选择 rest 而不是 car 和 cdr 的 lisp 如何处理 cdaddr 之类的组合? - How do lisps that prefer first and rest to car and cdr approach combinations like cdaddr?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM