MathGroup Archive 2009

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

Search the Archive

Re: StringJoin with ToString

  • To: mathgroup at
  • Subject: [mg98314] Re: StringJoin with ToString
  • From: ADL <alberto.dilullo at>
  • Date: Sun, 5 Apr 2009 06:40:44 -0400 (EDT)
  • References: <gr6cbs$pva$>

With the following definitions, your idea appears to work (at least in
a few examples I tested):

toString[x_?NumericQ, format___] := ToString[x, format];
toString[x_[y__], format___] := x @@ (toString /@ {y});
toString[x_Symbol, format___] := ToString[x, format];
toString[x_, format___] := x;

$UseNewStringJoin = True;
System`StringJoin[expr___] :=
  Block[{$UseNewStringJoin = False},
    StringJoin @@ (toString /@ {expr})] /; TrueQ[$UseNewStringJoin];

The problem was the way ToString works, which is incompatible with
intermediate formatting functions. The definition of "toString" does
the job.

In[12]:= StringJoin[{1, 2, 3}] // InputForm


In[13]:= StringJoin[1, a, 3] // InputForm


In[17]:= StringJoin[1, "2", \[Pi]] // InputForm


In[15]:= Append[dummy, 2]

During evaluation of In[15]:= Append::normal: Nonatomic expression
expected at position 1 in Append[dummy,2]. >>

Out[15]= Append[dummy,2]


On 4 Apr, 03:15, replicator... at wrote:
> It is quite interesting why StringJoin does not apply ToString to
> those arguments which are non-string. I've overridden the built-in
> StringJoin, to save a few unnecessary ToStrings by the standard method
> (the context specifications are necessary for packaging):
> Thanks
> Istvan Zachar

  • Prev by Date: Re: Styling the selected Tab's label in TabView
  • Next by Date: Re: passing an array variable as a file name string to FindList
  • Previous by thread: Re: StringJoin with ToString
  • Next by thread: StringJoin with ToString