       case of inconsistent API between Drop and Part?

• To: mathgroup at smc.vnet.net
• Subject: [mg127100] case of inconsistent API between Drop and Part?
• From: "Nasser M. Abbasi" <nma at 12000.org>
• Date: Sat, 30 Jun 2012 05:17:37 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com

```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= {a,e}

Drop[lis,{2,4}]

Out= {a,e}
----------------------

Example using Part:
------------------
Part[lis,2;;4]

Out= {b,c,d}

Part[lis,{2,4}]

Out= {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

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

```

• Prev by Date: Re: Book
• Next by Date: Re: Higher precision in Error function Erf[] needed.
• Previous by thread: how to make a list of rules with 2 other lists composed by different kinds of elements