From: Ben Lee
Subject: Newbie Question
Date: 
Message-ID: <acX7N6s=KPQ7GgGEPHJ6vBtPm1IB@4ax.com>
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?

From: Barry Margolin
Subject: Re: Newbie Question
Date: 
Message-ID: <ZJPK3.579$854.23402@burlma1-snr2>
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.
From: Coby
Subject: Re: Newbie Question
Date: 
Message-ID: <7tgr9b$npd$1@nnrp1.deja.com>
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.
From: Ian Wild
Subject: Re: Newbie Question
Date: 
Message-ID: <37FC6039.D3AE6313@cfmu.eurocontrol.be>
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++?
From: Tim Bradshaw
Subject: Re: Newbie Question
Date: 
Message-ID: <ey3670jxoxy.fsf@lostwithiel.tfeb.org>
* 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
From: David D. Smith
Subject: Re: Newbie Question
Date: 
Message-ID: <dds-0710991443130001@p057.bit-net.com>
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
From: Tim Bradshaw
Subject: Re: Newbie Question
Date: 
Message-ID: <ey33dvnx9xy.fsf@lostwithiel.tfeb.org>
* 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