       Re: Redudant code for style purposes?

• To: mathgroup at smc.vnet.net
• Subject: [mg132579] Re: Redudant code for style purposes?
• From: Bob Hanlon <hanlonr357 at gmail.com>
• Date: Mon, 14 Apr 2014 05:26:10 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-outx@smc.vnet.net
• Delivered-to: mathgroup-newsendx@smc.vnet.net
• References: <20140413092737.B651E6A38@smc.vnet.net>

```There are often multiple ways to do something with Mathematica. Which is
"better" could be based on code length, execution speed, clarity, first one
arrived at that works (task speed), individual style, individual knowledge
of Mathematica, etc. These can be influenced by the version of Mathematica
being used.

array = RandomReal[{0, 10}, 20];

Table[List @@ array[[i ;; i + 1]], {i, 1, 16}] ==
Table[List @@ array[[{i, i + 1}]], {i, 16}] ==
Table[List @@ array[[i ;; i + 1]], {i, 16}] ==
Table[array[[{i, i + 1}]], {i, 16}] ==
Table[array[[i ;; i + 1]], {i, 16}] ==
Partition[array, 2, 1][[1 ;; 16]] ==
Take[Partition[array, 2, 1], 16] ==
Partition[Take[array, 17], 2, 1]

True

Bob Hanlon

On Sun, Apr 13, 2014 at 5:27 AM, <andymhancock at gmail.com> wrote:

> The Mathematica Cookbook has an example:
>
>    array = RandomReal[{0, 10}, 20]
>    Table[List @@ array[[i ;; i + 1]], {i, 1, 16}]
>
> I'm new to Mathematica, but to me, the "List @@" seems redundant.  The
> statements give the same results if I remove it.  Is there a reason
> for this, either functionally or for clarity?
>
>

```

• Prev by Date: Re: Redudant code for style purposes?
• Next by Date: Re: Bug with ProbabilityDistribution
• Previous by thread: Re: Redudant code for style purposes?
• Next by thread: Re: Redudant code for style purposes?