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 ( (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?
Function that found matchs in nested Lisp
Re: Function that found matchs in nested Lisp
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))
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
Re: Function that found matchs in nested Lisp
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
What input? *x* is just a variable, if you mean the standard input you have to read it and just call atleast-filter.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
Re: Function that found matchs in nested Lisp
Thank you !! That help me a lot !!