Given a variable with content 1, I know that it's a member of at least five types:
1 (let* ((fred 1))
2 (princ (typep fred 'bit)) (terpri)
3 (princ (typep fred 'integer)) (terpri)
4 (princ (typep fred 'fixnum)) (terpri)
5 (princ (typep fred 'rational)) (terpri)
6 (princ (typep fred t)) (terpri))
T
T
T
T
T
Two questions here.
Given a variable with arbitrary content, how do I determine its supertype path?
Where could I have found the answer for this in documentation?
Supertype & Subtype Example: One good example for explaining this SuperType & SubType is describing the Tax Terms related to Employees. Here Employee is the SuperType or the Parent Entity whereas the two Child Entities “ FULL TIME EMPLOYEE W2 ” & “ HOURLY EMPLOYEE 1099 ” are the SubTypes.
In this section we add rules for mapping supertypes and subtypes to relations. There are three basic options a designer considers when mapping these structures to a database: Create a relation for each entity type in the hierarchy. Create relations for only the bottom-most entity types. Create one relation to represent the whole hierarchy.
This is a complete walkthrough guide with hints, tips, tricks, solutions and answers for the iOS and Android puzzle game, supertype, by Philipp Stollenmayer. Feel free to ask for extra help in the comments section. You can watch this video for the first 30 levels or continue below for my step-by-step guide.
Any type can therefore specialize and/or generalize other types in a multilevel isa hierarchy. Such types are entities in conceptual and logical modeling, and their relationships form supertype-subtype hierarchies. At the top of the hierarchy is the single entity that isn't generalized further; this is the supertype.
You are asking about types, not classes.
You cannot expect a good answer to your question because there are far more types which your number 1
belongs to than you really care about.
E.g.,
(typep 1 '(integer -6 42))
==> T
If you limit your attention to the Standardized Atomic Type Specifiers, you can use something like
(defconstant *Standardized-Atomic-Type-Specifiers* ...) ; see Figure 4-2
(sort (remove-if-not (lambda (type) (typep 1 type))
*Standardized-Atomic-Type-Specifiers*)
#'subtypep)
==> (BIT FIXNUM UNSIGNED-BYTE SIGNED-BYTE INTEGER RATIONAL REAL NUMBER ATOM T)
Now, if you are willing to restrict your interest to classes, the situation becomes much more manageable.
First of all, CLOS supports multiple inheritance, so "supertype path" is not uniquely defined a priori.
However, it has to be defined to determine the method precedence order, and this "path" is called class precedence list. It is computed by the standard MOP function compute-class-precedence-list
:
(compute-class-precedence-list (class-of 1))
==> (#<BUILT-IN-CLASS INTEGER> #<BUILT-IN-CLASS RATIONAL> #<BUILT-IN-CLASS REAL>
#<BUILT-IN-CLASS NUMBER> #<BUILT-IN-CLASS T>)
which is present in most Common Lisp implementations (use apropos
or find-all-symbols
to find which package it is exported from).
You can use class-name
to get the names of the classes instead of their metaobjects:
(mapcar #'class-name (compute-class-precedence-list (class-of 1)))
==> (INTEGER RATIONAL REAL NUMBER T)
Note that bit
, fixnum
, unsigned-byte
, signed-byte
, atom
are not in this list because they do not name standard classes, just types.
That's not easy, IIRC.
I would use CLOS in some way:
CL-USER 34 > (loop for c = (class-of 1)
then (first (class-direct-superclasses c))
collect (class-name c)
until (eq c (find-class t)))
(FIXNUM INTEGER RATIONAL REAL NUMBER T)
Note that you need CLASS-DIRECT-SUPERCLASSES
which is provided by CLOS implementations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With