[<<][compsci][>>][..]
Sun Mar 14 14:49:41 CET 2010

Ziggurat

The example from fig1+2 in [1].

;;; Fig 1: Creating classes and objects

;; Real number objects are described by a pair of integers (m . e)
;; where the value x is determined by x = m * 10^e
(define real-class (make-top-class))

;; Integer objects are described by a single integer; to instantiate
;; as a real number, use an exponent of 1.
(define int-class
  (make-class
   (lambda (x) (make-object real-class
                            (cons x 0)))))

;;; Fig 2: Creating methods

(declare-method (num->string n))

(method real-class num->string
        (lambda (n)
          (let ((data (view real-class n))
                (mant (car data))
                (exp  (cdr data)))
            (format "~sE~s" mant exp))))

(method int-class num->string
        (lambda (n)
          (let ((snum (view int-class n)))
            (number->string snum))))

;; Methods are functions that take the object as an argument.  The
;; `view' form returns the internal representation of an object.


I don't understand: why does int-class call (make-object real-class
...) while it still has access to the integer?

I don't get the paper.  I find no point to hook on.  Maybe some code
and interaction would help?


[1] http://www.ccs.neu.edu/home/dfisher/icfp06-ziggurat.pdf



[Reply][About]
[<<][compsci][>>][..]