On Sunday 01 August 2010 21:34:16 Kyle Schaffrick wrote:
Hi,
The following technique seems to work for finding out if you've been
aliased:
(ns somewhere.trial)
(let [here *ns*]
(defmacro whats-my-name []
(some (fn [[k v]] (when (= here v) `(quote ~k)))
(ns-aliases *ns*))))
user> (require '[somewhere.trial :as aliased]) =>
user> (aliased/whats-my-name) => aliased
So at the top of with-feature the parser could check for an alias and
construct the appropriate predicate from the result.
-Andy
> Hello,
>
> I'm trying to write a library with two main parts. The first is a
> macro, I'll call it 'with-feature, that walks through forms passed
> inside it, and any time it sees a call to another function in my
> library, 'feature, do some transformations.
>
> The problem I'm concerned about is as follows: When my macro sees
the
> forms that are passed into it, the symbols come in however the
consumer
> of the library wrote them. So say I :require my library and alias it to
> 'mylib', then the call 'with-feature is looking for appears as
> 'mylib/feature. Or, I could :use the library, and then it would appear
> as 'feature, or I could alias 'feature to 'banana--you get the idea.
>
> I don't want to reserve some magic symbol name that defies
namespace
> rules, so that if the library consumer code uses the symbol 'feature
> to mean something different, they get bizarre results.
>
> What is a good pattern for writing the "matching" logic in such a
> selectively-transforming macro so that it can properly find the magic
> call it's looking for in the presence of normal namespacing behavior?
>
> Thanks,
>
> -Kyle
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en