Created
March 13, 2016 20:36
-
-
Save keyvanakbary/4e3ccda72c169dcaf1b3 to your computer and use it in GitHub Desktop.
Modelling objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (create-user name) | |
(define say-hello | |
(print "Hello " name)) | |
(define (change-name new-name) | |
(set! name new-name) | |
name) | |
(define (dispatch method) | |
(cond | |
((eq? method 'say-hello) say-hello) | |
((eq? method 'change-name) change-name) | |
(else (raise "Invalid method")))) | |
dispatch) | |
(define user (create-user "Keyvan")) | |
(user 'say-hello) | |
; Hello Keyvan | |
((user 'change-name) "John") | |
(user 'say-hello) | |
; Hello John |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
solo por ver como quedaba te lo he picado en scala xD