[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Add cl-map-into, revision 3
From: |
Stefan Monnier |
Subject: |
Re: [PATCH] Add cl-map-into, revision 3 |
Date: |
Wed, 13 Oct 2021 18:32:05 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> +(cl-defmacro cl--do-seq-type-signature ((type-var signature &optional result)
> + &body body)
I'm not fond of this internal macro used at only one place.
I'd rather we write the resulting code at its caller's location.
> + `(let ((,sig ,signature) ,type-var)
> + ;; (declare (type (integer (1)) ,sig)
> + ;; ;; Let's keep nil for now.
> + ;; (type (member nil list vector) ,type-var))
> + (cl-check-type ,sig (integer (1)))
> + (cl-loop (cond
> + ((or (when (= 2 ,sig) (setq ,type-var 'list))
> + (when (= 3 ,sig) (setq ,type-var 'array)))
> + ;; This duplicates main code sometimes. Maybe,
> + ;; there is elegant enough way to eliminate duplication.
> + ,@(or first main) (cl-return ,result))
> + (t (setq ,type-var (if (zerop (mod ,sig 2))
> + 'list
> + 'array))
> + ,@main))
> + (setf ,sig (floor ,sig 2)))))))
(let (,type-var)
...
(setq ,type-var ...)
...)
generates worse code than
...
(let ((,type-var ...))
...)
> + (funcall
> + (if do-not-compile #'identity #'byte-compile)
> + `(lambda ,(cons (setq f (make-symbol "f")) (cons result-var ss))
I think you meant `#'eval` (or better: (lambda (x) (eval x t))) instead
of `#'identity`.
Also you'll want to bind `lexical-binding` around the call to `byte-compile`.
> + (apply
> + (let* ((sig (apply #'cl--compute-map-into-signature result-sequence
> + sequences))
> + (small (< sig cl--map-into-max-small-signature)))
> + (with-memoization (if small (aref cl--map-into-mappers-array sig)
> + ;; TODO: Order alist entries for faster lookup
> + ;; (note that we'll have to abandon alist-get then).
> + (alist-get sig cl--map-into-mappers-alist
> + nil nil #'=))
> + (cl--make-map-into-mapper sig)))
> + function result-sequence sequences))
[ Makes me wonder if we could define this as a cl-generic function, and
use something like method combinators to generate the code on the fly.
More specifically, if we can't with the current code, it seems like
a fun exercise to see what it would take to make it possible. ]
Stefan