Back
ensure (clj)
(source)function
(ensure ref)
Must be called in a transaction. Protects the ref from modification
by other transactions. Returns the in-transaction-value of
ref. Allows for more concurrency than (ref-set ref @ref)
Examples
clojure/core.typed
(ns clojure.core.typed.test.load-test
(:require [clojure.core.typed.load :as load]
[clojure.test :refer :all]))
;; ensures evaluation occurs
(deftest evaluation-test
(is (try (load/typed-load1 "clojure/core/typed/test/typed_load/eval")
nil
(catch clojure.lang.ExceptionInfo e
(-> e ex-data :blame :file #{"clojure/core/typed/test/typed_load/eval.clj"})))))
hraberg/deuce
(ns deuce.emacs
(:require [clojure.core :as c]
[deuce.emacs-lisp :as el]
[deuce.emacs-lisp.globals :as globals])
(:refer-clojure :only [])
(:use [deuce.emacs-lisp :only [and apply-partially catch cond condition-case defconst define-compiler-macro defmacro
defun defvar function if interactive lambda let let* or prog1 prog2 progn quote
save-current-buffer save-excursion save-restriction setq setq-default
unwind-protect while throw]]
[deuce.emacs.alloc]
[deuce.emacs.buffer]
[deuce.emacs.bytecode]
[deuce.emacs.callint]
[deuce.emacs.callproc]
[deuce.emacs.casefiddle]
[deuce.emacs.casetab]
[deuce.emacs.category]
[deuce.emacs.ccl]
[deuce.emacs.character]
[deuce.emacs.charset]
[deuce.emacs.chartab]
[deuce.emacs.cmds]
[deuce.emacs.coding]
[deuce.emacs.composite]
[deuce.emacs.data]
[deuce.emacs.dired]
[deuce.emacs.dispnew]
[deuce.emacs.doc]
[deuce.emacs.editfns]
[deuce.emacs.emacs]
[deuce.emacs.eval]
[deuce.emacs.fileio]
[deuce.emacs.filelock]
[deuce.emacs.floatfns]
[deuce.emacs.fns]
[deuce.emacs.font]
[deuce.emacs.frame]
[deuce.emacs.indent]
[deuce.emacs.insdel]
[deuce.emacs.keyboard]
[deuce.emacs.keymap]
[deuce.emacs.lread]
[deuce.emacs.macros]
[deuce.emacs.marker]
[deuce.emacs.menu]
[deuce.emacs.minibuf]
[deuce.emacs.print]
[deuce.emacs.process]
[deuce.emacs.search]
[deuce.emacs.syntax]
[deuce.emacs.term]
[deuce.emacs.terminal]
[deuce.emacs.textprop]
[deuce.emacs.undo]
[deuce.emacs.window]
[deuce.emacs.xdisp]
[deuce.emacs.xfaces]
[deuce.emacs.xml]))
;; Create *Deuce* log buffer first so it won't get selected.
(get-buffer-create "*Deuce*")
;; *Messages* is created by xdisp.c
(get-buffer-create "*Messages*")
;; *scratch* is created by buffer.c
(set-window-buffer (selected-window)
(get-buffer-create "*scratch*"))
;; Minibuffer 0 is the empty one, this is either created by frame.c or minibuffer.c
;; Not the leading space for buffers in the minibuffer window. *Minibuf-1* etc. gets created once it gets activated.
;; You can switch to these buffers in a normal window in Emacs and see them change as they're used.
(set-window-buffer (minibuffer-window)
(get-buffer-create " *Minibuf-0*"))
;; ensure_echo_area_buffers in xdisp.c creates (at least) two echo areas.
(get-buffer-create " *Echo Area 0*")
(get-buffer-create " *Echo Area 1*")
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]))
When you bind `print-continuous-numbering' to t, you should probably
also bind `print-number-table' to nil. This ensures that the value of
`print-number-table' can be garbage-collected once the printing is
done. If all elements of `print-number-table' are nil, it means that
the printing done so far has not found any shared structure or objects
that need to be recorded in the table.")
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))))
cc/reduce (t/All [a c] (t/IFn
;Without accumulator
; default
; (reduce + my-coll)
[[a a :-> (t/U (t/Reduced a) a)] (t/NonEmptySeqable a) :-> a]
[(t/IFn [a a :-> (t/U (t/Reduced a) a)] [:-> a]) (t/Seqable a) :-> a]
; default
; (reduce + 3 my-coll)
; (reduce (fn [a b] a) (reduced 1) nil)
; ;=> (reduced 1)
[[a c :-> (t/U (t/Reduced a) a)] a (t/Seqable c) :-> a]))
cc/transduce (t/All [a b c] (t/IFn [(t/Transducer a a) (t/Reducer a a) (t/Seqable a) :-> a]
[(t/Transducer b c) (t/IFn [c :-> c] [c a :-> (t/U c (t/Reduced c))]) a (t/Seqable b) :-> a]))
cc/reduce-kv (t/All [a k v] [[a k v :-> (t/U (t/Reduced a) a)] a (t/Option (t/Associative k v)) :-> a])
cc/reductions (t/All [a b] (t/IFn [[a a :-> (t/U (t/Reduced a) a)] (t/NonEmptySeqable a) :-> (t/NonEmptyASeq a)]
[(t/IFn [:-> a] [a a :-> (t/U (t/Reduced a) a)]) (t/Seqable a) :-> (t/NonEmptyASeq a)]
[[a b :-> (t/U (t/Reduced a) a)] a (t/Seqable b) :-> (t/NonEmptyASeq a)]))
cc/reduced (t/All [x] [x :-> (t/Reduced x)])
cc/unreduced (t/All [x] (t/IFn [(t/Reduced x) :-> x]
[(t/U x (t/Reduced x)) :-> x]))
cc/ensure-reduced (t/All [x] [(t/U x (t/Reduced x)) :-> (t/Reduced x)])
cc/completing (t/All [a b] [(t/IFn [:-> b] [b a :-> (t/U b (t/Reduced b))])
[b :-> b]
:-> (t/Reducer a b)])
typedclojure/typedclojure
(ns ^:no-doc typed-test.clj.ext.clojure.core__let
(:require [clojure.test :refer [deftest is testing]]
[clojure.core.typed :as t]
[typed.clj.checker.parse-unparse :as prs]
[typed.clj.checker.test-utils :refer :all]))
(deftest let-tag-test
(is-tc-e (let [a "a"]
(.startsWith a "b")))
(is-tc-e (let [a (let [foo 1] "a")]
(.startsWith a "b")))
;; ensure inferred :tag is not propagated to final expansion.
;; this would otherwise fail to expand, complaining about primitive
;; type hints on locals.
(is-tc-e (let [foo 1])))