Am Dienstag, 10. Januar 2017 01:19:16 UTC+1 schrieb Didier:
>
> How would you declare a namespace within a namespace? Or two namespaces in 
> the same file?
>
>
You can do so quite easily.

  (ns foo.bar)

  (defmulti a :dispatch)

  (defn b
    [x]
    (str "Called a. This was the result: " (a x)))

  (ns foo.bar.hidden)
  (alias 'parent 'foo.bar)

  (defmethod parent/a :yoyo
    [x]
    (str "yoyo: " (:value x)))

  (defmethod parent/a :dyne
    [x]
    (str "dyne: " (:value x)))

  ; Go back to original namespace.
  (in-ns 'foo.bar)

As you can try in the repl, this works.

  user=> (require 'foo.bar)
  nil
  user=> (foo.bar/b {:dispatch :yoyo :value 5})
  "Called a. This was the result: yoyo: 5"
  user=> (foo.bar/b {:dispatch :dyne :value 5})
  "Called a. This was the result: dyne: 5"

That said: I wouldn't recommend this. I'm not sure, I see a situation that 
would justify the weirdness and hidden complexities of this approach. Too 
much rope... If you really need this style of thing, put the hidden 
namespace in its own file and use load.

Kind regards
Meikel

-- 
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/d/optout.

Reply via email to