functional-koans / clojure-koans

A set of exercises for learning Clojure
3.73k stars 2.14k forks source link

Repl namespace issue #146

Open rr326 opened 5 years ago

rr326 commented 5 years ago

Something is wrong in the namespace setup (I think).

--> lein repl
nREPL server started on port 49447 on host 127.0.0.1 - nrepl://127.0.0.1:49447
REPL-y 0.4.3, nREPL 0.6.0
Clojure 1.10.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_121-b13
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

koan-engine.runner=> (string/join '(1 2 3))
Syntax error compiling at (form-init1178655580028819709.clj:1:1).
No such namespace: string

The koans themselves run successfully. This is MacOS. Sorry if I'm doing something dumb.

trptcolin commented 5 years ago

Yeah, I can see why that's confusing. Here's a short-term fix for you:

koan-engine.runner=> (clojure.string/join '(1 2 3))
"123"

...or...

koan-engine.runner=> (require '[clojure.string :as string])
nil
koan-engine.runner=> (string/join '(1 2 3))
"123"

See https://8thlight.com/blog/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html for more detail.

I think there are probably improvements we can make to the koans in order to make it clearer what's going on with namespaces, so I'll leave this open as a reminder (and in case anyone wants to tackle it!)