Back
ref (clj)
(source)function
(ref x)
(ref x & options)
Creates and returns a Ref with an initial value of x and zero or
more options (in any order):
:meta metadata-map
:validator validate-fn
:min-history (default 0)
:max-history (default 10)
If metadata-map is supplied, it will become the metadata on the
ref. validate-fn must be nil or a side-effect-free fn of one
argument, which will be passed the intended new state on any state
change. If the new state is unacceptable, the validate-fn should
return false or throw an exception. validate-fn will be called on
transaction commit, when all refs have their final values.
Normally refs accumulate history dynamically as needed to deal with
read demands. If you know in advance you will need history you can
set :min-history to ensure it will be available when first needed (instead
of after a read fault). History is limited, and the limit can be set
with :max-history.
Examples
clojure
(ns clojure.test-clojure.reducers
(:require [clojure.core.reducers :as r]
[clojure.test.generative :refer (defspec)]
[clojure.data.generators :as gen])
(:use clojure.test))
(deftest test-closed-over-clearing
;; this will throw OutOfMemory without proper reference clearing
(is (number? (reduce + 0 (r/map identity (range 1e8))))))
nextjournal/clerk
(ns viewers.controls
"Demo of Clerk's two-way bindings."
{:nextjournal.clerk/visibility {:code :show :result :show}}
(:require [clojure.core :as core]
[nextjournal.clerk :as clerk]
[nextjournal.clerk.viewer :as viewer]))
^{::clerk/viewer {:render-fn (list 'comp render-slider 'deref) :transform-fn transform-var}}
#'number-atom
^{::clerk/viewer {:render-fn (list 'comp render-text-input 'deref) :transform-fn transform-var}}
#'name-atom
^{::clerk/viewers (clerk/add-viewers [(assoc var-viewer :render-fn (list 'comp render-text-input 'deref))])}
#'name-atom
(def convenient-slider
{:transform-fn (comp transform-var (clerk/update-val #(cond-> % (viewer/get-safe % ::clerk/var-from-def) ::clerk/var-from-def)))
:render-fn '(fn [x] (let [state-atom (cond-> x (var? x) deref)]
[:input {:type :range :value @state-atom :on-change #(swap! state-atom (constantly (int (.. % -target -value))))}]))})
jonase/eastwood
(ns testcases.unusednss3
(:require [clojure.core.protocols :as protocols]
[clojure.core.reducers :as reducers]
[clojure.data :as data]
[clojure.java.io :as io]
[clojure.reflect :as reflect]))
(deftype Bar [whatever]
reflect/Reflector
(do-reflect [reflector typeref] nil))
hraberg/deuce
(ns deuce.emacs.print
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c]
[clojure.string :as s]
[deuce.emacs.buffer :as buffer]
[deuce.emacs.data :as data]
[deuce.emacs.editfns :as editfns]
[deuce.emacs.fns :as fns])
(:refer-clojure :exclude [print]))
(defvar print-gensym nil
"Non-nil means print uninterned symbols so they will read as uninterned.
I.e., the value of (make-symbol \"foobar\") prints as #:foobar.
When the uninterned symbol appears within a recursive data structure,
and the symbol appears more than once, in addition use the #N# and #N=
constructs as needed, so that multiple references to the same symbol are
shared once again when the text is read back.")
(defvar print-continuous-numbering nil
"*Non-nil means number continuously across print calls.
This affects the numbers printed for #N= labels and #M# references.
See also `print-circle', `print-gensym', and `print-number-table'.
This variable should not be set with `setq'; bind it with a `let' instead.")
(defvar print-number-table nil
"A vector used internally to produce `#N=' labels and `#N#' references.
The Lisp printer uses this vector to detect Lisp objects referenced more
than once.
(defun redirect-debugging-output (file &optional append)
"Redirect debugging output (stderr stream) to file FILE.
If FILE is nil, reset target to the initial stderr stream.
Optional arg APPEND non-nil (interactively, with prefix arg) means
append to existing target file."
)
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
#?(:cljs (do
(t/ann-protocol cljs.core/Fn)
(t/ann-protocol cljs.core/IFn)
(t/ann-protocol cljs.core/ICloneable
-clone [cljs.core/ICloneable :-> t/Any])
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IIterable
;; TODO
-iterator [(cljs.core/IIterable x) :-> t/Any #_Object])
(t/ann-protocol cljs.core/ICounted
-count [cljs.core/ICounted :-> t/Num])
(t/ann-protocol cljs.core/IEmptyableCollection
;; :/ TFn param on protocol?
-empty [cljs.core/IEmptyableCollection :-> t/Any])
(t/ann-protocol cljs.core/ICollection
-conj [cljs.core/ICollection t/Any :-> cljs.core/ICollection])
(t/ann-protocol [[x :variance :covariant]] cljs.core/IIndexed
-nth (t/All [y]
[(cljs.core/IIndexed x) t/JSnumber (t/? y) :-> (t/U x y)]))
(t/ann-protocol cljs.core/ASeq)
(t/ann-protocol [[x :variance :covariant
;;FIXME causes mystery error
;:< t/AnyNilableNonEmptySeq
]]
cljs.core/ISeqable)
(t/ann-protocol [[x :variance :covariant]] cljs.core/ISeq
-first [(cljs.core/ISeq x) :-> (t/Nilable x)]
-rest [(cljs.core/ISeq x) :-> (cljs.core/ISeq x)])
;cljs.core/INext [[x :variance :covariant]]
(t/ann-protocol [[v :variance :covariant]] cljs.core/ILookup)
(t/ann-protocol [[k :variance :covariant]
[v :variance :covariant]]
cljs.core/IAssociative
-contains-key [(cljs.core/IAssociative k v) t/Any :-> t/Bool]
-assoc (t/All [k1 v1] [(cljs.core/IAssociative k v) k1 v1 :->
(cljs.core/IAssociative (t/U k k1) (t/U v v1))]))
(t/ann-protocol cljs.core/IMap
-dissoc [cljs.core/IMap t/Any :-> cljs.core/IMap])
(t/ann-protocol [[k :variance :covariant]
[v :variance :covariant]]
cljs.core/IMapEntry
-key [(cljs.core/IMapEntry k v) :-> k]
-val [(cljs.core/IMapEntry k v) :-> v])
(t/ann-protocol cljs.core/ISet
-disjoin (t/All [s] [s t/Any :-> s]))
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IStack
-peek [(cljs.core/IStack x) :-> (t/U nil x)]
-pop [(cljs.core/IStack x) :-> (cljs.core/IStack x)])
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IVector
-assoc-n (t/All [x1] [(cljs.core/IVector x) t/Num x1
:-> (cljs.core/IVector (t/U x x1))]))
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IDeref
-deref [(cljs.core/IDeref x) :-> x])
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IDerefWithTimeout
-deref-with-timeout [(cljs.core/IDerefWithTimeout x) :-> x])
(t/ann-protocol cljs.core/IMeta
-meta [cljs.core/IMeta :-> (t/Nilable (t/Map t/Any t/Any))])
(t/ann-protocol cljs.core/IWithMeta
-with-meta [cljs.core/IWithMeta (t/Nilable (t/Map t/Any t/Any)) :-> cljs.core/IWithMeta])
;TODO
;cljs.core/IReduce [[]]
(t/ann-protocol cljs.core/IKVReduce ;;TODO
-kv-reduce [cljs.core/IKVReduce [t/Any t/Any t/Any :-> t/Any] :-> t/Any])
(t/ann-protocol cljs.core/IList)
(t/ann-protocol cljs.core/IEquiv
-equiv [cljs.core/IEquiv t/Any :-> t/Bool])
(t/ann-protocol cljs.core/IHash
-hash [cljs.core/IHash :-> t/Num])
(t/ann-protocol cljs.core/ISequential)
(t/ann-protocol cljs.core/IRecord)
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IReversible
-rseq [(cljs.core/IReversible x) :-> (t/NilableNonEmptySeq x)])
(t/ann-protocol [[k :variance :covariant]
[v :variance :covariant]] cljs.core/IFind
-find [(cljs.core/IFind k v) t/Any :-> (t/Nilable (cljs.core/IMapEntry k v))]
)
(t/ann-protocol [[x :variance :invariant]]
cljs.core/ISorted
-sorted-seq [(cljs.core/ISorted x) t/Bool :-> (t/Nilable (t/ASeq x))]
;; second arg => comparable?
-sorted-seq-from [(cljs.core/ISorted x) t/Any t/Bool :-> (t/Nilable (t/ASeq x))]
-entry-key [(cljs.core/ISorted x) t/Any :-> t/Any]
-comparator [(cljs.core/ISorted x) :-> [x x :-> t/Num]])
(t/ann-protocol cljs.core/IPending)
;cljs.core/IWriter [[]]
;cljs.core/IPrintWithWriter [[]]
; ;TODO
;;cljs.core/IWatchable [[]]
; ;cljs.core/IEditableCollection [[]]
; ;cljs.core/ITransientCollection [[]]
; ;cljs.core/ITransientAssociative [[]]
; ;cljs.core/ITransientMap [[]]
; ;cljs.core/ITransientVector [[]]
; ;cljs.core/ITransientSet [[]]
(t/ann-protocol [[x :variance :invariant]]
cljs.core/IComparable)
; ;cljs.core/IChunk [[]]
; ;cljs.core/IChunkedSeq [[]]
; ;cljs.core/IChunkedNext [[]]
(t/ann-protocol cljs.core/INamed
-named [cljs.core/INamed :-> t/Str]
-namespace [cljs.core/INamed :-> (t/Nilable t/Str)])
(t/ann-protocol [[x :variance :invariant]]
cljs.core/IVolatile
-vreset! (t/All [x] [(cljs.core/IVolatile x) x :-> x]))
(t/defalias
^{:doc "Supertype of all volatiles."
:forms '[AnyVolatile]}
t/AnyVolatile
#?(:clj (t/Instance clojure.lang.Volatile)
:cljs (t/I (cljs.core/IDeref t/Any)
(t/Instance cljs.core/IVolatile)
;;FIXME should just be Volatile
(t/Instance cljs.core/Volatile))))
(t/defalias
^{:doc "A volatile that can read and write type x."
:forms '[(Volatile x)]}
t/Volatile
(t/TFn [[x :variance :invariant]]
#?(:clj (clojure.lang.Volatile x)
:cljs (t/I (cljs.core/IDeref x)
(cljs.core/IVolatile x)
;;FIXME should just be Volatile
(cljs.core/Volatile x)))))
#?(:clj (t/defalias
^{:doc "Supertype of all refs."
:forms '[AnyRef]}
t/AnyRef
(t/Instance clojure.lang.Ref)))
#?(:clj
(t/defalias
^{:doc "A ref that can read and write type x."
:forms '[(Ref x)]}
t/Ref
(t/TFn [[x :variance :invariant]]
(clojure.lang.Ref x))))
#?(:clj
(t/defalias
^{:doc "A ref that can read and write type x."
:deprecated "1.1.6"
:superseded-by `t/Ref
:forms '[(Ref1 x)]}
t/Ref1
t/Ref))
(t/defalias
^{:doc "A Clojure derefable (see clojure.core/deref)."
:forms '[(Deref x)]}
t/Deref
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.IDeref x)
;; note: IDerefWithTimeout not used in cljs
:cljs (cljs.core/IDeref x))))
#?(:clj
(t/defalias
^{:doc "A Clojure future (see clojure.core/{future-call,future})."
:forms '[(Future x)]}
t/Future
(t/TFn [[x :variance :covariant]]
(t/I (t/Deref x)
(clojure.lang.IBlockingDeref x)
clojure.lang.IPending
java.util.concurrent.Future))))
#?(:clj
(t/defalias
^{:doc "A Clojure promise (see clojure.core/{promise,deliver})."
:forms '[(Promise x)]}
t/Promise
(t/TFn [[x :variance :invariant]]
(t/I (t/Deref x)
(clojure.lang.IBlockingDeref x)
clojure.lang.IPending
;; FIXME I think this might be an implementation detail.
[x :-> (t/Nilable (t/Promise x))]))))
(t/defalias
^{:doc "A Clojure blocking derefable (see clojure.core/deref)."
:forms '[(BlockingDeref x)]}
t/BlockingDeref
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.IBlockingDeref x)
:cljs (cljs.core/IDerefWithTimeout x))))
cc/*1 t/Any
cc/*2 t/Any
cc/*3 t/Any
cc/*e #?(:cljs t/Any :default (t/U nil Throwable))
#?@(:cljs [] :default [
cc/*agent* (t/U nil (t/Deref t/Any) #_(t/Agent t/Any))
cc/*allow-unresolved-vars* t/Any
cc/*data-readers* (t/Map t/Sym t/AnyVar)
cc/*default-data-reader-fn* (t/U nil [t/Any t/Any :-> t/Any])
cc/*fn-loader* t/Any
cc/*math-context* t/Any
cc/*source-path* t/Str
cc/*use-context-classloader* t/Any
])
cc/*assert* t/Any
cc/prefer-method [t/Multi t/Any t/Any :-> t/Any]
#?@(:cljs [] :default [
cc/print-simple [t/Any java.io.Writer :-> nil]
cc/char-escape-string (t/Map Character t/Str)
cc/char-name-string (t/Map Character t/Str)
cc/primitives-classnames (t/Map Class t/Str)
cc/namespace-munge [(t/U t/Sym t/Namespace) :-> t/Str]
;cc/find-protocol-impl ['{:on-interface Class
; :impls ?}]
cc/deref (t/All [x #?(:clj y)]
(t/IFn
[(t/Deref x) :-> x]
#?(:clj [(t/U (t/Deref t/Any) java.util.concurrent.Future) :-> t/Any])
#?(:clj [(t/BlockingDeref x) t/AnyInteger y :-> (t/U x y)])
#?(:clj [(t/U java.util.concurrent.Future (t/BlockingDeref t/Any)) t/AnyInteger t/Any :-> t/Any])))
cc/method-sig [java.lang.reflect.Method :-> '[t/Any t/AnyNilableNonEmptySeq t/Any]]
cc/proxy-name [Class (t/Seqable Class) :-> t/Str]
cc/get-proxy-class [Class :* :-> Class]
cc/construct-proxy [Class t/Any :* :-> t/Any]
cc/init-proxy [t/Proxy (t/Map t/Str t/Any) :-> t/Proxy]
cc/update-proxy [t/Proxy (t/Map t/Str t/Any) :-> t/Proxy]
cc/proxy-mappings [t/Proxy :-> (t/Map t/Str t/Any)]
cc/proxy-call-with-super (t/All [x] [[:-> x] t/Proxy t/Str :-> x])
cc/bean [Object :-> (t/Map t/Any t/Any)]
])
cc/associative? (t/Pred (t/Associative t/Any t/Any))
cc/coll? (t/Pred (t/Coll t/Any))
;TODO should these be parameterized?
cc/sequential? (t/Pred t/Sequential)
cc/sorted? (t/Pred (t/Sorted t/Any))
cc/meta [t/Any :-> (t/Nilable (t/Map t/Any t/Any))]
;; FIXME IObj annotations are a hack. doesn't literally return the same reference.
cc/with-meta (t/All [[x :< #?(:clj clojure.lang.IObj
:cljs cljs.core/IWithMeta)]]
[x (t/Nilable (t/Map t/Any t/Any)) :-> x])
cc/vary-meta (t/All [[x :< #?(:clj clojure.lang.IObj
:cljs cljs.core/IWithMeta)] b :..]
[x [(t/Nilable (t/Map t/Any t/Any)) b :.. b :-> (t/Nilable (t/Map t/Any t/Any))] b :.. b :-> x])
#?@(:cljs [] :default [
clojure.java.shell/sh [t/Any :*
;would be nice (combine :* and kw args)
; t/Str :*
;& :optional {:in t/Any ;; any valid input to clojure.java.io/copy
; :inc-enc t/Str :out-env (t/U ':bytes t/Str)
; :env (t/U (Array t/Str) (t/Map t/Any t/Any))
; :dir (t/U t/Str java.io.File)}
:-> '{:exit t/Str
:out (t/U (Array byte) t/Str)
:err t/Str}]
clojure.java.browse/browse-url [t/Any :-> t/Any]
clojure.java.io/delete-file [clojure.java.io/Coercions (t/? t/Any) :-> t/Any]
clojure.java.io/make-parents [(t/+ clojure.java.io/Coercions) :-> t/Any]
clojure.java.io/file [(t/+ clojure.java.io/Coercions) :-> java.io.File]
clojure.java.io/as-relative-path [clojure.java.io/Coercions :-> t/Str]
;; TODO second arg is flattened IOFactoryOpts
clojure.java.io/reader [clojure.java.io/IOFactory :-> java.io.BufferedReader]
;; TODO second arg is flattened IOFactoryOpts
clojure.java.io/writer [clojure.java.io/IOFactory :-> java.io.BufferedWriter]
clojure.java.io/resource [t/Str (t/? ClassLoader) :-> (t/Nilable java.net.URL)]
clojure.stacktrace/e [:-> t/Any]
clojure.stacktrace/print-cause-trace [Throwable :-> t/Any]
clojure.stacktrace/print-stack-trace [Throwable :-> t/Any]
clojure.stacktrace/print-throwable [Throwable :-> t/Any]
clojure.stacktrace/root-cause [Throwable :-> Throwable]
;; FIXME keyword arguments
clojure.reflect/reflect [(t/+ t/Any) :-> (t/Map t/Any t/Any)]
clojure.inspector/atom? [t/Any :-> t/Bool]
clojure.inspector/collection-tag [t/Any :-> t/Keyword]
clojure.inspector/tree-model [t/Any :-> t/Any]
clojure.inspector/old-table-model [t/AnySeqable :-> t/Any]
clojure.inspector/inspect [t/Any :-> javax.swing.JFrame]
clojure.inspector/inspect-tree [t/Any :-> javax.swing.JFrame]
clojure.inspector/inspect-table [t/AnySeqable :-> javax.swing.JFrame]
])
; need better metadata support if this even has a chance of working
; like class
;; idea: provide global registry of :type mappings to qualified keywords.
;; users can register their types to opt in. Add a new path element so we
;; can refine the type if the result is found to be a kw (and if the arg has immutable metadata),
;; eg., cc/type [t/Any :-> t/Any :obj {:id 0 :path [Type]}]
cc/type [t/Any :-> t/Any]
cc/add-watch (t/All [x [a :< (#?(:clj IRef :cljs t/Atom) x)]]
(t/IFn
; this arity remembers the type of reference we pass to the function
[a t/Any [t/Any a x x :-> t/Any] :-> t/Any]
; if the above cannot be inferred,
[(#?(:clj IRef :cljs t/Atom) x) t/Any [t/Any (#?(:clj IRef :cljs t/Atom) x) x x :-> t/Any] :-> t/Any]))
cc/remove-watch (t/All [x] [(#?(:clj IRef :cljs t/Atom) x) t/Any :-> t/Any])
#?@(:cljs [] :default [
cc/ref (t/All [x] [x & :optional {:validator (t/U nil [x :-> t/Any]) :meta (t/U nil (t/Map t/Any t/Any))
:min-history (t/U nil t/AnyInteger)
:max-history (t/U nil t/AnyInteger)}
:-> (t/Ref x)])
])
#?@(:cljs [] :default [
cc/*file* t/Str
])
cc/*command-line-args* (t/NilableNonEmptyASeq t/Str)
#?@(:cljs [
cc/*unchecked-if* t/Bool
cc/*unchecked-arrays* t/Bool
cc/*warn-on-infer* t/Bool
cc/enable-console-print! [:-> t/Any]
] :default [
cc/*warn-on-reflection* t/Bool
cc/*compile-path* t/Str
cc/*compile-files* t/Bool
cc/*unchecked-math* t/Bool
cc/*compiler-options* (t/Map t/Any t/Any)
cc/*in* java.io.Reader
cc/*out* java.io.Writer ;; FIXME cljs
cc/*err* java.io.Writer
cc/*repl* t/Any
])
cc/*flush-on-newline* t/Bool
cc/*print-meta* t/Bool
cc/*print-dup* t/Bool
cc/*print-readably* t/Bool
#?@(:cljs [] :default [
cc/*read-eval* (t/U ':unknown t/Bool)
])
nasa/Common-Metadata-Repository
(ns cmr.client.dev
"The CMR client Clojure REPL development namespace."
(:require
[clojure.core.async :as async]
[clojure.data.json :as json]
[clojure.data.xml :as xml]
[clojure.java.io :as io]
[clojure.pprint :refer [pprint]]
[clojure.string :as string]
[clojure.tools.namespace.repl :as repl]
[cmr.client.ac :as ac]
[cmr.client.common.const :as const]
[cmr.client.common.util :as util]
[cmr.client.http.core :as http]
[cmr.client.ingest :as ingest]
[cmr.client.search :as search]
[cmr.client.testing.runner :as runner]
[cmr.client.tests]
[ltest.core :as ltest]))
(repl/set-refresh-dirs
"src/clj"
"src/cljc"
"dev-resources/src")
(def reload
"An alias for `repl/refresh`"
#'repl/refresh)
(def refresh
"An alias for `repl/refresh`"
#'repl/refresh)
(def reset
"An alias for `repl/refresh`"
#'repl/refresh)