Public Vars

Back

keyword (clj)

(source)

function

(keyword name) (keyword ns name)
Returns a Keyword with the given namespace and name. Do not use : in the keyword strings, it will be added automatically.

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)))))
pedestal/pedestal
(ns io.pedestal.interceptor.error
  (:require [io.pedestal.interceptor :as interceptor]
            [clojure.core.match :as match]))

  `:exception-type` is a keyword of the exception's type, for example,
  `:java.lang.ArithmeticException
  "
  [binding-vector & match-forms]
  `(io.pedestal.interceptor/interceptor
     {:error (fn ~binding-vector
               (clojure.core.match/match [(ex-data ~(second binding-vector))]
                  ~@match-forms))}))
clojure/core.typed
(ns ^:skip-wiki clojure.core.typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  (:require [#?(:clj clojure.core.typed
                :cljs cljs.core.typed)
             :refer [defalias] :as t]))

(defalias
  ^{:doc "A keyword"
    :forms '[Keyword]}
  t/Keyword
  #?(:clj clojure.lang.Keyword
     :cljs cljs.core/Keyword))

(defalias
  ^{:doc "A keyword"
    :forms '[Kw]}
  t/Kw
  t/Keyword)
cognitect-labs/aws-api
(ns dynamodb-examples
  (:require [clojure.core.async :as a]
            [clojure.java.io :as io]
            [clojure.data.json :as json]
            [cognitect.aws.client.api :as aws]))

  (let [ ;; The aws-supplied example data are all json. We can use them
        ;; as/is, but we need keys defined the input specs to be
        ;; keywords if we want to validate the structure first!
        xform-specified-keys
        (fn [k]
          (get (reduce (fn [a v] (assoc a v (keyword v)))
                       {}
                       ["B" "BOOL" "BS" "Item" "L" "M" "N" "NS" "NULL" "PutRequest" "S" "SS"])
               k
               k))]
    (->> ["Forum.json"
          "Reply.json"
          "Thread.json"]
         (map #(-> (io/file "examples" "resources" "dynamodb" %)
                   slurp
                   (json/read-str :key-fn xform-specified-keys)))
         (map #(aws/invoke ddb {:op      :BatchWriteItem
                                :request {:RequestItems %}}))))
hraberg/deuce
(ns deuce.emacs.xfaces
  (:use [deuce.emacs-lisp :only (defun defvar)])
  (:require [clojure.core :as c])
  (:refer-clojure :exclude []))

(defun internal-get-lisp-face-attribute (symbol keyword &optional frame)
  "Return face attribute KEYWORD of face SYMBOL.
  If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
  face attribute name, signal an error.
  If the optional argument FRAME is given, report on face SYMBOL in that
  frame.  If FRAME is t, report on the defaults for face SYMBOL (for new
  frames).  If FRAME is omitted or nil, use the selected frame."
  )
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))))

(t/defalias
  ^{:doc "A keyword"
    :forms '[Keyword]}
  t/Keyword
  #?(:clj clojure.lang.Keyword
     :cljs cljs.core/Keyword))

(t/defalias
  ^{:doc "A keyword"
    :forms '[Kw]}
  t/Kw
  t/Keyword)

cc/keyword
(t/IFn [(t/U t/Keyword t/Sym t/Str) :-> t/Keyword 
        :object {:id 0 :path [Keyword]}
        :filters {:then tt
                  :else ff}]
       [nil :-> nil 
        :object {:id 0 :path [Keyword]}
        :filters {:then ff
                  :else tt}]
       [t/Any :-> (t/U nil t/Keyword) 
        :object {:id 0 :path [Keyword]}
        :filters {:then (is (t/U t/Keyword t/Sym t/Str) 0)
                  :else (! (t/U t/Keyword t/Sym t/Str) 0)}]
       [(t/Option t/Str) t/Str :-> t/Keyword
        :filters {:then tt
                  :else ff}])

#?@(:cljs [] :default [
cc/find-keyword
[(t/alt (t/cat (t/U t/Keyword t/Sym t/Str))
        (t/cat t/Str t/Str))
 :-> (t/Option t/Keyword)]
])

