Public Vars

Back

defonce (clj)

(source)

macro

(defonce name expr)
defs name to have the root value of the expr iff the named var has no root value, else expr is unevaluated

Examples

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]))

;; We `defonce` an atom and tag it with `^::clerk/sync`. This will create a corresponding (reagent) atom in the browser.
^{::clerk/sync true}
(defonce number-atom
  (atom 0))

^::clerk/sync
(defonce name-atom
  (atom "Sam Gold"))


^{::clerk/viewer convenient-slider ::clerk/sync true}
(defonce number-atom-2 (atom 99))
clojure/core.typed
(ns clojure.core.typed.checker.def-utils
  (:refer-clojure :exclude [defrecord defprotocol definterface])
  (:require [clojure.core :as core]))

(defmacro defprotocol [name & args]
  ;only define protocol if symbol doesn't resolve, not completely sure if this behaves like defonce
  (when-not (resolve name)
    `(core/defprotocol ~name ~@args)))
clojure/core.typed
(ns clojure.core.typed.checker.check.multi-utils
  (:require [clojure.core.typed.contract-utils :as con]
            [clojure.core.typed.checker.type-rep :as r]))

(defonce ^:dynamic *current-mm* nil)
(set-validator! #'*current-mm* (some-fn nil? 
                                        (con/hmap-c? :dispatch-fn-type r/Type?
                                                     :dispatch-val-ret r/TCResult?)))
clojure/core.typed
(ns ^:skip-wiki clojure.core.typed.checker.check.recur-utils
  (:require [clojure.core.typed.checker.utils :as u]
            [clojure.core.typed.checker.type-rep :as r]))

(defonce ^:dynamic *recur-target* nil)
(set-validator-doc! #'*recur-target* (some-fn nil? RecurTarget?))

(defonce ^:dynamic *loop-bnd-anns* nil)
(set-validator! #'*loop-bnd-anns* #(or (nil? %)
                                       (every? r/Type? %)))
typedclojure/typedclojure
(ns typed.cljc.checker.check.multi-utils
  (:require [clojure.core.typed.contract-utils :as con]
            [typed.cljc.checker.type-rep :as r]))

(defonce ^:dynamic *current-mm* nil)
(set-validator! #'*current-mm* (some-fn nil? 
                                        (con/hmap-c? :dispatch-fn-type r/Type?
                                                     :dispatch-val-ret r/TCResult?)))