Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1993
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1993

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

Search the Archive

Re: Flat Strings

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Re: Flat Strings
  • From: Roberto Sierra <73557.2101 at compuserve.com>
  • 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....


P.S.
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 compuserve.com



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