Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10732
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: case of inconsistent API between Drop and Part? |
| Date | 2012-07-02 09:23 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jsrpav$cvq$1@smc.vnet.net> (permalink) |
| References | <201206300917.FAA01642@smc.vnet.net> |
To drop elements 2 and 4 in one command:
lis = {a, b, c, d, e};
Drop[lis, {2, 4, 2}]
{a, c, e}
Bob Hanlon
On Sat, Jun 30, 2012 at 5:17 AM, Nasser M. Abbasi <nma@12000.org> wrote:
> One thing I always liked about Mathematica's functions is
> that the API's of its functions all seem to be consistent
> (for the most part).
>
> Here is a case where it is not consistent though to share it.
>
> (I am trying to make a list of all such cases in my cheat sheet)
>
> It is between Drop and Part.
>
> Drop[list,{m,n}] gives list with elements m THROUGH n dropped.
> Drop[list,m;;n] gives list with elements m THROUGH n dropped.
>
> but
>
> Part[list,{m,n}] gives the list of elements m AND n
> Part[list,m;;n] gives the list of elements m THROUGH n
>
> Example using Drop:
> -----------------
> Clear[a,b,c,d,e];
> lis={a,b,c,d,e};
> Drop[lis,2;;4]
>
> Out[161]= {a,e}
>
> Drop[lis,{2,4}]
>
> Out[162]= {a,e}
> ----------------------
>
> Example using Part:
> ------------------
> Part[lis,2;;4]
>
> Out[163]= {b,c,d}
>
> Part[lis,{2,4}]
>
> Out[164]= {b,d}
> --------------------
>
> What the above also mean, is that using the Drop function,
> there is no direct way to tell it to Drop element 2 AND
> element 4 in one command. (there are easy ways to do this,
> but not using one function call of Drop as is). (one easy
> solution is to complement the elements to drop, and use Part
> instead, and other ways)
>
> I do not know if the experts here agree that this is an
> inconsistency in the API between Drop and Part, but for me,
> (and I am no expert) it seems so.
>
> http://reference.wolfram.com/mathematica/ref/Part.html
> http://reference.wolfram.com/mathematica/ref/Drop.html
> --Nasser
>
--
Bob Hanlon
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: case of inconsistent API between Drop and Part? Bob Hanlon <hanlonr357@gmail.com> - 2012-07-02 09:23 +0000
csiph-web