Re: Question about function
- To: mathgroup at smc.vnet.net
- Subject: [mg124411] Re: Question about function
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Thu, 19 Jan 2012 05:06:49 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201201181101.GAA16655@smc.vnet.net>
Use SetAttributes to set attributes; and to make use of the attribute
Listable, put the arguments into a list.
ClearAll[xPrint]
SetAttributes[xPrint, {HoldAll, Listable}];
xPrint[x_] := (Print[HoldForm[x], " =", Tab, x]);
a = 5;
b = 6;
xPrint[a];
a = 5
xPrint[{a, b}];
a = 5
b = 6
Bob Hanlon
On Wed, Jan 18, 2012 at 6:01 AM, 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[]?
>
- References:
- Question about function
- From: oversky <mailcwc@gmail.com>
- Question about function