Re: Question about function
- To: mathgroup at smc.vnet.net
- Subject: [mg124409] Re: Question about function
- From: "Oleksandr Rasputinov" <oleksandr_rasputinov at hmamail.com>
- Date: Thu, 19 Jan 2012 05:06:06 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jf6917$gbm$1@smc.vnet.net>
On Wed, 18 Jan 2012 11:05:11 -0000, oversky <mailcwc at gmail.com> wrote: > I define the following function: > > xPrint[x_]:=(Print[HoldForm[x]," =",Tab,x]); > Attributes[xPrint]={HoldAll,Listable}; > a=5; > xPrint[a] > > -> a = 5 > > I want to modify this code such that it can handle multiple arguments. > For example, > > a=5; > b=6; > xPrint[a,b] > > -> a = 5 > -> b = 6 > > How do I get the argument one by one and feed it into Print[]? > Probably the simplest way is to make use of the Listable attribute that you've already set. Just make one more definition: xPrint[args__] := (xPrint[{args}];); and: In := a = 5; b = 6; xPrint[a, b] Out = a = 5 b = 6