Wow, you even implemented the rules! Good job. When I began to work on the rules, I realized a simple reference to the points would alleviate the need for them altogether. As long as our objects remain isolated from one another, they're nothing but glorified records. No object is an island ;-)
Lutz wrote:Perhaps we could define some basic rules, everybody could agree upon
That seems unlikely ;-) While there's no reason to forbid having multiple OOPs, by creating an
official version, we can begin to depend on it just as we now do with the language. To write intros and tutorials using it. To help attract OO programmers to newLISP.
I've used languages with no official object system, but many unofficial ones. Rather than improve the situation, it leads to simplistic, watered-down, unfinished OOPs.
I appreciate the simplicity of
def-type and feel it blends well with the language. I tried four or five object systems on my own, and none of them amounted to much. Fanda's OOP framework has progressed further than any of mine did (I really like how
object-do works), but as Fanda said himself, it's modeled on the way REBOL does objects. I would like an object system different from all the rest. I've not been truly satisfied with any OOP language (Smalltalk being the exception), so I'd rather try something that fits perfectly with the existing language, while improving upon the poor OO systems of the past.
Lutz wrote:This way we still leave open the implementation but agree on some basics for object and method representation and usage?
I like the idea of working in an idealized form before committing to any one implementation. Here is an example of my own, with object references using symbols:
Code: Select all
(load "def-type.lsp")
(def-type (point (x 0) (y 0)))
(define (point:string pt) (string (point:x pt) "@" (point:y pt)))
(define (point:xy pt x y) (point:x pt x) (point:y pt y))
(define (point:move pt dx dy)
(point:x pt (+ dx (point:x pt)))
(point:y pt (+ dy (point:y pt)))
)
(def-type (segment (a (point)) (b (point)))
(define (segment:string sg)
(string (point:string (segment:a sg)) " to " (point:string (segment:b sg)))
)
(define (segment:move sg ax ay bx by)
(point:move (segment:a sg) ax ay)
(point:move (segment:b sg) bx by)
)
(def-type (triangle (ab (segment)) (bc (segment)) (ca (segment))))
(define (triangle:string tr)
(string
(segment:string (triangle:ab tr)) ", "
(segment:string (triangle:bc tr)) ", "
(segment:string (triangle:ca tr))
)
)
;; S A M P L E R U N
(set 'a (point))
(println (point:string a))
(set 'b (point 20 0))
(println (point:string b))
(set 'c (point 10 5))
(println (point:string c))
(set 'ab (segment 'a 'b)) ; notice that this and the following are passing references.
(println (segment:string ab))
(set 'bc (segment 'b 'c))
(println (segment:string bc))
(set 'ca (segment 'c 'a))
(println (segment:string ca))
(set 'tri (triangle 'ab 'bc 'ca))
(println (triangle:string tri))
(println "Move segment 'bc':")
(segment:move (triangle:bc tri) 30 5 20 10)
(println (triangle:string tri))
;; E N D
Should output:
Code: Select all
0@0
20@0
10@15
0@0 to 20@0
20@0 to 10@15
10@15 to 0@0
0@0 to 20@0, 20@0 to 10@15, 10@15 to 0@0
0@0 to 50@5, 50@5 to 30@25, 30@25 to 0@0
That's it :-)
m i c h a e l