Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7975 > unrolled thread
| Started by | oversky <mailcwc@gmail.com> |
|---|---|
| First post | 2012-01-18 11:05 +0000 |
| Last post | 2012-01-19 10:06 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Question about function oversky <mailcwc@gmail.com> - 2012-01-18 11:05 +0000
Re: Question about function "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2012-01-19 10:06 +0000
| From | oversky <mailcwc@gmail.com> |
|---|---|
| Date | 2012-01-18 11:05 +0000 |
| Subject | Question about function |
| Message-ID | <jf6917$gbm$1@smc.vnet.net> |
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[]?
[toc] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2012-01-19 10:06 +0000 |
| Message-ID | <jf8pvs$3ea$1@smc.vnet.net> |
| In reply to | #7975 |
On Wed, 18 Jan 2012 11:05:11 -0000, oversky <mailcwc@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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web