50 likes | 220 Views
Additional Scheme examples. (define f (lambda (x) (lambda (y) (lambda (z) (+ x y z) ) ) ) ) > f #<CLOSURE (x) #@lambda (lambda (y) (lambda (z) (+ x y z)))> > (f 1) #<CLOSURE (y) #@lambda (lambda (z) (+ x y z))> > ((f 1) 2)
E N D
Additional Scheme examples (define f (lambda (x) (lambda (y) (lambda (z) (+ x y z)) ) ) ) > f #<CLOSURE (x) #@lambda (lambda (y) (lambda (z) (+ x y z)))> > (f 1) #<CLOSURE (y) #@lambda (lambda (z) (+ x y z))> > ((f 1) 2) #<CLOSURE (z) #@lambda (+ x y z)> > (((f 1) 2) 3) 6
Additional Scheme examples ( mapcar '((a b) (c d) (e f)) ) ( mapcadr '((a b) (c d) (e f)) ) ( map(lambda (x) (cons 0 (list x))) '(a b c d) )
Additional Scheme examples (define (repeatedElems L) (if (list? L) (doRepeatedElems L) 'repeated_elems_not_a_list) ) (define (doRepeatedElems L) (cond ((null? L) ()) ((member (car L) (cdr L)) (cons (car L) (doRepeatedElems (deleteAll (car L) (cdr L))) ) ) (else (doRepeatedElems (cdr L))) ) )
Additional Scheme examples (define (deleteAll L Ls) (cond ((null? Ls) ()) ((equal? (car Ls) L) (deleteAll L (cdr Ls))) (else (cons (car Ls) (deleteAll L (cdr Ls)))) ) ) > (repeatedElems '(a b c a d e a f g e w c a i))