Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:clojure/clojurescript

  • Loading branch information...
commit e5024ae2afed61a6594be6fc4e1a13e029b9e47b 2 parents 3ab435b + d953531
@swannodette swannodette authored
Showing with 57 additions and 19 deletions.
  1. +45 −13 src/cljs/cljs/core.cljs
  2. +12 −6 src/cljs/cljs/reader.cljs
View
58 src/cljs/cljs/core.cljs
@@ -248,6 +248,10 @@
IHash
(-hash [o] o))
+(extend-type boolean
+ IHash
+ (-hash [o] (js* "((~{o} === true) ? 1 : 0)")))
+
(extend-type function
IHash
(-hash [o] (goog.getUid o)))
@@ -286,13 +290,28 @@ reduces them without incurring seq initialization"
(-rest [_] (if (< (inc i) (.length a))
(IndexedSeq. a (inc i))
(list)))
+
ICounted
- (-count [_] (.length a))
+ (-count [_] (- (.length a) i))
+
+ IIndexed
+ (-nth [coll n]
+ (let [i (+ n i)]
+ (when (< i (.length a))
+ (aget a i))))
+ (-nth [coll n not-found]
+ (let [i (+ n i)]
+ (if (< i (.length a))
+ (aget a i)
+ not-found)))
ISequential
IEquiv
(-equiv [coll other] (equiv-sequential coll other))
+ ICollection
+ (-conj [coll o] (cons o coll))
+
IReduce
(-reduce [coll f]
(ci-reduce coll f (aget a i) (inc i)))
@@ -968,18 +987,31 @@ reduces them without incurring seq initialization"
;;;;;;;;;;;;;;;;;;;;;;;;;; basics ;;;;;;;;;;;;;;;;;;
+(defn- str*
+ "Internal - do not use!"
+ ([] "")
+ ([x] (cond
+ (nil? x) ""
+ :else (. x (toString))))
+ ([x & ys]
+ ((fn [sb more]
+ (if more
+ (recur (. sb (append (str* (first more)))) (next more))
+ (str* sb)))
+ (gstring/StringBuffer. (str* x)) ys)))
+
(defn str
"With no args, returns the empty string. With one arg x, returns
x.toString(). (str nil) returns the empty string. With more than
one arg, returns the concatenation of the str values of the args."
([] "")
- ([x] (if (nil? x) "" (. x (toString))))
+ ([x] (cond
+ (symbol? x) (. x (substring 2 (.length x)))
+ (keyword? x) (str* ":" (. x (substring 2 (.length x))))
+ (nil? x) ""
+ :else (. x (toString))))
([x & ys]
- ((fn [sb more]
- (if more
- (recur (. sb (append (str (first more)))) (next more))
- (str sb)))
- (gstring/StringBuffer. (str x)) ys)))
+ (apply str* x ys)))
(defn subs
"Returns the substring of s beginning at start inclusive, and ending
@@ -990,17 +1022,17 @@ reduces them without incurring seq initialization"
(defn symbol
"Returns a Symbol with the given namespace and name."
([name] (cond (symbol? name) name
- (keyword? name) (str "\uFDD1" "'" (subs name 2))
- :else (str "\uFDD1" "'" name)))
- ([ns name] (symbol (str ns "/" name))))
+ (keyword? name) (str* "\uFDD1" "'" (subs name 2)))
+ :else (str* "\uFDD1" "'" name))
+ ([ns name] (symbol (str* ns "/" name))))
(defn keyword
"Returns a Keyword with the given namespace and name. Do not use :
in the keyword strings, it will be added automatically."
([name] (cond (keyword? name) name
- (symbol? name) (str "\uFDD0" "'" (subs name 2))
- :else (str "\uFDD0" "'" name)))
- ([ns name] (keyword (str ns "/" name))))
+ (symbol? name) (str* "\uFDD0" "'" (subs name 2))
+ :else (str* "\uFDD0" "'" name)))
+ ([ns name] (keyword (str* ns "/" name))))
View
18 src/cljs/cljs/reader.cljs
@@ -71,7 +71,7 @@ nil if the end of stream has been reached")
(throw (apply str msg)))
(defn macro-terminating? [ch]
- (and (not= ch "#") (not= ch \') (contains? macros ch)))
+ (and (not= ch "#") (not= ch \') (not= ch ":") (contains? macros ch)))
(defn read-token
[rdr initch]
@@ -95,6 +95,7 @@ nil if the end of stream has been reached")
(def int-pattern (re-pattern "([-+]?)(?:(0)|([1-9][0-9]*)|0[xX]([0-9A-Fa-f]+)|0([0-7]+)|([1-9][0-9]?)[rR]([0-9A-Za-z]+)|0[0-9]+)(N)?"))
(def ratio-pattern (re-pattern "([-+]?[0-9]+)/([0-9]+)"))
(def float-pattern (re-pattern "([-+]?[0-9]+(\\.[0-9]*)?([eE][-+]?[0-9]+)?)(M)?"))
+(def symbol-pattern (re-pattern "[:]?([^0-9/].*/)?([^0-9/][^/]*)"))
(defn- match-int
[s]
@@ -252,11 +253,16 @@ nil if the end of stream has been reached")
(defn read-keyword
[reader initch]
- (let [token (read-token reader (read-char reader))]
- (if (gstring/contains token "/")
- (keyword (subs token 0 (.indexOf token "/"))
- (subs token (inc (.indexOf token "/")) (.length token)))
- (keyword token))))
+ (let [token (read-token reader (read-char reader))
+ [token ns name] (re-matches symbol-pattern token)]
+ (if (or (and (not (undefined? ns))
+ (identical? (. ns (substring (- (.length ns) 2) (.length ns))) ":/"))
+ (identical? (aget name (dec (.length name))) ":")
+ (not (== (.indexOf token "::" 1) -1)))
+ (reader-error reader "Invalid token: " token)
+ (if (not (undefined? ns))
+ (keyword (.substring ns 0 (.indexOf ns "/")) name)
+ (keyword token)))))
(defn desugar-meta
[f]
Please sign in to comment.
Something went wrong with that request. Please try again.