Skip to content

Instantly share code, notes, and snippets.

@kbaribeau
Last active August 18, 2016 08:39
Show Gist options
  • Save kbaribeau/d0d94c02a598490653de to your computer and use it in GitHub Desktop.
Save kbaribeau/d0d94c02a598490653de to your computer and use it in GitHub Desktop.
Clojure defrecord, namespaces, and dashes vs underscores
user=> (ns my-ns)
nil
my-ns=> (defrecord Outfit [shirt pants])
my_ns.Outfit
my-ns=> (ns clothes.outfit
#_=> (:require [my-ns])
#_=> (:import [my_ns Outfit])); note that we defined it in my-ns, but we have to use an underscore to import it
nil
clothes.outfit=> (Outfit. "t-shirt" "jeans")
#my_ns.Outfit{:shirt "t-shirt", :pants "jeans"}
clothes.outfit=> (ns clothes.outfit
#_=> (:require [my-ns])
#_=> (:import [my-ns Outfit])) ; if we try to import it with a '-', like we defined it, we get a ClassNotFoundException
ClassNotFoundException my-ns.Outfit java.net.URLClassLoader$1.run (URLClassLoader.java:366)
clothes.outfit=>
@collinalexbell
Copy link

Ya, this is weird. Why does it do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment