简体   繁体   English

计划中的汽车和Cdr

[英]Car and Cdr in Scheme

So I've been learn Scheme for school, and have run into a situation using car and cdr series that doesn't quite make sense to me. 因此,我一直在学校学习Scheme,并且遇到了对我来说不太有意义的使用carcdr系列的情况。

So given a list: (define x '(1 2 3 4 5)) 因此给出一个列表:( (define x '(1 2 3 4 5))

How come (caddddr x) spits an error at me, while (cddddr x) returns (5) and (car (cddddr x)) returns 5 . (caddddr x)对我吐出错误,而(cddddr x)返回(5)(car (cddddr x))返回5

Isn't (caddddr x) the same as (car (cddddr x)) ? (caddddr x)是否与(car (cddddr x))

You can only put a few a 's and d 's in there :-) check the documentation , between the initial c and the final r there can be between 1 and 4 characters in any combination of a 's and d 's. 您只能在其中放几个ad :-)检查文档 ,起始c和末尾r之间可以有1-4个字符,而ad的任意组合。 If you need to access a specific element beyond that, consider using list-ref , which returns an element given its zero-based index on the list, for example: 如果您需要访问除此以外的特定元素,请考虑使用list-ref ,它会返回给定元素在列表中从零开始的索引,例如:

(define x '(1 2 3 4 5))
(list-ref x 4)
=> 5

Because the scheme definition goes up to (cddddr pair)‌‌ but not beyond. 由于该方案定义上升到(cddddr pair)‌‌ ,但无法超越。 In the words of the specification for car and cdr and friends: "Arbitrary compositions, up to four deep, are provided." carcdr和朋友的规范的话来说:“提供了最多四层的任意组合。” See (for example): 参见(例如):

http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_idx_620

And as has been noted elsewhere, list-ref is probably what you want in this case. 正如其他地方所指出的,在这种情况下, list-ref可能就是您想要的。

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

相关问题 方案:列表的CAR和CDR - Scheme: CAR and CDR of a list 在scheme / lisp中列出用car和cdr进行呼叫 - List calling with car and cdr in scheme/lisp 如何在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 CDR,CAR和REST,FIRST和可能的实施之间的区别? - Difference between CDR, CAR and REST, FIRST and possible implementation? LISP:采用任意的S表达式并递归地反转每个cons节点(节点的car和cdr) - LISP: take an arbitrary s-expression and reverse every cons node (car and cdr of a node) recursively 如何仅使用 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.? 优先选择 rest 而不是 car 和 cdr 的 lisp 如何处理 cdaddr 之类的组合? - How do lisps that prefer first and rest to car and cdr approach combinations like cdaddr? 为什么我不能在 Scheme 的这个 let 语句中使用 car? - Why can't I use car inside this let statement in Scheme?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM