unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: akater <nuclearspace@gmail.com>
Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re: [PATCH] Add cl-map-into, revision 2
Date: Thu, 07 Oct 2021 10:18:14 +0300	[thread overview]
Message-ID: <83o8811ex5.fsf@gnu.org> (raw)
In-Reply-To: <87wnmprajk.fsf@gmail.com> (message from akater on Wed, 06 Oct 2021 23:35:59 +0000)

> From: akater <nuclearspace@gmail.com>
> Date: Wed, 06 Oct 2021 23:35:59 +0000
> Cc: emacs-devel@gnu.org
> 
> map-into is a standard Common Lisp function that acts as cl-map, only
> values are recorded into a preallocated sequence.
> 
> * lisp/emacs-lisp/cl-extra.el
> (cl-map-into): New primary function
> (cl--map-into-basic-call-arguments-limit,
> cl--map-into-max-small-signature): New auxiliary constant
> (cl--map-into-mappers-array, cl--map-into-mappers-alist): New variable
> (cl--compute-map-into-signature, cl--make-map-into-mapper): New auxiliary function
> (cl--do-seq-type-signature): New auxiliary macro

Thanks.  Please always accompany changes that introduce new features
by corresponding changes to documentation.  The Common Lisp
compatibility library is documented in cl.texi, and the new macro(s)
should be called out in NEWS.

See some additional minor comments below.

> +(cl-defmacro cl--do-seq-type-signature ((type-var signature &optional result)
> +                                        &body body)
> +  "With TYPE-VAR bound to sequence type, evaluate BODY forms.  Return RESULT.

The first line of a doc string should be a single sentence, not longer
than 79 characters.

> +(defun cl--make-map-into-mapper (signature &optional do-not-compile)
> +  "Return mapper for `cl-map-into' specialized on arglists of type
> +encoded by SIGNATURE.

Same here.

> +(defun cl-map-into (target function &rest sequences)
> +  "Common Lisp's map-into.

The first line of a doc string of a public interface should describe
the arguments, at least the mandatory ones.

> +TARGET and each element of SEQUENCES can each be either a list
> +or a vector.

Is there any reasons you excluded other kinds of sequences (strings
and bool-vectors)?

> +(ert-deftest cl-map-into ()
> +  (should (equal '(42 42 42)
> +                 (cl-map-into (list 0 0 0) #'+ '(1 2 3) [41 40 39])))
> +  (should (equal '(42 42 42)
> +                 (cl-map-into (list 0 0 0) #'+ [41 40 39] '(1 2 3))))
> +  (should (equal '(42 42 42)
> +                 (cl-map-into (list 0 0 0) #'* '(1 2 3) [42 21 14])))
> +  (should (equal '(42 42 42)
> +                 (let ((s (list 0 0 0)))
> +                   (cl-map-into s #'+ '(1 2 3) [41 40 39])
> +                   s)))
> +  (should (equal '(42 42 42)
> +                 (let ((s (list 0 0 0)))
> +                   (cl-map-into s #'+ s [41 40 39] '(1 2 3))
> +                   s)))
> +  (should (equal '(42 42 42)
> +                 (let ((s (list 0 0 0)))
> +                   (cl-map-into s #'+ '(1 2 3) s [41 40 39])
> +                   s)))
> +  (should (equal '(42 42 42)
> +                 (let ((s (list 0 0 0)))
> +                   (cl-map-into s #'+ '(1 2 3) [41 40 39] s)
> +                   s)))
> +  (should (equal '(42 42 42)
> +                 (let ((s (list 18 19 20)))
> +                   (cl-map-into s #'+ s '(6 4 2 1 not-even-a-number) s)
> +                   s)))
> +  (should (equal [42 42 42]
> +                 (let ((s (vector 0 0 0)))
> +                   (cl-map-into s #'+ '(1 2 3) [41 40 39])
> +                   s)))
> +  (should (equal [42 42 42]
> +                 (let ((s (vector 0 0 0)))
> +                   (cl-map-into s #'+ [41 40 39] '(1 2 3))
> +                   s)))
> +  (should (equal [42 42 42]
> +                 (let ((s (vector 18 19 20)))
> +                   (cl-map-into s #'+ s '(6 4 2 1 not-even-a-number) s)
> +                   s))))
> +

I don't see here any tests where the lengths of the sequences are
different.  Can you add some of those?

Thanks again for working on this.



  reply	other threads:[~2021-10-07  7:18 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-23 23:35 [PATCH] Add cl-map-into akater
2021-09-27 17:18 ` Stefan Monnier
2021-09-29 19:30   ` akater
2021-09-29 20:26     ` Stefan Monnier
2021-09-30  6:38       ` Bozhidar Batsov
2021-09-30 13:03         ` Adam Porter
2021-09-30 13:09           ` Bozhidar Batsov
2021-09-30 13:21             ` Adam Porter
2021-09-30 15:00               ` akater
2021-10-01 18:40         ` Stefan Monnier
2021-10-01 18:51           ` Eli Zaretskii
2021-10-01 19:04             ` Tassilo Horn
2021-10-01 20:52               ` Stefan Monnier
2021-10-01 22:08                 ` Glenn Morris
2021-10-02  3:53                   ` Stefan Monnier
2021-10-06 23:35   ` [PATCH] Add cl-map-into, revision 2 akater
2021-10-07  7:18     ` Eli Zaretskii [this message]
2021-10-07  8:24       ` akater
2021-10-07  9:00         ` Eli Zaretskii
2021-10-09  2:46       ` [PATCH] Add cl-map-into, revision 3 akater
2021-10-13 22:32         ` Stefan Monnier
2021-10-26 12:52           ` akater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83o8811ex5.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=nuclearspace@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).