From: Simon Pageot
Subject: Some help!
Date: 
Message-ID: <3718FD0D.663FCF0B@cyberus.ca>
I need a function that will go through a list and replace a given
element (let say every times it meets a 0).  If a list is :( (0 (1 (0)(
2 4) (3 2 1 0)))0)
The function should be able to replace the zero by another list in each
occurence of 0 in the first list.
I just know that it must be easy, but i just can't get it right at the
moment.

                    thanx for the help

                        Simon

From: Kent M Pitman
Subject: Re: Some help!
Date: 
Message-ID: <sfw7lrau8h9.fsf@world.std.com>
Simon Pageot <·····@cyberus.ca> writes:

> I need a function that will go through a list and replace a given
> element (let say every times it meets a 0).  If a list is :( (0 (1 (0)(
> 2 4) (3 2 1 0)))0)
> The function should be able to replace the zero by another list in each
> occurence of 0 in the first list.
> I just know that it must be easy, but i just can't get it right at the
> moment.

Thee is only one 0 in the list you've shown.  It contains only two elements:
a list and a number.

The first element of that list contains only two elements: a number and
a list.

And so on.

In Lisp, we refer to something being "in a list" ONLY if it's in the top-level
backbone of the list, not if it's contained within elements of the list.
The reason for this is somewhat philosophical, but basically amounts to
an issue of abstraction--whether or not the things inside the elements
are relevant is an issue of what their purpose is.

Note: If you were to call this item a tree, the answer would be quite 
different.  0 occurs a number of times in the tree which is constructed
of lists and atoms that you've shown.  Each of the lists you've shown
contains no more than 1 pointer to 0, but the tree contains many pointers
to zero.

By the way, when you say you "just can't get it right", what have you
tried?

And also, is this for a class?  We need to know that before we can be more
explicit about the answer.  This smells of a homework assignment, and we're
not big on doing people's homework for them--ESPECIALLY when it's not
identified as homework so that we know to tread lightly.
From: Lyman S. Taylor
Subject: Re: Some help!
Date: 
Message-ID: <37191D3B.238927C5@mindspring.com>
Simon Pageot wrote:
> 
> I need a function that will go through a list and replace a given
> element (let say every times it meets a 0).  If a list is :( (0 (1 (0)(
> 2 4) (3 2 1 0)))0)
> The function should be able to replace the zero by another list in each
> occurence of 0 in the first list.
> I just know that it must be easy, but i just can't get it right at the
> moment.

   Look up the function  SUBST  in your favorite Common Lisp Reference. 

   If this is a homework problem to write SUBST itself you should at least 
   give attribution as to where you got the code from (if present in the
   reference).

   One approach would be to write the "cdr" recursive
   version, SUBSTITUTE,  first and then  augument that code with the "car"
   recursive component.   That will likely not immediately lead to a direct 
   "replacement" for SUBST since:

   USER(4): (subst 'dotted nil '( 1 ( 2  3 ) ( 4 5 )) )
    (1 (2 3 . DOTTED) (4 5 . DOTTED) . DOTTED)

   But will work for the case above. 
 
---
Lyman
From: Thomas A. Russ
Subject: Re: Some help!
Date: 
Message-ID: <ymihfq9n9if.fsf@sevak.isi.edu>
  SUBST   or   NSUBST

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu