       RE: Pipes Inside Mathematica?

• To: mathgroup at smc.vnet.net
• Subject: [mg45669] RE: [mg45659] Pipes Inside Mathematica?
• From: "David Park" <djmp at earthlink.net>
• Date: Sat, 17 Jan 2004 02:34:39 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Harold,

There was a question similar to this just a few days ago.

{{5*Pi}, {13*E}} // IntegerPart //
Table[0, Extract[#, 1] // Evaluate, Extract[#, 2] // Evaluate] &

If you want to use a function that requires more than one argument after //,
then use a pure function. The only extra problem in this case is that Table
has the Attribute HoldAll so we also have to Evaluate the iterators.

David Park

From: Harold Noffke [mailto:Harold.Noffke at wpafb.af.mil]
To: mathgroup at smc.vnet.net

MathGroup:

I think Mathematica would be a better programming language if it had a
construct that allowed pipes (like Unix does).  The //-mark comes
close to facilitating this, but Mathematica needs a placeholder to
denote "result from preceding //-mark".

Here's a short example to illustrate what would be gained.

In:= m = 5*Pi // IntegerPart

Out= 15

In:= n = 13*E // IntegerPart

Out= 35

In:= Table[0, {m}, {n}] // MatrixForm

Out//MatrixForm=

0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0

>   >       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
:   :
:	:
:	:

0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0

>       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0

What we would really like to write is the preceding computation as a
pipeline, so that it looks something like this ...

{{5*Pi},{13*E}} // IntegerPart // Table[0, Extract[<?>,1],
Extract[<?>,2]] // MatrixForm

The <?> symbol means, "I don't know what to put here" -- it's a
placeholder for whatever Mathematica wants to use as "result from
preceding //-mark".  Maybe @ would make a good placeholder here, and
what we would see on screen is ...

{{5*Pi},{13*E}} // IntegerPart // Table[0, Extract[@,1], Extract[@,2]]
// MatrixForm

I think Mathematica will be a better programming language if it adopts
some sort of pipe convention.

Harold

```

• Prev by Date: Re: using functions with package name prefixed.
• Next by Date: Re: Re: hyperlink to pdf files
• Previous by thread: Pipes Inside Mathematica?
• Next by thread: Re: Pipes Inside Mathematica?