[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: substitution in a list

From: Ian Grant
Subject: Re: substitution in a list
Date: Tue, 23 Jan 2007 14:37:49 +0000

On Tue, 23 Jan 2007 12:44:33 +0100
Luca Saiu <address@hidden> wrote:

> orianaparo wrote:
> > Hi. I'm a newbie and I'm trying to write some programs in Guile.
> > I'd like to know how I can perform a substitution in a list.
> > I mean:I want to write a function that takes two arguments: a list
> > (possibly nested) of symbols
>  > [e.g ((a (b c) d) a (f b))] and another list that indicate what
>  > sort 
> of substitution the function
>  > should perform [e.g. ((a z) (b y))].
> Ok. I think you should start trying to break this into more manageable
> subproblems: think you have a function substitute-single which takes
> your possibly nested list, a symbol s to be replaced and its 
> replacement, and returns a new list with all occurrences of s
> substituted.

It would be a good idea to do it this way if the list of substitutions
were much longer than the list where they are being made. But if the
substitution list is short then looking up a symbol is relatively cheap
compared to consing up the transformed list and reversing it, so it
be better to test each symbol once.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]