17 lines
419 B
Racket
17 lines
419 B
Racket
(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
|
|
|
|
|