That is very elegant but has the exact same problem in that the macro
must be called on a literal vector of keywords.

--Robert McIntyre

On Fri, Sep 10, 2010 at 5:41 PM, Btsai <benny.t...@gmail.com> wrote:
> This is probably not the prettiest way to do it, but I think it gets
> the job done:
>
> (defn make-sym [keyword]
>  (->> keyword name (str "prefix-") symbol))
>
> (defn make-fn [keyword]
>  (let [n (gensym)]
>   (list 'defn (make-sym keyword) [n] (list '= n keyword))))
>
> (defmacro make-fns [keywords]
>  `(do ~@(map make-fn keywords)))
>
> user=> (make-fns [:a :b :c])
> #'user/prefix-c
> user=> (prefix-a :a)
> true
> user=> (prefix-a :x)
> false
> user=> (prefix-b :b)
> true
> user=> (prefix-b :x)
> false
> user=> (prefix-c :c)
> true
> user=> (prefix-c :x)
> false
>
> The credit belongs to Alan, and Mr. Stuart Halloway for his examples
> from Ch. 7 of Programming Clojure.
>
> On Sep 10, 2:37 pm, icemaze <icem...@gmail.com> wrote:
>> Alan, thank you for your reply.
>> Unfortunately your solution is very similar to mine and it suffers
>> from the same problem (maybe I'm using it incorrectly, I don't know).
>> If I write:
>>
>>   (doseq [x '(:a :b)]
>>     (make-fn x))
>>
>> it defines a single function "synthetic-x". Is there a way to make
>> this work? I tried everything but both eval and var-get don't work for
>> local bindings.
>>
>> Thanks again.
>
> --
> 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
> Note that posts from new members are moderated - please be patient with your 
> first post.
> 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

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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