Examples :
Code: Select all
(context 'Point)
(set 'x 0 'y 0)
(context MAIN)
(new Point 'p1)
(set 'p1:x 3 'p1:y 4)
(new Point 'p2)
(set 'p2:x 3 'p2:y 4)
(println (= p1 p2)) ; => nil : p1 and p2 are two distinct objects
(set 'p3 p1)
(println (= p1 p3)) ; => true : p1 and p3 refer to the same object
; this demonstrates that
(set 'p1:x 7)
(println p3:x) ;=> 7
;; with FOOP :
(define (Point:Point x y)
(list Point x y))
(set 'p1 (Point 3 4))
(set 'p2 (Point 3 4))
(println (= p1 p2)) ; => true
(set 'p3 p1)
(println (= p1 p3)) ; => true
(set 'p1 (Point 7 4))
(println p1) ;=> (Point 7 4)
(println p3) ;=> (Point 3 4)
With 'Context' :
Code: Select all
(context 'Point)
(set 'x 0 'y 0)
(context MAIN)
(new Point 'p1)
(set 'p1:x 3 'p1:y 4)
(println p1:x) ; => 3
Code: Select all
(define (Point:Point x y)
(list Point x y))
(set 'p1 (Point 3 4))
(println p1) ;=> (Point 3 4)