Page 1 of 1

Function that found matchs in nested Lisp

Posted: Fri Oct 02, 2015 1:40 pm
by Domus123
Hello guys,im kinda of new at common Lisp,so i dont know how to make this :
I need a fuction that look at list (A B C ) and find all the list that have at least one of the elements (A B C )
Ex: Input (A B C ) and have a globvar ((A 2 3 ) (3 B 1) (1 2 3) (4 5 C)) ,so my function should be abble to run all the list and find at least one element that match,if match, want to show this output :arrow: ( (A 2 3) (3 B 1) (4 5 C) )
Its like a search function
Did you guys know what should i do , or where should i start?

Re: Function that found matchs in nested Lisp

Posted: Mon Oct 05, 2015 9:27 pm
by Goheeca
That's quite simple:

Code: Select all

(defvar *x* '((a 2 3) (3 b 1) (1 2 3) (4 5 c)))

(defun atleast-filter (searched data)
  (remove-if-not #'(lambda (elem) (intersection searched elem)) data))

(atleast-filter '(a b c) *x*) ; => ((A 2 3) (3 B 1) (4 5 C))

Re: Function that found matchs in nested Lisp

Posted: Tue Oct 06, 2015 3:49 am
by Domus123
Thank you buddy,that works here . Just one more question , if i want to search without input *x* i could just do (lamda (elem) (intersection search elem)) *x*) and remove *x* in the input?

Re: Function that found matchs in nested Lisp

Posted: Tue Oct 06, 2015 6:23 am
by Goheeca
What input? *x* is just a variable, if you mean the standard input you have to read it and just call atleast-filter.

Re: Function that found matchs in nested Lisp

Posted: Wed Oct 07, 2015 9:38 am
by Domus123
Thank you !! That help me a lot !!