MathGroup Archive 2014

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Redudant code for style purposes?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg132581] Re: Redudant code for style purposes?
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Mon, 14 Apr 2014 05:26:50 -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

On 4/13/14 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?

List@@expr is short for Apply[List,expr] which replaces the head
of expr with List. Since,

In[3]:= Table[Head@array[[i ;; i + 1]], {i, 1, 3}]

Out[3]= {List,List,List}

the syntax is redundant. Also, if I wanted to transform the
original array as is being done, I would use

Partition[array[[;;17]],2,1]

that is

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

Out[4]= True




  • Prev by Date: Re: Bug with ProbabilityDistribution
  • Next by Date: Re: List vs. array in Mathematica
  • Previous by thread: Re: Redudant code for style purposes?
  • Next by thread: Re: Redudant code for style purposes?