[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Declaring primitive function types
From: |
Stefan Monnier |
Subject: |
Re: Declaring primitive function types |
Date: |
Sat, 02 Mar 2024 16:45:28 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
> DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0,
> doc: /* Return t if OBJECT is an array (string or vector). */,
> (function (t) boolean))
> (Lisp_Object object)
> {
> if (ARRAYP (object))
> return Qt;
> return Qnil;
> }
Everything else being equal (haha!), I'd vote to put the type *before*
the doc. But I guess you did it this way so we don't have to touch
the DEFUNs to which we don't add an annotation.
I think it looks pretty good.
> I guess another option would have been having the type in the doc
> argument (as for attributes) and have something like:
>
> DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0,
> doc: /* Return t if OBJECT is an array (string or vector). */
> type: (function (t) boolean))
> (Lisp_Object object)
> {
> if (ARRAYP (object))
> return Qt;
> return Qnil;
> }
>
> This would complexify a little things as we'd need 'make-docfile' to
> parse it and generate something somewhere that we read afterwards.
I'd much rather not go through `make-docfile`.
You could probably still make it work without `make-docfile`, just by
tweaking `Fsubr_type` so it skips the "type:" before calling Fread.
> I like the solution of the prototype for its simplicity but maybe people
> find the last one is more aesthetic?
Not sure about "aesthetic", but the presence of `type:` does make it more
obvious what this is about. The number of arguments to DEFUN is high
enough that it's toeing the limits of BoA style.
Another option along those lines would be:
DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0,
doc: /* Return t if OBJECT is an array (string or vector). */
((type (function (t) boolean))))
(Lisp_Object object)
which could accommodate extensions like
DEFUN (...
doc: /* ... */
((type (function (t) boolean))
(obsolete "use pcase, of course" "24,1")
(usage (fn ARGS [DOCSTRING] [INTERACTIVE] BODY...))))
- Stefan
- Re: Declaring primitive function types,
Stefan Monnier <=