Public Vars

Back

val (clj)

(source)

function

(val e)
Returns the value in the map entry.

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 unknown-tag
  (let [my-unknown (fn [tag val] {:unknown-tag tag :value val})
        throw-on-unknown (fn [tag val] (throw (RuntimeException. (str "No data reader function for tag " tag))))
        my-uuid (partial my-unknown 'uuid)
        u "#uuid \"550e8400-e29b-41d4-a716-446655440000\""
        s "#never.heard.of/some-tag [1 2]" ]
    (binding [*data-readers* {'uuid my-uuid}
              *default-data-reader-fn* my-unknown]
      (testing "Unknown tag"
        (is (= (read-string s)
               {:unknown-tag 'never.heard.of/some-tag
                :value [1 2]})))
      (testing "Override uuid tag"
        (is (= (read-string u)
               {:unknown-tag 'uuid
                :value "550e8400-e29b-41d4-a716-446655440000"}))))

(deftest namespaced-map-errors
  (are [err msg form] (thrown-with-msg? err msg (read-string form))
                      Exception #"Invalid token" "#:::"
                      Exception #"Namespaced map literal must contain an even number of forms" "#:s{1}"
                      Exception #"Namespaced map must specify a valid namespace" "#:s/t{1 2}"
                      Exception #"Unknown auto-resolved namespace alias" "#::BOGUS{1 2}"
                      Exception #"Namespaced map must specify a namespace" "#: s{:a 1}"
                      Exception #"Duplicate key: :user/a" "#::{:a 1 :a 2}"
                      Exception #"Duplicate key: user/a" "#::{a 1 a 2}"))

(deftest invalid-symbol-value
  (is (thrown-with-msg? Exception #"Invalid token" (read-string "##5")))
  (is (thrown-with-msg? Exception #"Invalid token" (edn/read-string "##5")))
  (is (thrown-with-msg? Exception #"Unknown symbolic value" (read-string "##Foo")))
  (is (thrown-with-msg? Exception #"Unknown symbolic value" (edn/read-string "##Foo"))))

  (eval (-> "^{:line 42 :column 99} (defn explicit-line-numbering [])" str->lnpr read))
  (is (= {:line 42 :column 99}
         (-> 'explicit-line-numbering resolve meta (select-keys [:line :column])))))
clojure
(ns clojure.test-clojure.server
    (:import java.util.Random)
    (:require [clojure.test :refer :all])
    (:require [clojure.core.server :as s]))

(defn check-invalid-opts
  [opts msg]
  (try
    (#'clojure.core.server/validate-opts opts)
    (is nil)
    (catch Exception e
      (is (= (ex-data e) opts))
      (is (= msg (.getMessage e))))))

(deftest test-validate-opts
  (check-invalid-opts {} "Missing required socket server property :name")
  (check-invalid-opts {:name "a" :accept 'clojure.core/+} "Missing required socket server property :port")
  (doseq [port [-1 "5" 999999]]
    (check-invalid-opts {:name "a" :port port :accept 'clojure.core/+} (str "Invalid socket server port: " port)))
  (check-invalid-opts {:name "a" :port 5555} "Missing required socket server property :accept"))
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))

(defmacro defequivtest
  ;; f is the core fn, r is the reducers equivalent, rt is the reducible ->
  ;; coll transformer
  [name [f r rt] fns]
  `(deftest ~name
     (let [c# (range -100 1000)]
       (doseq [fn# ~fns]
         (is (= (~f fn# c#)
                (~rt (~r fn# c#))))))))
logseq/logseq
(ns frontend.pubsub
  "All mults and pubs are collected to this ns.
  vars with suffix '-mult' is a/Mult, use a/tap and a/untap on them. used by event subscribers
  vars with suffix '-pub' is a/Pub, use a/sub and a/unsub on them. used by event subscribers
  vars with suffix '-ch' is chan used by event publishers."
  {:clj-kondo/config {:linters {:unresolved-symbol {:level :off}}}}
  #?(:cljs (:require-macros [frontend.pubsub :refer [def-mult-or-pub chan-of]]))
  (:require [clojure.core.async :as a :refer [chan mult pub]]
            [clojure.core.async.impl.protocols :as ap]
            [malli.core :as m]
            [malli.dev.pretty :as mdp]
            [clojure.pprint :as pp]))

;;; helper macro
(defmacro chan-of [malli-schema malli-schema-validator & chan-args]
  `(let [ch# (chan ~@chan-args)]
     (reify
       ap/ReadPort
       (~'take! [~'_ fn1-handler#]
        (ap/take! ch# fn1-handler#))
       ap/WritePort
       (~'put! [~'_ val# fn1-handler#]
        (if (~malli-schema-validator val#)
          (ap/put! ch# val# fn1-handler#)
          (do (mdp/explain ~malli-schema val#)
              (throw (ex-info "validate chan value failed" {:val val#}))))))))

(defmacro def-mult-or-pub
  "define following vars:
  - `symbol-name`-ch for event publisher.
  - `symbol-name`-mult or `symbol-name`-pub for event subscribers.
  - `symbol-name`-validator is malli schema validator
  def -pub var when `:topic-fn` exists otherwise -mult var"
  [symbol-name doc-string malli-schema & {:keys [ch-buffer topic-fn]
                                          :or   {ch-buffer 1}}]
  (let [schema-validator-name (symbol (str symbol-name "-validator"))
        schema-name           (symbol (str symbol-name "-schema"))
        ch-name               (symbol (str symbol-name "-ch"))
        mult-or-pub-name      (if topic-fn
                                (symbol (str symbol-name "-pub"))
                                (symbol (str symbol-name "-mult")))
        doc-string*           (str doc-string "\nMalli-schema:\n" (with-out-str (pp/pprint malli-schema)))]
    `(do
       (def ~schema-name ~malli-schema)
       (def ~schema-validator-name (m/validator ~malli-schema))
       (def ~ch-name ~doc-string* (chan-of ~malli-schema ~schema-validator-name ~ch-buffer))
       ~(if topic-fn
          `(def ~mult-or-pub-name ~doc-string* (pub ~ch-name ~topic-fn))
          `(def ~mult-or-pub-name ~doc-string* (mult ~ch-name))))))
babashka/babashka
(ns babashka.impl.match
  {:no-doc true}
  (:require [clojure.core.match :as match]
            clojure.core.match.array ;; side effecting
            clojure.core.match.debug ;; side effecting
            clojure.core.match.protocols ;; side effecting
            clojure.core.match.regex ;; side effecting
            [sci.core :as sci :refer [copy-var]]))

(def core-match-namespace
  {'match (copy-var match/match mns)
   'backtrack (copy-var match/backtrack mns)
   'val-at*   (copy-var match/val-at* mns)
   'defpred   (copy-var match/defpred mns)})
dundalek/closh
(defmacro def-eval []
  (if (System/getenv "__CLOSH_USE_SCI_EVAL__")
    `(do (require 'closh.zero.utils.sci)
         (def ~'eval closh.zero.utils.sci/sci-eval))
    `(def ~'eval clojure.core/eval)))

(def-eval)

(defmacro eval-closh-requires []
  (when-not (System/getenv "__CLOSH_USE_SCI_EVAL__")
    `(eval closh.zero.env/*closh-environment-requires*)))
originrose/cortex
(ns cortex.nn.impl
  "Implementation helpers to aid implementing neural network cortex protocols
or specific neural network layers"
  (:require [cortex.nn.layers :as layers]
            [clojure.core.matrix.macros :refer [c-for]]))


(defmacro in-bounds?
  "is value within the range of [min-val, max-val)"
  [value min-val max-val]
  `(and (>= ~value ~min-val)
        (< ~value ~max-val)))


(defmacro convolution-roll-unroll-inner-kernel
  [& body]
  `(let [~'chan-conv-offset (* ~'chan ~'output-channel-stride)
         ~'output-offset (+ (* ~'out-y ~'output-width)
                            ~'out-x)
         ;;positive values for how far out we are into the padding
         input-over-x# (max 0 (- (+ ~'input-rel-x ~'kernel-width)
                                 ~'input-width))
         input-over-y# (max 0 (- (+ ~'input-rel-y ~'kernel-height)
                                 ~'input-height))
         ;;Negative values for how far before the 0 idx we are.
         input-under-x# (min ~'input-rel-x 0)
         input-under-y# (min ~'input-rel-y 0)
         ;;Width of the kernel excluding padding
         ~'exc-pad-width (max 0 (+ (- ~'kernel-width input-over-x#)
                                   input-under-x#))
         ~'exc-pad-height (max 0 (+ (- ~'kernel-height input-over-y#)
                                    input-under-y#))
         ~'exc-pad-kernel-num-elems (* ~'exc-pad-width ~'exc-pad-height)]
     (c-for
      [~'k-y 0 (< ~'k-y ~'kernel-height) (inc ~'k-y)]
      (c-for
       [~'k-x 0 (< ~'k-x ~'kernel-width) (inc ~'k-x)]
       (let [~'input-x (+ ~'input-rel-x ~'k-x)
             ~'input-y (+ ~'input-rel-y ~'k-y)
             ~'output-conv-addr (+ (* ~'output-offset
                                      ~'output-column-stride)
                                   ~'chan-conv-offset
                                   (* ~'k-y ~'kernel-width)
                                   ~'k-x)
             ~'input-addr  (+ (* ~'input-y ~'input-width)
                              ~'input-x
                              ~'chan-input-offset)
             ~'input-valid? (and (in-bounds? ~'input-x 0 ~'input-width)
                                 (in-bounds? ~'input-y 0 ~'input-height))
             loop-valid?# (and (in-bounds? ~'input-x ~'min-x ~'max-x)
                               (in-bounds? ~'input-y ~'min-y ~'max-y))]
         (when loop-valid?#
           ~@body))))))
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 []))

  When Emacs reads text, it tries to detect how the text is encoded.
  This code detection is sensitive to escape sequences.  If Emacs sees
  a valid ISO-2022 escape sequence, it assumes the text is encoded in one
  of the ISO2022 encodings, and decodes text by the corresponding coding
  system (e.g. `iso-2022-7bit').

  The default value is nil, and it is strongly recommended not to change
  it.  That is because many Emacs Lisp source files that contain
  non-ASCII characters are encoded by the coding system `iso-2022-7bit'
  in Emacs's distribution, and they won't be decoded correctly on
  reading if you suppress escape sequence detection.

  Do not alter the value of this variable manually.  This variable should be
  updated by the functions `define-coding-system' and
  `define-coding-system-alias'.")

(defvar coding-system-for-write nil
  "Specify the coding system for write operations.
  Programs bind this variable with `let', but you should not set it globally.
  If the value is a coding system, it is used for encoding of output,
  when writing it to a file and when sending it to a file or subprocess.

  If this does not specify a coding system, an appropriate element
  is used from one of the coding system alists.
  There are three such tables: `file-coding-system-alist',
  `process-coding-system-alist', and `network-coding-system-alist'.
  For output to files, if the above procedure does not specify a coding system,
  the value of `buffer-file-coding-system' is used.")

(defvar coding-system-for-read nil
  "Specify the coding system for read operations.
  It is useful to bind this variable with `let', but do not set it globally.
  If the value is a coding system, it is used for decoding on read operation.
  If not, an appropriate element is used from one of the coding system alists.
  There are three such tables: `file-coding-system-alist',
  `process-coding-system-alist', and `network-coding-system-alist'.")

  The default value is `select-safe-coding-system' (which see).")

  When an error was detected in the last code conversion, this variable
  is set to one of the following symbols.
    `insufficient-source'
    `inconsistent-eol'
    `invalid-source'
    `interrupted'
    `insufficient-memory'
  When no error was detected, the value doesn't change.  So, to check
  the error status of a code conversion by this variable, you must
  explicitly set this variable to nil before performing code
  conversion.")

  Do not alter the value of this variable manually.  This variable should be
  updated by the functions `make-coding-system' and
  `define-coding-system-alias'.")

  Integer values 0, 1, and 2 indicate a format of end-of-line; LF, CRLF,
  and CR respectively.

  A vector value indicates that a format of end-of-line should be
  detected automatically.  Nth element of the vector is the subsidiary
  coding system whose eol-type is N."
  ({"\n" '0 "\r\n" 1 "\r" 2} (System/lineSeparator)))

  If optional 4th argument COUNT is non-nil, it specifies at most how
  many un-encodable characters to search.  In this case, the value is a
  list of positions.

  The value is an alist ((CODING-SYSTEM POS0 POS1 ...) ...), where
  CODING-SYSTEM is a member of CODING-SYSTEM-LIST and can't encode the
  whole region, POS0, POS1, ... are buffer positions where non-encodable
  characters are found.

  If all coding systems in CODING-SYSTEM-LIST can encode the region, the
  value is nil.

  START may be a string.  In that case, check if the string is
  encodable, and the value contains indices to the string instead of
  buffer positions.  END is ignored.

  If the current buffer (or START if it is a string) is unibyte, the value
  is nil."
  )

  Optional fourth arg BUFFER non-nil means that the encoded text is
  inserted in that buffer after point (point does not move).  In this
  case, the return value is the length of the encoded text.

(defun find-operation-coding-system (operation &rest arguments)
  "Choose a coding system for an operation based on the target name.
  The value names a pair of coding systems: (DECODING-SYSTEM . ENCODING-SYSTEM).
  DECODING-SYSTEM is the coding system to use for decoding
  (in case OPERATION does decoding), and ENCODING-SYSTEM is the coding system
  for encoding (in case OPERATION does encoding).

(defun coding-system-put (coding-system prop val)
  "Change value in CODING-SYSTEM's property list PROP to VAL."
  )

  Optional fourth arg BUFFER non-nil means that the decoded text is
  inserted in that buffer after point (point does not move).  In this
  case, the return value is the length of the decoded text.

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