Public Vars

Back

when (clj)

(source)

macro

(when test & body)
Evaluates test. If logical true, evaluates body in an implicit do.

Examples

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


(deftest test-sorted-maps
  (let [m (into (sorted-map)
                '{1 a, 2 b, 3 c, 4 d})]
    (is (= "1a2b3c4d" (reduce-kv str "" m))
        "Sorted maps should reduce-kv in sorted order")
    (is (= 1 (reduce-kv (fn [acc k v]
                          (reduced (+ acc k)))
                        0 m))
        "Sorted maps should stop reduction when asked")))

(defn reduced-at-probe
  [m p]
  (reduce-kv (fn [_ k v] (when (== p k) (reduced :foo))) nil m))

(deftest test-fold-runtime-exception
  (is (thrown? IndexOutOfBoundsException
               (let [test-map-count 1234
                     k-fail (rand-int test-map-count)]
                 (r/fold (fn ([])
                           ([ret [k v]])
                           ([ret k v] (when (= k k-fail)
                                        (throw (IndexOutOfBoundsException.)))))
                         (zipmap (range test-map-count) (repeat :dummy)))))))
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//))))))

(defspec types-that-should-roundtrip
  roundtrip
  [^{:tag cgen/ednable} o]
  (when-not (= o %)
    (throw (ex-info "Value cannot roundtrip, see ex-data" {:printed o :read %}))))

(defspec types-that-need-dup-to-roundtrip
  roundtrip-dup
  [^{:tag cgen/dup-readable} o]
  (when-not (= o %)
    (throw (ex-info "Value cannot roundtrip, see ex-data" {:printed o :read %}))))
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 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.ccl
  (:use [deuce.emacs-lisp :only (defun defvar)])
  (:require [clojure.core :as c])
  (:refer-clojure :exclude []))

(defvar font-ccl-encoder-alist nil
  "Alist of fontname patterns vs corresponding CCL program.
  Each element looks like (REGEXP . CCL-CODE),
   where CCL-CODE is a compiled CCL program.
  When a font whose name matches REGEXP is used for displaying a character,
   CCL-CODE is executed to calculate the code point in the font
   from the charset number and position code(s) of the character which are set
   in CCL registers R0, R1, and R2 before the execution.
  The code point in the font is set in CCL registers R1 and R2
   when the execution terminated.
   If the font is single-byte font, the register R2 is not used.")

  If optional 4th arg CONTINUE is non-nil, keep IC on read operation
  when read buffer is exhausted, else, IC is always set to the end of
  CCL-PROGRAM on exit.
hraberg/deuce
(ns deuce.emacs.eval
  (:use [deuce.emacs-lisp :only (defun defvar)])
  (:require [clojure.core :as c]
            [deuce.emacs.alloc :as alloc]
            [deuce.emacs.data :as data]
            [deuce.emacs-lisp.cons :as cons]
            [deuce.emacs-lisp :as el])
  (:import [clojure.lang Var])
  (:refer-clojure :exclude [apply eval macroexpand]))

(defvar debugger-may-continue nil
  "Non-nil means debugger may continue execution.
  This is nil when the debugger is called under circumstances where it
  might not be safe to continue.")

(defun functionp (object)
  "Non-nil if OBJECT is a function."
  (when (or (fn? object)
            (and (symbol? object) (el/fun object))
            (and (seq? object) (= 'lambda (first object))))
    true))

(defun autoload (function file &optional docstring interactive type)
  "Define FUNCTION to autoload from FILE.
  FUNCTION is a symbol; FILE is a file name string to pass to `load'.
  Third arg DOCSTRING is documentation for the function.
  Fourth arg INTERACTIVE if non-nil says function can be called interactively.
  Fifth arg TYPE indicates the type of the object:
     nil or omitted says FUNCTION is a function,
     `keymap' says FUNCTION is really a keymap, and
     `macro' or t says FUNCTION is really a macro.
  Third through fifth args give info about the real definition.
  They default to nil.
  If FUNCTION is already defined other than as an autoload,
  this does nothing and returns nil."
  (when (or (not (el/fun function)) (-> (el/fun function) meta :autoload))
    (let [macro? (= 'macro type)
          autoload-symbol (fn autoload-symbol [function]
                            (let [f (el/fun function)]
                              (when (-> f meta :autoload)
                                (ns-unmap 'deuce.emacs (el/sym function))
                                ((el/fun 'load) (-> f meta :file) nil true))))
          definition  (if macro?
                        (fn autoload-macro [&form &env & args] ;; Note implicit macro args, see defalias
                          (do
                            (autoload-symbol function)
                            `(el/progn (~(el/sym function) ~@args))))
                        (fn autoload [& args]
                          (autoload-symbol function)
                          (c/apply (el/fun function) args)))] ;; el->clj?
      (ns-unmap 'deuce.emacs function)
      (el/defvar-helper* 'deuce.emacs function definition docstring)
      (alter-meta! (el/fun function) merge {:autoload true :file file} (when interactive {:interactive nil}))
      (when macro? (.setMacro ^Var (el/fun function))))
    function))

(defun called-interactively-p (kind)
  "Return t if the containing function was called by `call-interactively'.
  If KIND is `interactive', then only return t if the call was made
  interactively by the user, i.e. not in `noninteractive' mode nor
  when `executing-kbd-macro'.
  If KIND is `any', on the other hand, it will return t for any kind of
  interactive call, including being called as the binding of a key, or
  from a keyboard macro, or in `noninteractive' mode.

  The only known proper use of `interactive' for KIND is in deciding
  whether to display a helpful message, or how to display it.  If you're
  thinking of using it for any other purpose, it is quite likely that
  you're making a mistake.  Think: what do you want to do when the
  command is called from a keyboard macro?

  Do not use `make-local-variable' to make a hook variable buffer-local.
  Instead, use `add-hook' and specify t for the LOCAL argument."
  (when-let [hook (el/global hook)]
    (let [hook @hook]
      (doall (map #(c/apply funcall % args) (if (fn? hook) [hook] hook))))))

  The only known proper use of `interactive-p' is in deciding whether to
  display a helpful message, or how to display it.  If you're thinking
  of using it for any other purpose, it is quite likely that you're
  making a mistake.  Think: what do you want to do when the command is
  called from a keyboard macro?

(defun defvaralias (new-alias base-variable &optional docstring)
  "Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
  Aliased variables always have the same value; setting one sets the other.
  Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS.  If it is
  omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
  or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
  itself an alias.  If NEW-ALIAS is bound, and BASE-VARIABLE is not,
  then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
  The return value is BASE-VARIABLE."
  (if-let [base (el/global base-variable)]
    (el/defvar-helper* 'deuce.emacs-lisp.globals new-alias
      @base (or docstring (-> base meta :doc)))
    (when-let [new (el/global new-alias)]
      (el/defvar-helper* 'deuce.emacs-lisp.globals base-variable
        @new (or docstring (-> new meta :doc)))))
  base-variable)

(defun backtrace-debug (level flag)
  "Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
  The debugger is entered when that frame exits, if the flag is non-nil."
  )

  If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
  then strings and vectors are not accepted."
  (if (or (data/stringp function) (data/vectorp function))
    (when-not for-call-interactively true)
    (when-let [f (el/fun function)]
      (when (contains? (meta f) :interactive)
        true))))
hraberg/deuce
(ns deuce.emacs.term
  (:use [deuce.emacs-lisp :only (defun defvar)])
  (:require [clojure.core :as c]
            [deuce.emacs.data :as data]
            [deuce.emacs.eval :as eval]
            [deuce.emacs.terminal :as terminal])
  (:import [com.googlecode.lanterna.screen Screen])
  (:refer-clojure :exclude []))

(defvar visible-cursor nil
  "Non-nil means to make the cursor very visible.
  This only has an effect when running in a text terminal.
  What means \"very visible\" is up to your terminal.  It may make the cursor
  bigger, or it may make it blink, or it may do nothing at all.

  TTY may be a terminal object, a frame, or nil (meaning the selected
  frame's terminal)."
  (when-let [terminal ^Screen (terminal/frame-terminal)]
    (.startScreen terminal)
    ((ns-resolve 'deuce.main 'start-ui))
    (eval/run-hook-with-args 'resume-tty-functions terminal)))

  A suspended tty may be resumed by calling `resume-tty' on it."
  (when-let [terminal ^Screen (terminal/frame-terminal)]
    ((ns-resolve 'deuce.main 'stop-ui))
    (.stopScreen terminal)
    (eval/run-hook-with-args 'suspend-tty-functions terminal)))
hraberg/deuce
(ns deuce.emacs.undo
  (:use [deuce.emacs-lisp :only (defun defvar)])
  (:require [clojure.core :as c])
  (:refer-clojure :exclude []))

(defvar undo-strong-limit nil
  "Don't keep more than this much size of undo information.
  This limit is applied when garbage collection happens.
  When a previous command increases the total undo list size past this
  value, that command and the earlier commands that came before it are forgotten.
  However, the most recent buffer-modifying command's undo info
  is never discarded for this reason.

(defvar undo-limit nil
  "Keep no more undo information once it exceeds this size.
  This limit is applied when garbage collection happens.
  When a previous command increases the total undo list size past this
  value, the earlier commands that came before it are forgotten.

(defvar undo-outer-limit-function nil
  "Function to call when an undo list exceeds `undo-outer-limit'.
  This function is called with one argument, the current undo list size
  for the most recent command (since the last undo boundary).
  If the function returns t, that means truncation has been fully handled.
  If it returns nil, the other forms of truncation are done.