This program is written using Drscheme. Drscheme is a compiler for scheme which is a dialect of LISP. To get a free copy of Drscheme, pls go here http://download.plt-scheme.org/drscheme/
This simple program will remove the first occurence of a specified element from list. for example, you have a list like this 2 3 4 5 and you want to remove 3 from the list and your new list will be 2 4 5.
(define (remove x lis) (if (member x lis)(cond
((equal? x (car lis)) (cdr lis))
(else (cons (car lis) (remove x (cdr lis)))))
lis)
)
That is it, now lets see if the program works. type this below your program window and click run from the compiler menu.
(remove 3 ‘(1 2 3 3 4))
(remove 2 ‘(3 2 4))
(remove 2 ‘(2))
Your answer should be as follows
1 2 3 4
3 4
()
For any corrections, pls add it as a comment so we can all improve on our LISP programing.
(remove 1 ‘(3 2 4))