Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Question about function
Replies: 1   Last Post: Jan 19, 2012 5:06 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
oleksandr_rasputinov@hmamail.com

Posts: 193
Registered: 6/20/11
Re: Question about function
Posted: Jan 19, 2012 5:06 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.