Element
Delete all Occurrences of an Element from a List Using Scheme Source Code
The following code deletes all occurrences of an element from a list
CODE
(define deleteall( lambda (x y)
(if (null? y )
()
(if (eqv? (car y) x)
(deleteall x (cdr y))
(cons (car y) (deleteall x (cdr y)))))))
Delete the Nth Occurrence of an Element from a List with Set! Using Scheme Source Code
The following code deletes the Nth occurrence of an element from a List with Set!
Delete the Nth Occurrence of an Element from a List without Set! Using Scheme Source Code
The following code deletes the Nth occurrence of an element from a list without using Set!
Check if an Element is a Member of a List using Scheme Source Code
The following code checks if an element is a member of a list
CODE
(define (member? x y)
(cond ((null? y) #f)
((eqv? x (car y)) #t)
(else (member? x (cdr y)))))
RESULT
> (member_list 'd '(a x c v b))
#f
> (member? 'f '(a s d f g h))
#t
Replace an Element from a List using Scheme Source Code
The following code replaces an element from a list
CODE
(define replace( lambda (x b y)
(if (null? y )
()
(if (eqv? (car y) x)
(cons b (replace x b (cdr y)))
(cons (car y) (replace x b (cdr y)))))))
