I my self study of LISP, I'm trying to write programs that do what I
did in C++. I'm stuck on this one who do I make a predicate function
which has two arguments and yields a list that is a modified copy of
the second argument containing only those elements that contain at
least one instance of the first argument as a sublist?
In article <····························@4ax.com>,
Ben Lee <········@netdoor.com> wrote:
>I my self study of LISP, I'm trying to write programs that do what I
>did in C++. I'm stuck on this one who do I make a predicate function
>which has two arguments and yields a list that is a modified copy of
>the second argument containing only those elements that contain at
>least one instance of the first argument as a sublist?
Write a predicate that implements your selection criteria, and then pass it
as the :TEST option to REMOVE. The predicate will receive the first
argument and an element of the second argument as parameters, and should
return a truth value indicating whether it should be removed from the
result.
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
In article <····························@4ax.com>,
Ben Lee <········@netdoor.com> wrote:
> I my self study of LISP, I'm trying to write programs that do what I
> did in C++. I'm stuck on this one who do I make a predicate function
> which has two arguments and yields a list that is a modified copy of
> the second argument containing only those elements that contain at
> least one instance of the first argument as a sublist?
>
is this the behavior you are looking for?
(defun this-predicate (arg1 arg2)
(remove arg1 arg2
:test #'(lambda (a b)
(if (listp b)
(not (member a b :test #'equal))
t))))
(this-predicate '(a) '((1 2 3) (a) ((a) (b) (c)) foo a))
==>(((A) (B) (C)))
(this-predicate 'a '((1 2 3) (a) (a b c) ((a) (b) (c)) foo a))
==>((A) (A B C))
Perhaps more readable would be to define the supporting function and
use it by name instead of a lambda eg:
(remove arg1 arg2 :test #'not-in-sublist)
or something. Then you can throw in some recursion!
Coby
Sent via Deja.com http://www.deja.com/
Before you buy.
Ben Lee wrote:
>
> I my self study of LISP, I'm trying to write programs that do what I
> did in C++. I'm stuck on this one who do I make a predicate function
> which has two arguments and yields a list that is a modified copy of
> the second argument containing only those elements that contain at
> least one instance of the first argument as a sublist?
Cripes! Did you /really/ do this in C++?
* Ben Lee wrote:
> I my self study of LISP, I'm trying to write programs that do what I
> did in C++. I'm stuck on this one who do I make a predicate function
> which has two arguments and yields a list that is a modified copy of
> the second argument containing only those elements that contain at
> least one instance of the first argument as a sublist?
Could you show us the C++ code to do this so we can understand what
you mean better?
--tim
In article <···············@lostwithiel.tfeb.org>, Tim Bradshaw
<···@tfeb.org> wrote:
> * Ben Lee wrote:
> > I my self study of LISP, I'm trying to write programs that do what I
> > did in C++. I'm stuck on this one who do I make a predicate function
> > which has two arguments and yields a list that is a modified copy of
> > the second argument containing only those elements that contain at
> > least one instance of the first argument as a sublist?
>
> Could you show us the C++ code to do this so we can understand what
> you mean better?
>
> --tim
(remove '(1 2 3)
'((1 2 3) (4 5 6) (7 8 9 1 2 3) (5 1 7 2 9 3))
:test-not #'search)
=>
((1 2 3) (7 8 9 1 2 3))
d
* David D Smith wrote:
> (remove '(1 2 3)
> '((1 2 3) (4 5 6) (7 8 9 1 2 3) (5 1 7 2 9 3))
> :test-not #'search)
> =>
> ((1 2 3) (7 8 9 1 2 3))
I'm afraid I will have to throw you back into the river as you're not
the catch I was hoping for...
--tim