- Code: Select all
`Gotten output:`

> (intersect '(a b c) '( b a c))

a b c

>(intersect '(a (b c) d) '(a b c d))

a d

>(intersect '(a b (c f)) '(a d (c f) e) )

a

- Code: Select all
`Expected output:`

> (intersect '(a b c) '( b a c))

a b c

>(intersect '(a (b c) d) '(a b c d))

a d

>(intersect '(a b (c f)) '(a d (c f) e) )

a (cf)

As you see, if there are two same lists in the lists it should be printed. If there are same elements in two lists but one and more often in other list in list, it shouldn't be printed as you see in the second. How can I get the expected output? Could you fix my code:

- Code: Select all
`(defun printelems (A B)`

(if (eq A ())

A

(if (member (first A) B)

(cons (first A) (printelems (rest A) B))

(printelems (rest A) B))))