Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; APPEND
- (define my-append
- '(lambda-rec (append xs ys) (if (null? xs)
- ys
- (cons (car xs) (append (cdr xs) ys)))))
- (define append-test (list my-append '(cons 1 (cons 2 null)) '(cons 3 (cons 4 null))))
- ;; MAP
- (define my-map
- '(lambda-rec (map proc args) (if (null? args)
- null
- (cons (proc (car args))
- (map proc (cdr args))))))
- (define map-test (list my-map '(lambda (x) (* x x)) '(cons 2 (cons 3 (cons 4 null)))))
- ;; REVERSE
- (define my-reverse
- '(lambda-rec (reverse xs) (let (append (lambda-rec (append xs ys) (if (null? xs)
- ys
- (cons (car xs) (append (cdr xs) ys)))))
- (if (null? xs)
- null
- (append (reverse (cdr xs))
- (cons (car xs) null))))))
- (define reverse-test (list my-reverse '(cons 1 (cons 2 (cons 3 (cons 4 null))))))
- ;;TESTY:
- ;-append
- (eval append-test)
- ;-map
- (eval map-test)
- ;-reverse
- (eval reverse-test)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement