From: Henry W
Subject: SUBST
Date: 
Message-ID: <37935cd0.553941@nntpserver.swip.net>
How would I go about replacing a list of lists with another list of
lists (in another list)? I thought SUBST was supposed to work on all
levels, but apparently, it doesn't. How do I solve this?

Best
Henry

From: Lieven Marchand
Subject: Re: SUBST
Date: 
Message-ID: <m3673gh30h.fsf@localhost.localdomain>
········@hotmail.com (Henry W) writes:

> How would I go about replacing a list of lists with another list of
> lists (in another list)? I thought SUBST was supposed to work on all
> levels, but apparently, it doesn't. How do I solve this?

May this offer you enlightenment ;-)

USER(2): (defvar *tree* '(((foo) (bar baz) ((qux quux quuuux)))))
*TREE*
USER(3): (subst '(this is replacement) '(qux quux quuuux) *tree*)
(((FOO) (BAR BAZ) ((QUX QUUX QUUUUX))))
USER(4): (subst '(this is replacement) '(qux quux quuuux) *tree* :test #'equal)
(((FOO) (BAR BAZ) ((THIS IS REPLACEMENT))))

BTW: The CLHS doesn't specify what is the default value of the :test
argument. Was this deliberate or an oversight?

-- 
Lieven Marchand <···@bewoner.dma.be>
If there are aliens, they play Go. -- Lasker
From: Steven M. Haflich
Subject: Re: SUBST
Date: 
Message-ID: <3793B622.20F4D7F3@franz.com>
Lieven Marchand wrote:
 
> BTW: The CLHS doesn't specify what is the default value of the :test
> argument. Was this deliberate or an oversight?

See 17.2.1 Satisfying a Two-Argument Test.
From: Henry W
Subject: Re: SUBST
Date: 
Message-ID: <37943e99.1090504@nntpserver.swip.net>
On 19 Jul 1999 21:07:42 +0200, Lieven Marchand <···@bewoner.dma.be>
wrote:

>········@hotmail.com (Henry W) writes:
>
>> How would I go about replacing a list of lists with another list of
>> lists (in another list)? I thought SUBST was supposed to work on all
>> levels, but apparently, it doesn't. How do I solve this?
>
>May this offer you enlightenment ;-)
>
>USER(2): (defvar *tree* '(((foo) (bar baz) ((qux quux quuuux)))))
>*TREE*
>USER(3): (subst '(this is replacement) '(qux quux quuuux) *tree*)
>(((FOO) (BAR BAZ) ((QUX QUUX QUUUUX))))
>USER(4): (subst '(this is replacement) '(qux quux quuuux) *tree* :test #'equal)
>(((FOO) (BAR BAZ) ((THIS IS REPLACEMENT))))

Thanks, but what if the original list of lists is static? (i.e. I
can't specity it by defvar:ing the *tree*?) (Secondly, does this
approach really work when both arguments are list of lists?)

/Henry
From: Barry Margolin
Subject: Re: SUBST
Date: 
Message-ID: <OH4l3.1470$KM3.430010@burlma1-snr2>
In article <················@nntpserver.swip.net>,
Henry W <········@hotmail.com> wrote:
>On 19 Jul 1999 21:07:42 +0200, Lieven Marchand <···@bewoner.dma.be>
>wrote:
>
>>········@hotmail.com (Henry W) writes:
>>
>>> How would I go about replacing a list of lists with another list of
>>> lists (in another list)? I thought SUBST was supposed to work on all
>>> levels, but apparently, it doesn't. How do I solve this?
>>
>>May this offer you enlightenment ;-)
>>
>>USER(2): (defvar *tree* '(((foo) (bar baz) ((qux quux quuuux)))))
>>*TREE*
>>USER(3): (subst '(this is replacement) '(qux quux quuuux) *tree*)
>>(((FOO) (BAR BAZ) ((QUX QUUX QUUUUX))))
>>USER(4): (subst '(this is replacement) '(qux quux quuuux) *tree* :test #'equal)
>>(((FOO) (BAR BAZ) ((THIS IS REPLACEMENT))))
>
>Thanks, but what if the original list of lists is static? (i.e. I

The approach is not dependent on how the lists are specified.

>can't specity it by defvar:ing the *tree*?) (Secondly, does this
>approach really work when both arguments are list of lists?)

Yes.  The test is done before recursing into subtrees.

The only difference between the failing and working solution is the test.
You were probably letting the test default to EQL, as in the first SUBST.
Since each time you type a list the reader creates new conses to hold it,
it will never be EQL to something in the original list of lists.  By using
EQUAL instead of EQL, you compare them in a way that allows for this.

Alternatively, you could rewrite your code so that the parameter to SUBST
really is a piece of the original list of lists, rather than something that
just looks like it.  E.g.

(defvar *a* '(1 2 3))
(defvar *b* '(a b c))
(defvar *c* '(x y z))
(defvar *tree* (list *a* *b*))

(subst *c* *b* *tree*) =>
((1 2 3) (X Y Z))

-- 
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: Lieven Marchand
Subject: Re: SUBST
Date: 
Message-ID: <m3wvvvb4kz.fsf@localhost.localdomain>
········@hotmail.com (Henry W) writes:

> On 19 Jul 1999 21:07:42 +0200, Lieven Marchand <···@bewoner.dma.be>
> wrote:
> 
> >········@hotmail.com (Henry W) writes:
> >
> >> How would I go about replacing a list of lists with another list of
> >> lists (in another list)? I thought SUBST was supposed to work on all
> >> levels, but apparently, it doesn't. How do I solve this?
> >
> >May this offer you enlightenment ;-)
> >
> >USER(2): (defvar *tree* '(((foo) (bar baz) ((qux quux quuuux)))))
> >*TREE*
> >USER(3): (subst '(this is replacement) '(qux quux quuuux) *tree*)
> >(((FOO) (BAR BAZ) ((QUX QUUX QUUUUX))))
> >USER(4): (subst '(this is replacement) '(qux quux quuuux) *tree* :test #'equal)
> >(((FOO) (BAR BAZ) ((THIS IS REPLACEMENT))))
> 
> Thanks, but what if the original list of lists is static? (i.e. I

I don't know what you mean by static. If you mean constant, that's no
problem. SUBST makes a fresh copy.

> can't specity it by defvar:ing the *tree*?) (Secondly, does this
> approach really work when both arguments are list of lists?)

Sure, EQUAL will test the subtree at each node.

-- 
Lieven Marchand <···@bewoner.dma.be>
If there are aliens, they play Go. -- Lasker