all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Andrea Corallo <acorallo@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: feature/type-hierarchy 8a63e50036f 1/5: * Define 'cl--type-hierarchy' and compute 'cl--typeof-types' from it
Date: Fri, 01 Mar 2024 11:49:38 -0500	[thread overview]
Message-ID: <jwvil25ly30.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20240215170330.82819C0F009@vcs2.savannah.gnu.org> (Andrea Corallo via Mailing list for Emacs changes's message of "Thu, 15 Feb 2024 12:03:30 -0500 (EST)")

> -(defconst cl--typeof-types
> -  ;; Hand made from the source code of `type-of'.
> -  '((integer number integer-or-marker number-or-marker atom)
> -    (symbol-with-pos symbol atom) (symbol atom) (string array sequence atom)
[...]
> +(defconst cl--type-hierarchy
[...]
> +    (symbol keyword boolean symbol-with-pos)
[...]
> +    (symbol-with-pos keyword))

How did you come up with `cl--type-hierarchy`?
Because, obviously, something changed here.
How is `keyword` a "direct subtype" of `symbol-with-pos`?

> +(defconst cl--direct-supertypes-of-type
> +  (make-hash-table :test #'eq)
> +  "Hash table TYPE -> SUPERTYPES.")
> +
> +(defconst cl--direct-subtypes-of-type
> +  (make-hash-table :test #'eq)
> +  "Hash table TYPE -> SUBTYPES.")
> +
> +(cl-loop for (parent . children) in cl--type-hierarchy
> +         do (cl-loop
> +             for child in children
> +             do (cl-pushnew parent (gethash child cl--direct-supertypes-of-type))
> +             do (cl-pushnew child (gethash parent cl--direct-subtypes-of-type))))

FWIW, I think we should create a "type descriptor" defstruct (from which
`cl--class` would inherit), and generalize the `cl--class` symbol
property to one that holds the type descriptor of the given name.

So you could get the direct parents of `integer` with something like:

    (slot-value (get 'integer 'cl--class) 'parents)

[ And then `C-h o integer RET` should show the corresponding info.  ]

> +(defconst cl--typeof-types nil

This can't make sense.
If you change it later with `push/setq` it should not be a "defconst".
So either arrange to compute its default value directly inside the
`defconst`, or use a `defvar`.

> +(maphash (lambda (type _)
> +           (push (cl--supertypes-for-typeof-types type) cl--typeof-types))
> +         cl--direct-supertypes-of-type)

Did you compare the resulting alist to the one we had before?
Remember that the order of "(direct or not) supertypes" in there is
important.
The current table has errors.  I see for example:

    (fixnum integer integer-or-marker number atom number-or-marker)

where `atom` should come *after* `number-or-marker`.


        Stefan




       reply	other threads:[~2024-03-01 16:49 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <170801660982.26727.13226947668211497607@vcs2.savannah.gnu.org>
     [not found] ` <20240215170330.82819C0F009@vcs2.savannah.gnu.org>
2024-03-01 16:49   ` Stefan Monnier [this message]
2024-03-01 18:12     ` feature/type-hierarchy 8a63e50036f 1/5: * Define 'cl--type-hierarchy' and compute 'cl--typeof-types' from it Andrea Corallo
2024-03-01 18:59       ` Stefan Monnier
2024-03-03  8:51         ` Andrea Corallo
2024-03-03 14:21           ` Stefan Monnier
2024-03-03 18:34             ` Andrea Corallo
2024-03-03 20:41               ` Stefan Monnier
2024-03-04  9:16                 ` Andrea Corallo
2024-03-04 15:37                   ` Stefan Monnier
2024-03-04 16:12                     ` Andrea Corallo
2024-03-04 16:35                       ` Stefan Monnier
2024-03-03 16:56     ` Andrea Corallo
2024-03-03 17:31       ` Stefan Monnier
2024-03-03 18:05         ` Andrea Corallo
2024-03-03 18:20           ` Stefan Monnier
2024-03-03 18:37             ` Andrea Corallo
2024-03-03 20:42               ` Stefan Monnier
2024-03-04  9:24                 ` Andrea Corallo
2024-03-04 15:51                   ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvil25ly30.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=acorallo@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.