MathGroup Archive 1993

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Flat Strings

  • To: mathgroup at
  • Subject: Re: Flat Strings
  • From: Roberto Sierra <73557.2101 at>
  • Date: 01 Jun 93 21:06:53 EDT

> I took a quick look at your problem and this is a quick and dirty solution
> I bashed out in a minute or so, but it works.
> Here it is.
> FlatString[a_,b__]:=Module[{temp},
>         temp={a,b}/.FlatString->StringJoin;
>         temp[[0]]=StringJoin;
>         FlatString[temp]]

Great idea.  I tried it out and it showed about 10% speed improvement
over my best attempt.  I refined your solution a little bit further
and came up with the following, which is an additional 10-15% faster.
Eliminating the Module block is important, since Module would cause
a large number of internal 'temp$xxxx' symbols to be generated and
slows everything down a little.  [This version also flattens Lists.]

    FlatString[a_,b__] :=
        FlatString[{a,b} /. FlatString->StringJoin /. List->StringJoin];

Thanks for the excellent suggestion....

You might find it easier and cleaner to use 'Apply' than saying

    temp[[0]] = StringJoin,

as in

    Apply[StringJoin,temp]    -or-    StringJoin @@ temp

So far as I know, these will all evaluate to the same result.

 - -
 o o
  J   roberto sierra
  O   tempered microdesigns
 \_/  73557.2101 at

  • Next by Date: citing Mma
  • Next by thread: RE: Flat Strings