Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6232
| From | David Bailey <dave@removedbailey.co.uk> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Part // interesting undocumented feature |
| Date | 2011-11-06 11:03 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j95phv$m8d$1@smc.vnet.net> (permalink) |
| References | <j930uu$a9g$1@smc.vnet.net> |
On 05/11/2011 09:51, Scot T. Martin wrote:
> A colleague new to Mathematica showed me something that I thought should cause an error:
>
> Part[data[[All,1]]]
>
> Of course, I thought the form should just be "data[[All,1]".
>
> It turns out that there is form of Part that works like an identity function:
>
> In[1]:= Part[5]
> Out[1]= 5
>
> Just out of a Mathematica trivia challenge question, can anyone think of an example when this undocumented syntax of Part[ ] could possibly be of use or why the programmers have it as an acceptable syntax?
>
>
>
I was not aware of this, but it makes sense.
It is the limiting case of the construction Part[expr,i,j,k....] - the
case where no part specifiers are supplied.
Usually this sort of feature is included to avoid having to perform
special tests for end conditions. For example:
In[673]:= pp={1,2};
expr={{a,b},{c,d}};
Part[expr,Sequence@@pp]
Out[675]= b
In[677]:= pp={1};
In[678]:= Part[expr,Sequence@@pp]
Out[678]= {a, b}
In[680]:= pp={};
In[681]:= Part[expr,Sequence@@pp]
Out[681]= {{a, b}, {c, d}}
Thus the case pp={} does not need to be handled as a special case.
David Bailey
http://www.dbaileyconsultancy.co.uk
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Part // interesting undocumented feature "Scot T. Martin" <smartin@seas.harvard.edu> - 2011-11-05 09:51 +0000 Re: Part // interesting undocumented feature David Bailey <dave@removedbailey.co.uk> - 2011-11-06 11:03 +0000
csiph-web