Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #16365

Re: MakeExpression on a list

From David Bailey <dave@removedbailey.co.uk>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: MakeExpression on a list
Date 2013-12-26 11:18 +0000
Message-ID <l9h39e$39g$1@smc.vnet.net> (permalink)
References <l9bce4$koo$1@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


On 24/12/2013 07:17, Yi Wang wrote:> Dear all,
 >
 > I was trying to use MakeExpression to translate
 >
 > Subscript[f, \[FilledSmallSquare]]
 >
 > into
 >
 > f[x,y,z,t].
 >
 > Currently, I can do it with
 >
 > X={x,y,z,t}
 >
 > MakeExpression[SubscriptBox[f_,"\[FilledSmallSquare]"],form_]
 >      := MakeExpression[RowBox[
 >          {f, 
"[",Sequence@@Riffle[Map[ToBoxes[#,form]&,X],","],"]"}],form]
 >
 > However, I was wondering if there are simpler ways (using Riffle to 
make a sequence of strings seems stupid). Especially, why the following 
doesn't work:
 >
 > MakeExpression[SubscriptBox[f_,"\[FilledSmallSquare]"],form_]
 >      := MakeExpression[f,form][x,y,z,t]
 >
 > Thank you very much in advance!
 >
 > Note:
 >
 > I know I could use the Notation package, or directly write
 >
 > MakeExpression[SubscriptBox[f_,"\[FilledSmallSquare]"],form_]
 >      := MakeExpression[RowBox[{f, "[x,y,z,t]"}],form]
 >
 > However, I would like to be able to change coordinate, say 
X={x,y,z,t} into X={r, theta, phi, t} and use the same code to parse 
input. Thus I don't want to hard code "[x,y,z,t]". Also the Notation 
package doesn't seem to provide such flexibility.
 >
 > Merry Christmas and happy new year!
 > Yi
 >
Because MakeExpression returns an expression wrapped in HoldComplete to 
prevent it evaluating ahead of time.

I guess you could splice the changes into the resultant expression 
(allowing for the HoldComplete wrapper), but it is probably easier to to 
use the standard method. However, check the box expression for 
f[x,y,z,t] - it isn't as you have written it!

I must admit, I also prefer to use MakeBoxes/MakeExpression rather than 
use the notation package.

David Bailey
http://www.dbaileyconsultancy.co.uk

Back to comp.soft-sys.math.mathematica | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

MakeExpression on a list Yi Wang <tririverwangyi@gmail.com> - 2013-12-24 07:17 +0000
  Re: MakeExpression on a list David Bailey <dave@removedbailey.co.uk> - 2013-12-26 11:18 +0000

csiph-web