diff options
| author | Stefan Kangas | 2021-10-05 15:36:31 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2021-10-05 15:38:38 +0200 |
| commit | d652efcd087099c71cd76c4bbf2bbf04314844b4 (patch) | |
| tree | 828ea43e01d213d00ec2832d7c877d246f9328e6 | |
| parent | 4bf532ee82473740cfd43c66ecbfe6cfddf99df9 (diff) | |
| download | emacs-d652efcd087099c71cd76c4bbf2bbf04314844b4.tar.gz emacs-d652efcd087099c71cd76c4bbf2bbf04314844b4.zip | |
Make 'mapconcat' argument 'separator' optional
* src/fns.c (Fmapconcat): Make third 'separator' argument
optional. (Bug#50965)
* doc/lispref/functions.texi (Mapping Functions): Update
documentation for above change.
* test/src/fns-tests.el (fns-tests-mapconcat): New test.
* doc/misc/cl.texi (Obsolete Setf Customization): Don't use third
mapconcat argument in example.
* lisp/emacs-lisp/subr-x.el (string-join): Doc fix.
| -rw-r--r-- | doc/lispref/functions.texi | 9 | ||||
| -rw-r--r-- | doc/misc/cl.texi | 2 | ||||
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/emacs-lisp/subr-x.el | 4 | ||||
| -rw-r--r-- | src/fns.c | 8 | ||||
| -rw-r--r-- | test/src/fns-tests.el | 17 |
6 files changed, 35 insertions, 9 deletions
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index c856557c3cb..3163300184a 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi | |||
| @@ -961,14 +961,14 @@ side-effects only---the values it returns are ignored, not collected | |||
| 961 | into a list. @code{mapc} always returns @var{sequence}. | 961 | into a list. @code{mapc} always returns @var{sequence}. |
| 962 | @end defun | 962 | @end defun |
| 963 | 963 | ||
| 964 | @defun mapconcat function sequence separator | 964 | @defun mapconcat function sequence &optional separator |
| 965 | @code{mapconcat} applies @var{function} to each element of | 965 | @code{mapconcat} applies @var{function} to each element of |
| 966 | @var{sequence}; the results, which must be sequences of characters | 966 | @var{sequence}; the results, which must be sequences of characters |
| 967 | (strings, vectors, or lists), are concatenated into a single string | 967 | (strings, vectors, or lists), are concatenated into a single string |
| 968 | return value. Between each pair of result sequences, @code{mapconcat} | 968 | return value. Between each pair of result sequences, @code{mapconcat} |
| 969 | inserts the characters from @var{separator}, which also must be a | 969 | inserts the characters from @var{separator}, which also must be a |
| 970 | string, or a vector or list of characters. @xref{Sequences Arrays | 970 | string, or a vector or list of characters; a @code{nil} value is |
| 971 | Vectors}. | 971 | treated as the empty string. @xref{Sequences Arrays Vectors}. |
| 972 | 972 | ||
| 973 | The argument @var{function} must be a function that can take one | 973 | The argument @var{function} must be a function that can take one |
| 974 | argument and returns a sequence of characters: a string, a vector, or | 974 | argument and returns a sequence of characters: a string, a vector, or |
| @@ -986,8 +986,7 @@ string. | |||
| 986 | 986 | ||
| 987 | @group | 987 | @group |
| 988 | (mapconcat (lambda (x) (format "%c" (1+ x))) | 988 | (mapconcat (lambda (x) (format "%c" (1+ x))) |
| 989 | "HAL-8000" | 989 | "HAL-8000") |
| 990 | "") | ||
| 991 | @result{} "IBM.9111" | 990 | @result{} "IBM.9111" |
| 992 | @end group | 991 | @end group |
| 993 | @end example | 992 | @end example |
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index 1e5d40b0377..04e2c71a2b9 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi | |||
| @@ -5030,7 +5030,7 @@ The above @code{incf} example could be written using | |||
| 5030 | @ignore | 5030 | @ignore |
| 5031 | (defmacro concatf (place &rest args) | 5031 | (defmacro concatf (place &rest args) |
| 5032 | (gv-letplace (getter setter) place | 5032 | (gv-letplace (getter setter) place |
| 5033 | (macroexp-let2 nil v (mapconcat 'identity args "") | 5033 | (macroexp-let2 nil v (mapconcat 'identity args) |
| 5034 | (funcall setter `(concat ,getter ,v))))) | 5034 | (funcall setter `(concat ,getter ,v))))) |
| 5035 | @end ignore | 5035 | @end ignore |
| 5036 | @end defmac | 5036 | @end defmac |
| @@ -118,6 +118,10 @@ with recent versions of Firefox. | |||
| 118 | 118 | ||
| 119 | * Lisp Changes in Emacs 29.1 | 119 | * Lisp Changes in Emacs 29.1 |
| 120 | 120 | ||
| 121 | +++ | ||
| 122 | ** Third 'mapconcat' argument 'separator' is now optional. | ||
| 123 | An explicit nil always meant the empty string, now it can be left out. | ||
| 124 | |||
| 121 | --- | 125 | --- |
| 122 | ** Themes can now be made obsolete. | 126 | ** Themes can now be made obsolete. |
| 123 | Using 'make-obsolete' on a theme is now supported. This will make | 127 | Using 'make-obsolete' on a theme is now supported. This will make |
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index ecd3ca831e8..8d6bb19fd49 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el | |||
| @@ -208,7 +208,9 @@ The variable list SPEC is the same as in `if-let'." | |||
| 208 | (string= string "")) | 208 | (string= string "")) |
| 209 | 209 | ||
| 210 | (defsubst string-join (strings &optional separator) | 210 | (defsubst string-join (strings &optional separator) |
| 211 | "Join all STRINGS using SEPARATOR." | 211 | "Join all STRINGS using SEPARATOR. |
| 212 | Optional argument SEPARATOR must be a string, a vector, or a list of | ||
| 213 | characters; nil stands for the empty string." | ||
| 212 | (mapconcat #'identity strings separator)) | 214 | (mapconcat #'identity strings separator)) |
| 213 | 215 | ||
| 214 | (define-obsolete-function-alias 'string-reverse 'reverse "25.1") | 216 | (define-obsolete-function-alias 'string-reverse 'reverse "25.1") |
| @@ -2852,12 +2852,16 @@ mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq) | |||
| 2852 | return leni; | 2852 | return leni; |
| 2853 | } | 2853 | } |
| 2854 | 2854 | ||
| 2855 | DEFUN ("mapconcat", Fmapconcat, Smapconcat, 3, 3, 0, | 2855 | DEFUN ("mapconcat", Fmapconcat, Smapconcat, 2, 3, 0, |
| 2856 | doc: /* Apply FUNCTION to each element of SEQUENCE, and concat the results as strings. | 2856 | doc: /* Apply FUNCTION to each element of SEQUENCE, and concat the results as strings. |
| 2857 | In between each pair of results, stick in SEPARATOR. Thus, " " as | 2857 | In between each pair of results, stick in SEPARATOR. Thus, " " as |
| 2858 | SEPARATOR results in spaces between the values returned by FUNCTION. | 2858 | SEPARATOR results in spaces between the values returned by FUNCTION. |
| 2859 | |||
| 2859 | SEQUENCE may be a list, a vector, a bool-vector, or a string. | 2860 | SEQUENCE may be a list, a vector, a bool-vector, or a string. |
| 2860 | SEPARATOR must be a string, a vector, or a list of characters. | 2861 | |
| 2862 | Optional argument SEPARATOR must be a string, a vector, or a list of | ||
| 2863 | characters; nil stands for the empty string. | ||
| 2864 | |||
| 2861 | FUNCTION must be a function of one argument, and must return a value | 2865 | FUNCTION must be a function of one argument, and must return a value |
| 2862 | that is a sequence of characters: either a string, or a vector or | 2866 | that is a sequence of characters: either a string, or a vector or |
| 2863 | list of numbers that are valid character codepoints. */) | 2867 | list of numbers that are valid character codepoints. */) |
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 57594572094..2d641cc3111 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el | |||
| @@ -430,6 +430,23 @@ | |||
| 430 | (buffer-hash)) | 430 | (buffer-hash)) |
| 431 | (sha1 "foo")))) | 431 | (sha1 "foo")))) |
| 432 | 432 | ||
| 433 | (ert-deftest fns-tests-mapconcat () | ||
| 434 | (should (string= (mapconcat #'identity '()) "")) | ||
| 435 | (should (string= (mapconcat #'identity '("a" "b")) "ab")) | ||
| 436 | (should (string= (mapconcat #'identity '() "_") "")) | ||
| 437 | (should (string= (mapconcat #'identity '("A") "_") "A")) | ||
| 438 | (should (string= (mapconcat #'identity '("A" "B") "_") "A_B")) | ||
| 439 | (should (string= (mapconcat #'identity '("A" "B" "C") "_") "A_B_C")) | ||
| 440 | ;; non-ASCII strings | ||
| 441 | (should (string= (mapconcat #'identity '("Ä" "ø" "☭" "தமிழ்") "_漢字_") | ||
| 442 | "Ä_漢字_ø_漢字_☭_漢字_தமிழ்")) | ||
| 443 | ;; vector | ||
| 444 | (should (string= (mapconcat #'identity ["a" "b"] "") "ab")) | ||
| 445 | ;; bool-vector | ||
| 446 | (should (string= (mapconcat #'identity [nil nil] "") "")) | ||
| 447 | (should-error (mapconcat #'identity [nil nil t]) | ||
| 448 | :type 'wrong-type-argument)) | ||
| 449 | |||
| 433 | (ert-deftest fns-tests-mapcan () | 450 | (ert-deftest fns-tests-mapcan () |
| 434 | (should-error (mapcan)) | 451 | (should-error (mapcan)) |
| 435 | (should-error (mapcan #'identity)) | 452 | (should-error (mapcan #'identity)) |