Function that found matchs in nested Lisp

Discussion of Common Lisp
Post Reply
Domus123
Posts: 12
Joined: Fri Oct 02, 2015 1:29 pm

Function that found matchs in nested Lisp

Post by Domus123 » Fri Oct 02, 2015 1:40 pm

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?

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Function that found matchs in nested Lisp

Post by Goheeca » Mon Oct 05, 2015 9:27 pm

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.

Domus123
Posts: 12
Joined: Fri Oct 02, 2015 1:29 pm

Re: Function that found matchs in nested Lisp

Post by Domus123 » Tue Oct 06, 2015 3:49 am

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?

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Function that found matchs in nested Lisp

Post by Goheeca » Tue Oct 06, 2015 6:23 am

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.

Domus123
Posts: 12
Joined: Fri Oct 02, 2015 1:29 pm

Re: Function that found matchs in nested Lisp

Post by Domus123 » Wed Oct 07, 2015 9:38 am

Thank you !! That help me a lot !!

Post Reply