cc/seq? (t/Pred (t/Seq t/Any))
cc/set? (t/Pred (t/Set t/Any))
cc/vector? (t/Pred (t/Vec t/Any))
cc/nil? (t/Pred nil)
#?@(:cljs [
cc/undefined? (t/Pred t/JSundefined)
])
cc/false? (t/Pred false)
cc/true? (t/Pred true)
cc/symbol? (t/Pred t/Sym)
cc/keyword? (t/Pred t/Keyword)
cc/map? (t/Pred (t/Map t/Any t/Any))
cc/boolean? (t/Pred t/Bool)
cc/any? [t/Any :-> true]
cc/record? (t/Pred #?(:clj clojure.lang.IRecord
                      :cljs cljs.core/IRecord))

#?@(: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]
])

clojure.walk/keywordize-keys [t/Any :-> t/Any]
clojure.walk/macroexpand-all [t/Any :-> t/Any]
clojure.walk/postwalk [[t/Any :-> t/Any] t/Any :-> t/Any]
clojure.walk/postwalk-demo [t/Any :-> t/Any]
clojure.walk/postwalk-replace [(t/Map t/Any t/Any) t/Any :-> t/Any]
clojure.walk/prewalk [[t/Any :-> t/Any] t/Any :-> t/Any]
clojure.walk/prewalk-demo [t/Any :-> t/Any]
clojure.walk/prewalk-replace [(t/Map t/Any t/Any) t/Any :-> t/Any]
clojure.walk/stringify-keys [t/Any :-> t/Any]
clojure.walk/walk [[t/Any :-> t/Any] [t/Any :-> t/Any] t/Any :-> t/Any]

; 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/= [(t/+ t/Any) :-> t/Bool]
cc/identical? [t/Any t/Any :-> t/Bool]
#?@(:cljs [
cc/keyword-identical? [t/Any t/Any :-> t/Bool]
])
cc/distinct? [(t/+ t/Any) :-> t/Bool]

cc/integer? (t/Pred t/AnyInteger)
cc/int? (t/Pred #?(:clj (t/U Long
                             Integer
                             Short
                             Byte)
                   :cljs (t/U t/CLJSInteger
                              goog.math.Integer
                              goog.math.Long)))
cc/pos-int? [t/Any :-> t/Bool
             :filters {:then (is #?(:clj (t/U Long
                                              Integer
                                              Short
                                              Byte)
                                    :cljs (t/U t/CLJSInteger
                                               goog.math.Integer
                                               goog.math.Long)) 0)}]
cc/neg-int? [t/Any :-> t/Bool
             :filters {:then (is #?(:clj (t/U Long
                                              Integer
                                              Short
                                              Byte)
                                    :cljs (t/U t/CLJSInteger
                                               goog.math.Integer
                                               goog.math.Long)) 0)}]
cc/nat-int? [t/Any :-> t/Bool
             :filters {:then (is #?(:clj (t/U Long
                                              Integer
                                              Short
                                              Byte)
                                    :cljs (t/U t/CLJSInteger
                                               goog.math.Integer
                                               goog.math.Long)) 0)}]
cc/number? (t/Pred t/Num)
cc/double? (t/Pred #?(:clj Double
                      :cljs t/Num))
cc/float? (t/Pred #?(:clj (t/U Double Float)
                     :cljs t/Num))
cc/ident? (t/Pred t/Ident)
cc/simple-ident? [t/Any :-> t/Bool :filters {:then (is t/Ident 0)}]
cc/qualified-ident? [t/Any :-> t/Bool :filters {:then (is t/Ident 0)}]
cc/simple-symbol? [t/Any :-> t/Bool :filters {:then (is t/Sym 0)}]
cc/qualified-symbol? [t/Any :-> t/Bool :filters {:then (is t/Sym 0)}]
cc/simple-keyword? [t/Any :-> t/Bool :filters {:then (is t/Kw 0)}]
cc/qualified-keyword? [t/Any :-> t/Bool :filters {:then (is t/Kw 0)}]
cc/var? (t/Pred t/AnyVar)