If this is the mother of all constructors:
Code: Select all
(define (Class:Class) (cons (context) (args)))
Code: Select all
(define (Class:? obj)
(and (list? obj) (not (empty? obj)) (= (obj 0) (context)))
)
Code: Select all
> (Point:? (Point 23 54))
true
> (Complex:? (Complex 0.68 -1.64))
true
> (Complex:? (Point 0 0))
nil
> _
The predicate's first two tests, (list? obj) and (not (empty? obj))), can become part of a function to test for objectness:
Code: Select all
(constant (global 'object?)
(fn (obj)
(and (list? obj) (not (empty? obj)) (context? (obj 0)))
)
)
Code: Select all
(define (Class:? obj) (and (object? obj) (= (obj 0) (context))))
Code: Select all
> (:? (Point 23 43))
true
> (:? (Complex 0.33 0.11))
true
> (:? (CornFlakes (CornFlake) (CornFlake) (CornFlake) ...))
true
> _
m i c h a e l
P.S. Even the ellipsis in the CornFlakes object can become valid newLISP code:
Code: Select all
(set '... '...)