[英]Scheme lists with limited functions available
Is there any way to make or add to a list in Scheme with only these functions available: equal?, car, cdr, cons, cond, if, quote, +, *, null?, symbol? 在Scheme中,是否有任何方法可以在仅具有以下功能的情况下添加或添加到列表中:equal?,car,cdr,cons,cond,if,quote,+,*,null?,symbol? , integer?, any car/cdr variant, define, let.
,整数?,任何car / cdr变体,定义,让。 (You'll notice that the use of any #list or #append calls is not allowed).
(您会注意到,不允许使用任何#list或#append调用)。
I've tried cons several different ways, but it just gives things like '(0 . 10) rather than just (0 10) which would be ideal. 我已经尝试了几种不同的缺点,但是它只是给出了'(0。10)之类的信息,而不仅仅是给出(0 10)的理想情况。 Yes this is part of a larger assignment.
是的,这是较大任务的一部分。
In Scheme, a "proper list" ends with the empty list. 在Scheme中,“适当列表”以空列表结尾。 So, you can make
'(0 10)
like this: 因此,您可以像这样使
'(0 10)
:
(cons 0 (cons 10 '()))
In general, you can always add something to the front of a proper list with (cons new-element old-list)
, and you'll get a new proper list. 通常,您总是可以使用
(cons new-element old-list)
在适当列表的前面添加一些(cons new-element old-list)
,这样您将获得一个新的适当列表。 The cdr
of a non-null proper list is always itself a proper list. 非空正确列表的
cdr
本身始终是正确列表。 The car
can be anything. car
可以是任何东西。
The word cons
is short for "construct": it's the most primitive procedure for constructing lists. cons
是“ construct”的缩写:这是构造列表的最原始的过程。
In general: You can define ALL built in procedures, which are NOT "special forms", for your own. 通常:您可以为自己定义所有内置过程,这些过程不是“特殊形式”。
Define your own 定义自己的
(define (append-my List1 List2)
(if (null? List1)
list2
(cons (car List1)
(append-my (cdr List1) List2))))
In the book "Structure and Interpretation of Computer Programs" you find many definitions for built-in procedures. 在“计算机程序的结构和解释”这本书中,您会找到许多内置过程的定义。 Every body interested in Scheme or Lisp should study the first three chapters of SICP.
对Scheme或Lisp感兴趣的每个机构都应学习SICP的前三章。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.