Permalink
Browse files

require dynamically rebindable vars be explicitly declared dynamic, v…

…ia ^:dynamic metadata support in def, or setDynamic builder method in Var. Also auto-enable :dynamic for *var*s as a bridge - prints warning, and will be removed before release.
  • Loading branch information...
richhickey committed Oct 15, 2010
1 parent 64e4a00 commit b9b1a094499b69a94bd47fc94c4f082d80239fa9
View
@@ -3140,7 +3140,7 @@
(number? x) (BigDecimal/valueOf (long x))
:else (BigDecimal. x)))
-(def ^{:private true} print-initialized false)
+(def ^:dynamic ^{:private true} print-initialized false)
(defmulti print-method (fn [x writer] (type x)))
(defmulti print-dup (fn [x writer] (class x)))
@@ -5095,17 +5095,17 @@
;;;;;;;;;;; require/use/load, contributed by Stephen C. Gilardi ;;;;;;;;;;;;;;;;;;
-(defonce
+(defonce ^:dynamic
^{:private true
:doc "A ref to a sorted set of symbols representing loaded libs"}
*loaded-libs* (ref (sorted-set)))
-(defonce
+(defonce ^:dynamic
^{:private true
:doc "the set of paths currently being loaded by this thread"}
*pending-paths* #{})
-(defonce
+(defonce ^:dynamic
^{:private true :doc
"True while a verbose load is pending"}
*loading-verbosely* false)
@@ -5465,22 +5465,22 @@
:static true}
[coll] (instance? clojure.lang.Reversible coll))
-(def
+(def ^:dynamic
^{:doc "bound in a repl thread to the most recent value printed"
:added "1.0"}
*1)
-(def
+(def ^:dynamic
^{:doc "bound in a repl thread to the second most recent value printed"
:added "1.0"}
*2)
-(def
+(def ^:dynamic
^{:doc "bound in a repl thread to the third most recent value printed"
:added "1.0"}
*3)
-(def
+(def ^:dynamic
^{:doc "bound in a repl thread to the most recent exception caught by the repl"
:added "1.0"}
*e)
@@ -5941,7 +5941,7 @@
:minor (Integer/valueOf ^String (prop "minor"))
:incremental (Integer/valueOf ^String (prop "incremental"))
:qualifier (prop "qualifier")}]
- (def *clojure-version*
+ (def ^:dynamic *clojure-version*
(if (not (= (prop "interim") "false"))
(clojure.lang.RT/assoc clojure-version :interim true)
clojure-version)))
@@ -12,7 +12,7 @@
(import '(java.io Writer))
-(def
+(def ^:dynamic
^{:doc "*print-length* controls how many items of each collection the
printer will print. If it is bound to logical false, there is no
limit. Otherwise, it must be bound to an integer indicating the maximum
@@ -23,7 +23,7 @@
:added "1.0"}
*print-length* nil)
-(def
+(def ^:dynamic
^{:doc "*print-level* controls how many levels deep the printer will
print nested objects. If it is bound to logical false, there is no
limit. Otherwise, it must be bound to an integer indicating the maximum
@@ -17,7 +17,7 @@
(-> "os.name" System/getProperty .toLowerCase
(.startsWith "mac os x")))
-(def *open-url-script* (when (macosx?) "/usr/bin/open"))
+(def ^:dynamic *open-url-script* (when (macosx?) "/usr/bin/open"))
(defn- open-url-in-browser
"Opens url (a string) in the default system web browser. May not
@@ -13,17 +13,17 @@
(:import
(java.io File)))
-(def *feeling-lucky-url* "http://www.google.com/search?btnI=I%27m%20Feeling%20Lucky&q=allinurl:")
-(def *feeling-lucky* true)
+(def ^:dynamic *feeling-lucky-url* "http://www.google.com/search?btnI=I%27m%20Feeling%20Lucky&q=allinurl:")
+(def ^:dynamic *feeling-lucky* true)
-(def *local-javadocs* (ref (list)))
+(def ^:dynamic *local-javadocs* (ref (list)))
-(def *core-java-api*
+(def ^:dynamic *core-java-api*
(if (= "1.5" (System/getProperty "java.specification.version"))
"http://java.sun.com/j2se/1.5.0/docs/api/"
"http://java.sun.com/javase/6/docs/api/"))
-(def *remote-javadocs*
+(def ^:dynamic *remote-javadocs*
(ref (sorted-map
"java." *core-java-api*
"javax." *core-java-api*
@@ -15,8 +15,8 @@ collecting its stdout"}
(:import (java.io OutputStreamWriter ByteArrayOutputStream StringWriter)
(java.nio.charset Charset)))
-(def *sh-dir* nil)
-(def *sh-env* nil)
+(def ^:dynamic *sh-dir* nil)
+(def ^:dynamic *sh-env* nil)
(defmacro with-sh-dir
"Sets the directory for use with sh, see sh for details."
@@ -63,7 +63,7 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm
navigator (init-navigator args)]
(execute-format writer compiled-format navigator)))
-(def ^{:private true} *format-str* nil)
+(def ^:dynamic ^{:private true} *format-str* nil)
(defn- format-error [message offset]
(let [full-message (str message \newline *format-str* \newline
@@ -20,7 +20,7 @@
(import [clojure.lang IDeref]
[java.io Writer])
-(def ^{:private true} *default-page-width* 72)
+(def ^:dynamic ^{:private true} *default-page-width* 72)
(defn- get-field [^Writer this sym]
(sym @@this))
@@ -289,7 +289,7 @@
(pprint-simple-code-list alis)))
;;; The map of symbols that are defined in an enclosing #() anonymous function
-(def ^{:private true} *symbol-map* {})
+(def ^:dynamic ^{:private true} *symbol-map* {})
(defn- pprint-anon-func [alis]
(let [args (second alis)
@@ -342,7 +342,7 @@
%))
amap))))
-(def ^{:private true} *code-table*
+(def ^:dynamic ^{:private true} *code-table*
(two-forms
(add-core-ns
{'def pprint-hold-first, 'defonce pprint-hold-first,
@@ -27,64 +27,64 @@
;;; constructs
-(def
+(def ^:dynamic
^{:doc "Bind to true if you want write to use pretty printing", :added "1.2"}
*print-pretty* true)
-(defonce ; If folks have added stuff here, don't overwrite
+(defonce ^:dynamic ; If folks have added stuff here, don't overwrite
^{:doc "The pretty print dispatch function. Use with-pprint-dispatch or set-pprint-dispatch
to modify.",
:added "1.2"}
*print-pprint-dispatch* nil)
-(def
+(def ^:dynamic
^{:doc "Pretty printing will try to avoid anything going beyond this column.
Set it to nil to have pprint let the line be arbitrarily long. This will ignore all
non-mandatory newlines.",
:added "1.2"}
*print-right-margin* 72)
-(def
+(def ^:dynamic
^{:doc "The column at which to enter miser style. Depending on the dispatch table,
miser style add newlines in more places to try to keep lines short allowing for further
levels of nesting.",
:added "1.2"}
*print-miser-width* 40)
;;; TODO implement output limiting
-(def
+(def ^:dynamic
^{:private true,
:doc "Maximum number of lines to print in a pretty print instance (N.B. This is not yet used)"}
*print-lines* nil)
;;; TODO: implement circle and shared
-(def
+(def ^:dynamic
^{:private true,
:doc "Mark circular structures (N.B. This is not yet used)"}
*print-circle* nil)
;;; TODO: should we just use *print-dup* here?
-(def
+(def ^:dynamic
^{:private true,
:doc "Mark repeated structures rather than repeat them (N.B. This is not yet used)"}
*print-shared* nil)
-(def
+(def ^:dynamic
^{:doc "Don't print namespaces with symbols. This is particularly useful when
pretty printing the results of macro expansions"
:added "1.2"}
*print-suppress-namespaces* nil)
;;; TODO: support print-base and print-radix in cl-format
;;; TODO: support print-base and print-radix in rationals
-(def
+(def ^:dynamic
^{:doc "Print a radix specifier in front of integers and rationals. If *print-base* is 2, 8,
or 16, then the radix specifier used is #b, #o, or #x, respectively. Otherwise the
radix specifier is in the form #XXr where XX is the decimal value of *print-base* "
:added "1.2"}
*print-radix* nil)
-(def
+(def ^:dynamic
^{:doc "The base to use for printing integers and rationals."
:added "1.2"}
*print-base* 10)
@@ -96,9 +96,9 @@ radix specifier is in the form #XXr where XX is the decimal value of *print-base
;; structure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(def ^{ :private true } *current-level* 0)
+(def ^:dynamic ^{ :private true } *current-level* 0)
-(def ^{ :private true } *current-length* nil)
+(def ^:dynamic ^{ :private true } *current-length* nil)
;; TODO: add variables for length, lines.
View
@@ -236,14 +236,14 @@
;;; USER-MODIFIABLE GLOBALS
-(defonce
+(defonce ^:dynamic
^{:doc "True by default. If set to false, no test functions will
be created by deftest, set-test, or with-test. Use this to omit
tests when compiling or loading production code."
:added "1.1"}
*load-tests* true)
-(def
+(def ^:dynamic
^{:doc "The maximum depth of stack traces to print when an Exception
is thrown during a test. Defaults to nil, which means print the
complete stack trace."
@@ -253,16 +253,16 @@
;;; GLOBALS USED BY THE REPORTING FUNCTIONS
-(def *report-counters* nil) ; bound to a ref of a map in test-ns
+(def ^:dynamic *report-counters* nil) ; bound to a ref of a map in test-ns
-(def *initial-report-counters* ; used to initialize *report-counters*
+(def ^:dynamic *initial-report-counters* ; used to initialize *report-counters*
{:test 0, :pass 0, :fail 0, :error 0})
-(def *testing-vars* (list)) ; bound to hierarchy of vars being tested
+(def ^:dynamic *testing-vars* (list)) ; bound to hierarchy of vars being tested
-(def *testing-contexts* (list)) ; bound to hierarchy of "testing" strings
+(def ^:dynamic *testing-contexts* (list)) ; bound to hierarchy of "testing" strings
-(def *test-out* *out*) ; PrintWriter for test reporting output
+(def ^:dynamic *test-out* *out*) ; PrintWriter for test reporting output
(defmacro with-test-out
"Runs body with *out* bound to the value of *test-out*."
@@ -45,8 +45,8 @@
(defn- escape-xml [text]
(apply str (map #(escape-xml-map % %) text)))
-(def *var-context*)
-(def *depth*)
+(def ^:dynamic *var-context*)
+(def ^:dynamic *depth*)
(defn indent
[]
View
@@ -12,10 +12,10 @@
(:import (org.xml.sax ContentHandler Attributes SAXException)
(javax.xml.parsers SAXParser SAXParserFactory)))
-(def *stack*)
-(def *current*)
-(def *state*) ; :element :chars :between
-(def *sb*)
+(def ^:dynamic *stack*)
+(def ^:dynamic *current*)
+(def ^:dynamic *state*) ; :element :chars :between
+(def ^:dynamic *sb*)
(defstruct element :tag :attrs :content)
Oops, something went wrong.

0 comments on commit b9b1a09

Please sign in to comment.