[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Declaring primitive function types
From: |
Andrea Corallo |
Subject: |
Re: Declaring primitive function types |
Date: |
Sun, 03 Mar 2024 03:57:55 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Stefan Monnier via "Emacs development discussions."
<emacs-devel@gnu.org> writes:
>> 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.
That's correct, I wanted to minimize the diff of the patch.
> 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...))))
Okay thanks, I'll try to come-up with something that does not add a new
argument to the macro.
Andrea