Back
nil? (clj)
(source)function
(nil? x)
Returns true if x is nil, false otherwise.
Examples
clojure
(deftest division
(is (= clojure.core// /))
(binding [*ns* *ns*]
(eval '(do (ns foo
(:require [clojure.core :as bar])
(:use [clojure.test]))
(is (= clojure.core// bar//))))))
(deftest reader-conditionals
(testing "basic read-cond"
(is (= '[foo-form]
(read-string {:read-cond :allow :features #{:foo}} "[#?(:foo foo-form :bar bar-form)]")))
(is (= '[bar-form]
(read-string {:read-cond :allow :features #{:bar}} "[#?(:foo foo-form :bar bar-form)]")))
(is (= '[foo-form]
(read-string {:read-cond :allow :features #{:foo :bar}} "[#?(:foo foo-form :bar bar-form)]")))
(is (= '[]
(read-string {:read-cond :allow :features #{:baz}} "[#?( :foo foo-form :bar bar-form)]"))))
(testing "environmental features"
(is (= "clojure" #?(:clj "clojure" :cljs "clojurescript" :default "default"))))
(testing "default features"
(is (= "default" #?(:clj-clr "clr" :cljs "cljs" :default "default"))))
(testing "splicing"
(is (= [] [#?@(:clj [])]))
(is (= [:a] [#?@(:clj [:a])]))
(is (= [:a :b] [#?@(:clj [:a :b])]))
(is (= [:a :b :c] [#?@(:clj [:a :b :c])]))
(is (= [:a :b :c] [#?@(:clj [:a :b :c])])))
(testing "nested splicing"
(is (= [:a :b :c :d :e]
[#?@(:clj [:a #?@(:clj [:b #?@(:clj [:c]) :d]):e])]))
(is (= '(+ 1 (+ 2 3))
'(+ #?@(:clj [1 (+ #?@(:clj [2 3]))]))))
(is (= '(+ (+ 2 3) 1)
'(+ #?@(:clj [(+ #?@(:clj [2 3])) 1]))))
(is (= [:a [:b [:c] :d] :e]
[#?@(:clj [:a [#?@(:clj [:b #?@(:clj [[:c]]) :d])] :e])])))
(testing "bypass unknown tagged literals"
(is (= [1 2 3] #?(:cljs #js [1 2 3] :clj [1 2 3])))
(is (= :clojure #?(:foo #some.nonexistent.Record {:x 1} :clj :clojure))))
(testing "error cases"
(is (thrown-with-msg? RuntimeException #"Feature should be a keyword" (read-string {:read-cond :allow} "#?((+ 1 2) :a)")))
(is (thrown-with-msg? RuntimeException #"even number of forms" (read-string {:read-cond :allow} "#?(:cljs :a :clj)")))
(is (thrown-with-msg? RuntimeException #"read-cond-splicing must implement" (read-string {:read-cond :allow} "#?@(:clj :a)")))
(is (thrown-with-msg? RuntimeException #"is reserved" (read-string {:read-cond :allow} "#?@(:foo :a :else :b)")))
(is (thrown-with-msg? RuntimeException #"must be a list" (read-string {:read-cond :allow} "#?[:foo :a :else :b]")))
(is (thrown-with-msg? RuntimeException #"Conditional read not allowed" (read-string {:read-cond :BOGUS} "#?[:clj :a :default nil]")))
(is (thrown-with-msg? RuntimeException #"Conditional read not allowed" (read-string "#?[:clj :a :default nil]")))
(is (thrown-with-msg? RuntimeException #"Reader conditional splicing not allowed at the top level" (read-string {:read-cond :allow} "#?@(:clj [1 2])")))
(is (thrown-with-msg? RuntimeException #"Reader conditional splicing not allowed at the top level" (read-string {:read-cond :allow} "#?@(:clj [1])")))
(is (thrown-with-msg? RuntimeException #"Reader conditional splicing not allowed at the top level" (read-string {:read-cond :allow} "#?@(:clj []) 1"))))
(testing "clj-1698-regression"
(let [opts {:features #{:clj} :read-cond :allow}]
(is (= 1 (read-string opts "#?(:cljs {'a 1 'b 2} :clj 1)")))
(is (= 1 (read-string opts "#?(:cljs (let [{{b :b} :a {d :d} :c} {}]) :clj 1)")))
(is (= '(def m {}) (read-string opts "(def m #?(:cljs ^{:a :b} {} :clj ^{:a :b} {}))")))
(is (= '(def m {}) (read-string opts "(def m #?(:cljs ^{:a :b} {} :clj ^{:a :b} {}))")))
(is (= 1 (read-string opts "#?(:cljs {:a #_:b :c} :clj 1)")))))
(testing "nil expressions"
(is (nil? #?(:default nil)))
(is (nil? #?(:foo :bar :clj nil)))
(is (nil? #?(:clj nil :foo :bar)))
(is (nil? #?(:foo :bar :default nil)))))
clj-commons/manifold
(ns manifold.stream.async
{:no-doc true}
(:require
[manifold.deferred :as d]
[clojure.core.async :as a]
[manifold.stream
[graph :as g]
[core :as s]]
[manifold
[executor :as executor]
[utils :as utils]])
(:import
[java.util.concurrent.atomic
AtomicReference]))
(let [x (a/<!! ch)]
(if (nil? x)
(do
(.markDrained this)
default-val)
x))
(let [d (d/deferred)
d' (.getAndSet last-take d)
f (fn [_]
(a/take! ch
(fn [msg]
(d/success! d
(if (nil? msg)
(do
(.markDrained this)
default-val)
msg)))))]
(if (d/realized? d')
(f nil)
(d/on-realized d' f f))
d)))
;; if I don't take this out of the goroutine, core.async OOMs on compilation
mark-drained #(.markDrained this)
f (fn [_]
(a/go
(let [result (a/alt!
ch ([x] (if (nil? x)
(do
(mark-drained)
default-val)
x))
(a/timeout timeout) timeout-val
:priority true)]
(d/success! d result))))]
(if (d/realized? d')
(f nil)
(d/on-realized d' f f))
(if blocking?
@d
d))))
(assert (not (nil? x)) "core.async channel cannot take `nil` as a message")
(if (nil? timeout)
(.put this x blocking?)
(assert (not (nil? x)) "core.async channel cannot take `nil` as a message"))
hraberg/deuce
(ns deuce.emacs.chartab
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c]
[deuce.emacs.alloc :as alloc]
[deuce.emacs.data :as data]
[deuce.emacs.fns :as fns])
(:import [deuce.emacs.data CharTable]
[java.util Arrays])
(:refer-clojure :exclude []))
(defun set-char-table-range (char-table range value)
"Set the value in CHAR-TABLE for a range of characters RANGE to VALUE.
RANGE should be t (for all characters), nil (for the default value),
a cons of character codes (for characters in the range),
or a character code. Return VALUE."
(let [[start end] (if (data/consp range)
[(int (data/car range)) (int (data/cdr range))]
[0 (count (.contents ^CharTable char-table))])]
(Arrays/fill ^objects (.contents ^CharTable char-table) (int start) (int end)
(if (nil? range) (.defalt ^CharTable char-table) value)))
value)
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]))
(defun error-message-string (obj)
"Convert an error value (ERROR-SYMBOL . DATA) to an error message.
See Info anchor `(elisp)Definition of signal' for some details on how this
error message is constructed."
(let [error-symbol (data/car obj)
data (data/cdr obj)]
(str (or (fns/get error-symbol 'error-message)
(s/capitalize (s/join " " (s/split (str error-symbol) #"-"))))
(when (and (data/listp data) (not (nil? data)))
(str ": " (s/join ", " (map pr-str data)))))))
hraberg/deuce
(ns deuce.emacs.coding
(:use [deuce.emacs-lisp :only (defun defvar) :as el])
(:require [clojure.core :as c]
[deuce.emacs.alloc :as alloc]
[deuce.emacs.charset :as charset]
[deuce.emacs.fns :as fns]
[deuce.emacs-lisp.globals :as globals])
(:refer-clojure :exclude []))
(defun check-coding-system (coding-system)
"Check validity of CODING-SYSTEM.
If valid, return CODING-SYSTEM, else signal a `coding-system-error' error.
It is valid if it is nil or a symbol defined as a coding system by the
function `define-coding-system'."
(if (nil? coding-system)
coding-system
(el/throw 'coding-system-error coding-system)))
liquidz/merr
(ns merr.spec
(:require
[clojure.core.specs.alpha :as c.s]
[clojure.spec.alpha :as s]
[merr.core :as core]))
(s/def ::merr-error (partial instance? merr.core.MerrError))
(s/def ::type some?)
(s/def ::message (s/or :string string? :none nil?))
(s/def ::data any?)
(s/def ::cause any?)
(s/def ::error-map (s/keys :opt-un [::type ::message ::data ::cause]))
(s/fdef core/assert
:args (s/cat :pred any?
:m map?)
:ret (s/or :err ::merr-error
:none nil?))