]> git.eshelyaron.com Git - emacs.git/commitdiff
Add `drop` as alias for `nthcdr`
authorMattias EngdegÄrd <mattiase@acm.org>
Sun, 28 Apr 2024 16:38:44 +0000 (18:38 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 29 Apr 2024 19:48:06 +0000 (21:48 +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.

(cherry picked from commit 8718a7c7062eb562e2fda0dee5f7bfddb0861f1d)

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 794269b01493c105b97af85abdc57d0f356f4907..4a96d47c1e44b87422321793c3cd504a5e33595e 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2151,6 +2151,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 db09fd680d50de6c77cb527fb9eda73f71c667c4..e5a8123c7e7d042918649e42caffd4e6d93b4a90 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)