i need to create this procedures: my-cons, my-car, my-cdr in Scheme.
It should work like this:
(define p1 (my-cons 3 8))
(p1 #t)
3
(p1 #f)
8
(my-car p1)
3
(my-cdr p1)
8
now, I have only this:
(define my-cons
(lambda (x y)
(cons x y)
(let ((a (car (cons x y))))
(lambda (a) (if (equal? a #f) y x)))))
but in this code i can’t apply my-cons or my-cdr on defined p1
Can someone help me with this?
First, there’s some extraneous code in
my-conswhich doesn’t seem to belong here. This is enough:(Also, you don’t need to compare a boolean value with
#tor#f— it’s usable inifas it is.)Now you have
my-consthat returns a function which returns eitherxorydepending on its arugment. You can use that when implementingmy-carandmy-cdr: