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

26 lines
672 B
Racket
Raw Normal View History

2024-04-26 23:07:23 +02:00
;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
2024-04-23 22:05:17 +02:00
(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)
2024-04-26 23:07:23 +02:00
;Usage example
2024-04-23 22:05:17 +02:00
(define p (point 1 2))
(p 'getx) ; 1
(p 'gety) ; 2
(p 'type) ; point
(p 'info) ; (point 1 2)
2024-04-26 23:07:23 +02:00
(p 'foo) ; display "point as no method: foo"
2024-04-23 22:05:17 +02:00