Re: MakeExpression on a list
- To: mathgroup at smc.vnet.net
- Subject: [mg132144] Re: MakeExpression on a list
- From: David Bailey <dave at removedbailey.co.uk>
- Date: Thu, 26 Dec 2013 06:24:09 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
- References: <l9bce4$koo$1@smc.vnet.net>
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