linfo2335-programming-parad.../project-2/step0.rkt

26 lines
672 B
Racket

;Auhors:Dubois Brieuc, Dubois Simon
;Addapted from the example given in the assignment. Major change are:
; function directly defined in dispatch
; = changed to eq? to take symbol as input
; eror message added
;Class definition
(define (point x y)
(define (dispatch m)
(cond ((eq? m 'getx) x)
((eq? m 'gety) y)
((eq? m 'type) 'point)
((eq? m 'info) (list 'point x y))
(else (display (string-append "point as no method: " (symbol->string m) "\n")))))
dispatch)
;Usage example
(define p (point 1 2))
(p 'getx) ; 1
(p 'gety) ; 2
(p 'type) ; point
(p 'info) ; (point 1 2)
(p 'foo) ; display "point as no method: foo"