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

17 lines
419 B
Racket
Raw Normal View History

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)
(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