Subject: Re: bug#76413: [PATCH] New macro 'compf' for composing functions

From: "Basil L. Contovounesios" <[email-masked]>
Date: Wed, 19 Feb 2025 18:13:03 +0100

Eshel Yaron [2025-02-19 16:10 +0100] wrote:

> From e2834b162f3f1fa1c8dc8e057e3aa00950269d8e Mon Sep 17 00:00:00 2001
> From: Eshel Yaron <[email-masked]>
> Date: Wed, 19 Feb 2025 12:58:40 +0100
> Subject: [PATCH v2] New macro 'compf' for composing functions

Nice.

> +FUNS may contain symbols which refer to functions, such as `car' and
> +`cdr' in the example above, and it can also contain `lambda' functions
> +and other forms which evaluate to function values.

A (declare (debug ...)) property would be nice, particularly for
stepping through the latter types of argument.

>  To refer to a local
> +variable VAR that is bound to a function, wrap VAR in a vector, as in:
> +
> +  (let ((foo (lambda (...) ...)))
> +    (compf ignore [foo] always))

Is there precedent for this [syntax] somewhere?

I understand that function symbols may be needed more frequently than
variable symbols in arguments to compf, but did you consider
distinguishing between the two kinds of symbol by #'-quoting function
symbols, and leaving variables unquoted?
AFAIK this has more precedents in Elisp.

> +    (let* ((x (gensym "x")) (arg x))
> +      (dolist (fun (reverse funs))
> +        (setq arg
> +              (cond
> +               ((symbolp fun) `(,fun ,arg))
> +               ((vectorp fun) `(funcall ,(aref fun 0) ,arg))
> +               (t `(funcall ,fun ,arg)))))
> +      `(lambda (,x) ,arg)))))

I wonder if we could/should be smart™ about the func-arity of the
rightmost function and adapt the wrapper lambda's arglist accordingly.

Finally, would you like to write an announcement and some tests as well?

Thanks,
-- 
Basil