4 ms·
Common Lisp also provides type information, dynamic type information. CL-USER 72 > (defclass person () (name age)) #<STANDARD-CLASS PERSON 80101598FB>
by lispm 2y ago
Common Lisp also provides type information, dynamic type information.
CL-USER 72 > (defclass person () (name age))
#<STANDARD-CLASS PERSON 80101598FB>
I can now ask Lisp to find the class object named person.
CL-USER 73 > (find-class 'person)
#<STANDARD-CLASS PERSON 80101598FB>
Now I've got a real class object, not just a pointer to dead code. I can inspect it, change it...
I'm adding a slot to an existing class:
CL-USER 74 > (defclass person () (name age height))
#<STANDARD-CLASS PERSON 80101598FB>
I can then ask for the slots of that class.
CL-USER 75 > (class-direct-slots (find-class 'person))
(#<STANDARD-DIRECT-SLOT-DEFINITION NAME 8220278CA3>
#<STANDARD-DIRECT-SLOT-DEFINITION AGE 8220278CBB>
#<STANDARD-DIRECT-SLOT-DEFINITION HEIGHT 8220278CD3>)
I can define a method for it.
CL-USER 76 > (defmethod greet ((a-person person)) (format t "Hello ~a" (slot-value a-person 'name)))
#<STANDARD-METHOD GREET NIL (PERSON) 801001B69B>
I now can retrieve the method object from its generic function.
CL-USER 77 > (find-method #'greet () (list (find-class 'person)))
#<STANDARD-METHOD GREET NIL (PERSON) 801001B69B>
That's live code exploration using dynamic types.
> You can do this with most major languages today as well.
Hmm, I'm in this graphics program on my Mac, how do I "break" the program and then interact with its Objective-C objects?