unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Declaring primitive function types
@ 2024-02-23  9:55 Andrea Corallo
  2024-03-02 21:45 ` Stefan Monnier via Emacs development discussions.
  0 siblings, 1 reply; 4+ messages in thread
From: Andrea Corallo @ 2024-02-23  9:55 UTC (permalink / raw)
  To: emacs-devel

Hi all,

yesterday night I toyed with some code (scratch/func-type-decls) to move
out the type declaration of primitive functions from
'comp-known-type-specifiers' and move them to where actually functions
are defined.

In order to do that I added an optional argument to the DEFUN macro.

So to get practical 'arrayp' definition goes from:

DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0,
       doc: /* Return t if OBJECT is an array (string or vector).  */)
  (Lisp_Object object)
{
  if (ARRAYP (object))
    return Qt;
  return Qnil;
}

to:

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;
}

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 like the solution of the prototype for its simplicity but maybe people
find the last one is more aesthetic?  Also I've the impression that
'make-docfile' was used so far only for problems that were not solvable
with just the DEFUN expansion.

Opinions?

Thanks!

  Andrea

PS for lisp functions I'm about to open another thread as I think will
be more efficient to be discuss the two separately



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Declaring primitive function types
  2024-02-23  9:55 Declaring primitive function types Andrea Corallo
@ 2024-03-02 21:45 ` Stefan Monnier via Emacs development discussions.
  2024-03-03  8:57   ` Andrea Corallo
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier via Emacs development discussions. @ 2024-03-02 21:45 UTC (permalink / raw)
  To: emacs-devel

> 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




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Declaring primitive function types
  2024-03-02 21:45 ` Stefan Monnier via Emacs development discussions.
@ 2024-03-03  8:57   ` Andrea Corallo
  2024-03-03 14:31     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Andrea Corallo @ 2024-03-03  8:57 UTC (permalink / raw)
  To: Stefan Monnier via Emacs development discussions.; +Cc: Stefan Monnier

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Declaring primitive function types
  2024-03-03  8:57   ` Andrea Corallo
@ 2024-03-03 14:31     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2024-03-03 14:31 UTC (permalink / raw)
  To: Andrea Corallo; +Cc: Stefan Monnier via Emacs development discussions.

>> 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...))))

In both examples above, there should be a comma right after
the doccomment.  Sorry 'bout that.


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-03 14:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-23  9:55 Declaring primitive function types Andrea Corallo
2024-03-02 21:45 ` Stefan Monnier via Emacs development discussions.
2024-03-03  8:57   ` Andrea Corallo
2024-03-03 14:31     ` Stefan Monnier

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).