Gary Verhaegen <gary.verhae...@gmail.com> writes:
> Well, do actually means "execute all of the following forms, sequentially,
> at this point". It seems to me that the position of saying this also works
> when "this point" is the top-level is sensible.

Perhaps; what does not seem sensible is that it *only* works at
top-level. As I gave in my original email

(do (intern 'user 'x 1)
    x)

works, but 

(try
    (do (intern 'user 'y 1)
     y))

fails.


> I do not know what your actual use-case is, but, as Meikel said, it seems a
> bit strange to use intern if you know the symbol at compile time.

Yes, I didn't explain that.

So, I have a library which provides a load of "def" forms which all
intern. This is implemented through a macro which expands to a def form. 


(defmacro intern-owl
  "Intern an OWL Entity. Compared to the clojure.core/intern function this
signals a hook, and adds :owl true to the metadata. NAME must be a symbol"
  ([name entity]
     ;; we use def semantics here, rather than intern-owl-string, because
     ;; intern is not picked up by the compiler as defining a symbol
     `(tawny.owl/run-intern-hook
       (def ~(vary-meta name
                        merge
                        {:owl true})
              ~entity))))


As you can see, I add some metadata and run a hook function. This is my
main use case; it works because I know the symbol at compile time.

However, in a secondary use case, I do not know the symbol and have to
calculate it. It looks like this....

(defn intern-owl-string
  "Interns an OWL Entity. Compared to the clojure.core/intern function this
signals a hook, and adds :owl true to the metadata. NAME must be a strings"
  ([name entity]
     (tawny.owl/run-intern-hook
      (intern *ns*
              (with-meta
                (symbol name)
                {:owl true})
               entity))))

So, now we have two problems. The first is that I have two nearly
identical functions. And the second, intern-owl-string will fail under
difficult to predict circumstances (for someone who does't know the guts
of the compiler).

As it happens, the second is mostly a pain during testing -- and I can
work around it -- this form for instance works okay.

(try (let [sym 'b] (intern 'user sym 1)(var-get (get (ns-publics *ns*) sym))))

and does the same as this.

(try (do (intern 'user 'y 1) y))

Phil

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to