FOOP Scoop!
If this is the mother of all constructors:
(define (Class:Class) (cons (context) (args)))
Then this must be the daddy of all predicates:
(define (Class:? obj)
(and (list? obj) (not (empty? obj)) (= (obj 0) (context)))
)
Of course, for this to have real meaning within the context of your code, you must use the fully qualified method name when applying it:
> (Point:? (Point 23 54))
true
> (Complex:? (Complex 0.68 -1.64))
true
> (Complex:? (Point 0 0))
nil
> _
When using it this way, it's usually referred to as a class method.
The predicate's first two tests, (list? obj) and (not (empty? obj))), can become part of a function to test for objectness:
(constant (global 'object?)
(fn (obj)
(and (list? obj) (not (empty? obj)) (context? (obj 0)))
)
)
With that, you could define the predicate this way:
(define (Class:? obj) (and (object? obj) (= (obj 0) (context))))
Even though these should be used as class methods, you can still apply the ? to an object using polymorphism:
> (:? (Point 23 43))
true
> (:? (Complex 0.33 0.11))
true
> (:? (CornFlakes (CornFlake) (CornFlake) (CornFlake) ...))
true
> _
But in essence, all you're really asking the object is: are you your own type? :-)
m i c h a e l
P.S. Even the ellipsis in the CornFlakes object can become valid newLISP code:
(set '... '...)
;-)
Thanks! What little treasures I find while leisurely browsing the newLISP forum instead of learning Cocoa...