I just asked a similar question and got the answer I needed, but his time I cannot find any extra parenthesis that would be causing this error: "Error: (4 6 5 87 7) is not a function". Is it due to something else? My code takes a number and if it is already in the list, it does not add it. If the list does not already contain the number, then it adds it.
(define (insert x ls)
(insertHelper x ls '() 0)
)
(define (insertHelper x ls lsReturn counter)
(cond
(
(and (null? ls) (= counter 0))
(reverse (cons x lsReturn))
)
(
(and (null? ls) (>= counter 1))
(reverse lsReturn)
)
(
(eqv? x (car ls))
(insertHelper x (cdr ls) (cons (car ls) lsReturn) (+ counter 1))
)
(
else ((insertHelper x (cdr ls) (cons (car ls) lsReturn) (+ counter 0)))
)
)
)
(define theSet (list 4 6 5 87))
(display theSet)
(display "\n")
(display (insert 7 theSet))