clisp - Lisp: to perform set union operation -


i 'am beginner in lisp.i use clisp in ubuntu.i have code here in lisp carry out union operation on 2 lists.the logic correct.but stuck @ error is:

*** - append: proper list must not end t

my code is:

(defun set-union (l1 l2) (cond   ((null l2)   ;if l2 null union l1 itself.    l1)   ((not (member (first l2) l1))  ;check if first member of l2 in l1 or not   (setq l1 (append (set-union l1 (rest l2)) (list (first l2))))) ;if not append union of l1 , rest of l2.  (t   (set-union l1 (rest l2)))   )) ;if second condition not true carry out union on l1 , rest of elements of l2 (setq l1 (list 'a 'c 'b 'g)) (setq l2 (list 'd 'g 't)) (set-union l1 l2) (print l1) 

i need help!!thanks.

(append (set-union l1 (rest l2)) (first l2)) 

at point of logic tries append (a c b g . t) , e, fails because first not proper list.

either use

(append (set-union l1 (rest l2)) (list (first l2))) 

or, better

(cons (first l2) (set-union l1 (rest l2))) 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -