clojure.string no namespace error

170 views
Skip to first unread message

Omer Kudat

unread,
Oct 18, 2011, 5:52:09 AM10/18/11
to Clojure
Hi all,

I've started to teach myself clojure recently, so apologies for a
potentially stupid question.

I'm using clojure-1.3.0.jar, downloaded very recently. I would like to
use clojure.string/split-lines, but I cannot access the namespace.

I've tried:
(import 'clojure.string)
(import 'string)
and
(:require [clojure.string :as str]))

The last one is from the documentation in the string.clj file embedded
in the jar. They all throw either a "java.lang.ClassNotFoundException:
clojure.string" or a "java.lang.Exception: No namespace:
clojure.string".

Calling (all-ns) gives me a list of namespaces which does not include
string, and (find-ns) doesn't find clojure.string either.

Not sure what I'm doing wrong. Any pieces of wisdom?
Omer

Philipp Meier

unread,
Oct 18, 2011, 9:10:22 AM10/18/11
to clo...@googlegroups.com
If you do a

(require 'clojure.string)

then all vars will be accessible as clojure.string/... e.g. clojure.string/split-lines.

You can use "use" to import the vars into the current namespane:

(use 'clojure.string)

This wil make available all vars from clojure.string in you current namespace (e.g. user).

The later syntax is for use within the macro "ns" to declare a namespace, e.g.

(ns user (:require [clojure.string :as str]))

Omer Kudat

unread,
Oct 18, 2011, 9:50:04 AM10/18/11
to clo...@googlegroups.com
Thanks, I think I was trying to wrong thing (don't know why I was trying to use import rather than require).

Aaron Bedra

unread,
Oct 18, 2011, 4:28:41 PM10/18/11
to clo...@googlegroups.com
Here's an example from the REPL that should get you going:

user => (require '[clojure.string :as str])
nil
user=> (str/split-lines "foo\nbar\r\nbaz\n")
["foo" "bar" "baz"]

Cheers,

Aaron Bedra
--
Clojure/core
http://clojure.com

Reply all
Reply to author
Forward
0 new messages