Thanks Chouser,

No, I really didn't have any intentions with this example. I was
merely exploring around. In hindsight it is also obvious why this
works.

(defn foo[]
  (defn bar [x] (* x 2))
  nil)
(foo)
(bar 2)    ---> returns 4

I just didn't realize initially what was going on... that defn binds
globally. And yeah, this could be abused to allow some kind of weird
mutability. I was't going for that. :)

What I originally wrote was this.... (with camel case corrected)

(defn create-a [first-name last-name]
  (let [fnc-map {'type (fn [] "person")
                 'get-first-name (fn [] first-name)
                 'get-last-name (fn [] last-name)
                 'name-length (fn [] (+ (count first-name) (count last-name)))}]
    (fn [fnc-symbol & args]
      (apply (fnc-map fnc-symbol) args))))

((create-a "Kurt" "Z") 'get-first-name)

(def bob-vance (create-a "Bob" "Vance"))
(bob-vance 'name-length)
(bob-vance 'get-first-name)

I wasn't completely satisfied with the example because it seemed I
could make it a bit more abstract. Before I went down the path of
writing a macro, I ended up stumbling on some strangeness with defn.

If you are curious as to my intentions, I have been watching the SICP
lecture series. And I was a bit intrigued in alternative ways of
implenting simple "types" in a lisp instead of having a lookup table.

Kurt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to