So, from the SICP we know that the cons
car
and cdr
can be defined as a procedure:
(define (cons x y)
(lambda (m) (m x y)))
(define (car z)
(z (lambda (p q) p)))
(define (cdr z)
(z (lambda (p q) q)))
But the pre-defined procedure list
, which takes the arguments to build a list, uses the original cons
. That means, a list that list
built, isn't a procedure as I want.
(car (list 1 2 3))
;The Object (1 2 3) is not applicable
So i write this:
(define (list . l)
(if (null? l)
'()
(cons (original-car l)
(list (original-cdr l)))))
I just wondering how to define the original-car
and original-cdr
. Are there some way to make a copy of a procedure in Scheme? Or there's some alternate way to solve this problem. thx
(define original-car car)
? I don't think I get what you're trying to do. I use chicken scheme and(car '( 1 2 3))
works fine, as does(car (list 1 2 3))
.list
procedure to adapt my lambda-version cons and car/cdr.