Permalink
Browse files

Ch. 5 excercises

  • Loading branch information...
1 parent 5c8b9de commit a3851b91f88a1298c0ae94419ddac533287d2022 @aubreyrhodes committed Nov 30, 2012
Showing with 28 additions and 0 deletions.
  1. +28 −0 my-solutions/class.clj
View
@@ -0,0 +1,28 @@
+(load-file "sources/class.clj")
+
+(def apply-message-to
+ (fn [class instance message args]
+ (let [method (message (:__instance_methods__ class))]
+ (apply method instance args))))
+
+(def class-from-instance
+ (fn [instance]
+ (eval (:__class_symbol__ instance))))
+
+(def send-to
+ (fn [instance message args]
+ (apply-message-to (class-from-instance instance) instance message args)))
+
+(println (let [a-point (make Point 1 1)]
+ (apply-message-to Point a-point :shift [1 3])))
+
+;; Excercise 3
+(def apply-message-to
+ (fn [class instance message args]
+ (let [method (or (message (:__instance_methods__ class))
+ message)]
+ (apply method instance args))))
+
+(def b-point (make Point 2 2))
+
+(println (send-to b-point :x []))

0 comments on commit a3851b9

Please sign in to comment.