Add `drop` as alias for `nthcdr`
authorMattias Engdegård <mattiase@acm.org>
Sun, 28 Apr 2024 16:38:44 +0000 (18:38 +0200)
committerMattias Engdegård <mattiase@acm.org>
Mon, 29 Apr 2024 12:29:52 +0000 (14:29 +0200)
It's a common name for this function and symmetric with respect to
`take`.  It's also a lot less awkward to type and say.

* lisp/subr.el (drop): New alias.
* doc/lispref/lists.texi (List Elements): Document.  Mention the
equation tying `take` and `drop` together.
* etc/NEWS: Announce.

doc/lispref/lists.texi
etc/NEWS
lisp/subr.el

index ca42942250c925a27eadbea19eeae3fc5d917652..dce9115c61bf174f03fbb59775a58b3869730b65 100644 (file)
@@ -317,6 +317,7 @@ For historical reasons, it takes its arguments in the opposite order.
 @xref{Sequence Functions}.
 @end defun
 
+@findex drop
 @defun nthcdr n list
 This function returns the @var{n}th @sc{cdr} of @var{list}.  In other
 words, it skips past the first @var{n} links of @var{list} and returns
@@ -327,6 +328,8 @@ If @var{n} is zero, @code{nthcdr} returns all of
 @var{list}.  If the length of @var{list} is @var{n} or less,
 @code{nthcdr} returns @code{nil}.
 
+An alias for @code{nthcdr} is @code{drop}.
+
 @example
 @group
 (nthcdr 1 '(1 2 3 4))
@@ -350,6 +353,9 @@ it returns the part of @var{list} that @code{nthcdr} skips.
 @code{take} returns @var{list} if shorter than @var{n} elements;
 it returns @code{nil} if @var{n} is zero or negative.
 
+In general, @code{(append (take @var{n} @var{list}) (drop @var{n} @var{list}))}
+will return a list equal to @var{list}.
+
 @example
 @group
 (take 3 '(a b c d))
index eceecc107fc947cae01bb3d32fa33ca380dd1585..3908c49225321341645982239312858066901d7b 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2013,6 +2013,9 @@ precedence over the variable when present.
 Mostly used internally to do a kind of topological sort of
 inheritance hierarchies.
 
++++
+** 'drop' is now an alias for the function 'nthcdr'.
+
 +++
 ** New polymorphic comparison function 'value<'.
 This function returns non-nil if the first argument is less than the
index fba7034215452cf80965c4ab2a10e2f36bbb74fc..352ecc315ef52fff6ce490a05d2ba87bcb79b74b 100644 (file)
@@ -2036,6 +2036,7 @@ instead; it will indirectly limit the specpdl stack size as well.")
 \f
 ;;;; Alternate names for functions - these are not being phased out.
 
+(defalias 'drop #'nthcdr)
 (defalias 'send-string #'process-send-string)
 (defalias 'send-region #'process-send-region)
 (defalias 'string= #'string-equal)