Adding an element to a list in Scheme
Posted
by user272483
on Stack Overflow
See other posts from Stack Overflow
or by user272483
Published on 2010-03-29T23:11:14Z
Indexed on
2010/03/30
14:43 UTC
Read the original article
Hit count: 345
I'm using R5RS Scheme and I just want to implement a function that returns the intersection of two given lists, but I can't do that because I cannot add an element to a list. Here is my code. How can I fix it? I'm really a beginner in Scheme - this is my first work using Scheme.
thx in advance..
(define list3 '())
(define (E7 list1 list2)
(cond
((null? list1)
list3)
((member (car list1) list2) (append list3 (list (car list1))))
)
(cond
((null? list1)
list3)
((not(null? list1)) (E7 (cdr list1) list2)
)
)
)
(E7 '(4 5) '(3 4))
© Stack Overflow or respective owner