09 decembrie 2014

Eopl3: chapter 9.4 solution to exercise 9.6

> lang.scm__________________________________________________________

        (expression
            ("instanceof" expression identifier)
        instance-exp)

> interp.scm________________________________________________________

        (instance-exp (expr className)
            (let ((hisClass (object->class-name (value-of expr env))))
                (if (eq? className hisClass) (bool-val #t) (bool-val #f))))

_______________________Test:______________________________________ __

class c1 extends object
    field x
    field y
    method initialize ()
        begin
         set x = 11;
         set y = 12
        end
    method m1 ()
        -(x,1)

class c2 extends object
    field x
    method initialize ()
        begin
         set x = 0
        end

let o2 = new c2() in instanceof o2 c1    ;; #f

;; let o2 = new c1() in instanceof o2 c1    ;; #t


alte ex rezolvate de altii: aici

Niciun comentariu: