bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#77725: 31.0.50; Add support for types accepted by `cl-typep' to cl-g


From: David Ponce
Subject: bug#77725: 31.0.50; Add support for types accepted by `cl-typep' to cl-generic?
Date: Fri, 18 Apr 2025 17:02:58 +0200
User-agent: Mozilla Thunderbird

Hi Stefan,

(merge-ordered-lists '((test test)))
=> (test test)

Ah, right, `merge-ordered-lists` presumes the arg lists are already sane.


So, I kept the test to ensure `name' is not in `parents'.

The converse is that if we have already decided that the value is *not*
for type BAR, then it can't be of type FOO either, so there's no point
testing FOO.
Wouldn't this involve calculating the parents of all the types traversed,
instead of just the matching ones?

I wasn't describing an algorithm, just a principle that can be used
within an algorithm.  Depending on the algorithm you use it can be used
in different ways.  With your current loop, I don't think you can make
much use of it.

But I think what we could do fairly easily is the following:

- based on the PARENTS declaration, create a map from builtin-type to
   the set of cl-types that have that builtin-type among their parents.
   That presumes some PARENTS include some builtin-types, obviously
   otherwise the map will be trivial with all cl-types associated with
   the `t` "dummy parent".
   [ We could even go crazy and try and guess PARENTS when not provided,
     by analyzing the type's definition.  ]
- in `cl-types-of` start by calling `cl-type-of`, then use the map to
   find which cl-types may need to be checked.

But let's keep this for later.

I was thinking about the exact same idea not long ago :-) I totally
agree with your analysis.  I noted this point in a FIXME.

Please, find attached a new version of cl-types.el:

- I've divided the code more logically between the `cl-deftype2' macro
  and the `cl--type-generalize' function.

- In `cl-types-of', I implemented the idea of ​​not testing a type
  already selected as a parent of a type already selected :-)

- I tried to add some comments to the not so obvious code.

I also wrote a first try at a test file, cl-types-tests.el, also
attached:

- It includes your proposed tests with multiples-of...
  All tests pass for me :-)

Please let me know if something is not correct, need more work, etc.

Regarding a possible merge in cl-lib, should cl-types.el be copied at
the end of cl-lib, after cl-macs is loaded?  If I correctly understand
the logic of loading these libs ;-)

Thank you!
David

Attachment: cl-types-tests.el
Description: Text Data

Attachment: cl-types.el
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]