Skip to content

Commit

Permalink
name handles strings
Browse files Browse the repository at this point in the history
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information
stuarthalloway committed May 28, 2010
1 parent 89ed54e commit 4bea7a5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/clj/clojure/core.clj
Expand Up @@ -1222,11 +1222,11 @@
(. rev (rseq)))

(defn name
"Returns the name String of a symbol or keyword."
"Returns the name String of a string, symbol or keyword."
{:tag String
:added "1.0"}
[^clojure.lang.Named x]
(. x (getName)))
(if (string? x) x (. x (getName))))

(defn namespace
"Returns the namespace String of a symbol or keyword, or nil if not present."
Expand Down
11 changes: 1 addition & 10 deletions src/clj/clojure/java/shell.clj
Expand Up @@ -52,21 +52,12 @@ collecting its stdout"}
[cmd opts] (split-with string? args)]
[cmd (merge default-opts (apply hash-map opts))]))

(defn- as-env-key
"Helper so that callers can use symbols, keywords, or strings
when building an environment map."
[arg]
(cond
(symbol? arg) (name arg)
(keyword? arg) (name arg)
(string? arg) arg))

(defn- as-env-string
"Helper so that callers can pass a Clojure map for the :env to sh."
[arg]
(cond
(nil? arg) nil
(map? arg) (into-array String (map (fn [[k v]] (str (as-env-key k) "=" v)) arg))
(map? arg) (into-array String (map (fn [[k v]] (str (name k) "=" v)) arg))
true arg))

(defn sh
Expand Down
6 changes: 6 additions & 0 deletions test/clojure/test_clojure/other_functions.clj
Expand Up @@ -44,6 +44,12 @@
(> 5 0) true ))


(deftest test-name
(are [x y] (= x (name y))
"foo" :foo
"bar" 'bar
"quux" "quux"))

; time assert comment doc

; partial
Expand Down

1 comment on commit 4bea7a5

@wilkes
Copy link

@wilkes wilkes commented on 4bea7a5 May 28, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing functions like as-env-key have always annoyed me. Thanks!

Please sign in to comment.