Back
if-not (clj)
(source)macro
(if-not test then)
(if-not test then else)
Evaluates test. If logical false, evaluates and returns then expr,
otherwise else expr, if supplied, else nil.
Examples
thheller/shadow-cljs
(ns shadow.remote.runtime.cljs.js-builtins
(:require
[goog.object :as gobj]
[clojure.core.protocols :as p]))
(extend-protocol p/Datafiable
;; FIXME: this is kind of a bad idea
;; can't do this for all objects, since none of the CLJS types implement this
;; protocol either. the protocol dispatch will end up using object
;; FIXME: this could detect CLJS types to some extent
;; or should it just implement the protocols for the types?
object
(datafy [o]
(if-not (identical? (.-__proto__ o) js/Object.prototype)
o
(with-meta
(->> (gobj/getKeys o)
(reduce
(fn [m key]
(assoc! m key (gobj/get o key)))
(transient {}))
(persistent!))
PrecursorApp/precursor
(ns pc.http.routes.api
(:require [cemerick.url :as url]
[cheshire.core :as json]
[clojure.core.memoize :as memo]
[clojure.string :as str]
[clojure.tools.reader.edn :as edn]
[crypto.equality :as crypto]
[defpage.core :as defpage :refer (defpage)]
[pc.auth :as auth]
[pc.crm :as crm]
[pc.datomic :as pcd]
[pc.early-access]
[pc.http.doc :as doc-http]
[pc.http.team :as team-http]
[pc.http.handlers.custom-domain :as custom-domain]
[pc.models.chat-bot :as chat-bot-model]
[pc.models.doc :as doc-model]
[pc.models.flag :as flag-model]
[pc.models.team :as team-model]
[pc.profile :as profile]
[ring.middleware.anti-forgery :as csrf]
[slingshot.slingshot :refer (try+ throw+)]))
(defpage new [:post "/api/v1/document/new"] [req]
(let [params (some-> req :body slurp edn/read-string)
read-only? (:read-only params)
doc-name (:document/name params)]
(if-not (:subdomain req)
(let [cust-uuid (get-in req [:auth :cust :cust/uuid])
intro-layers? (:intro-layers? params)
doc (doc-model/create-public-doc!
(merge {:document/chat-bot (rand-nth chat-bot-model/chat-bots)}
(when cust-uuid {:document/creator cust-uuid})
(when read-only? {:document/privacy :document.privacy/read-only})
(when doc-name {:document/name doc-name})))]
(when intro-layers?
(doc-http/add-intro-layers doc))
{:status 200 :body (pr-str {:document (doc-model/read-api doc)})})
(if (and (:team req)
(auth/logged-in? req)
(auth/has-team-permission? (pcd/default-db) (:team req) (:auth req) :admin))
(let [doc (doc-model/create-team-doc!
(:team req)
(merge {:document/chat-bot (rand-nth chat-bot-model/chat-bots)}
(when-let [cust-uuid (get-in req [:cust :cust/uuid])]
{:document/creator cust-uuid})
(when read-only?
{:document/privacy :document.privacy/read-only})
(when doc-name
{:document/name doc-name})))]
{:status 200 :body (pr-str {:document (doc-model/read-api doc)})})
{:status 400 :body (pr-str {:error :unauthorized-to-team
:redirect-url (str (url/map->URL {:host (profile/hostname)
:protocol (if (profile/force-ssl?)
"https"
(name (:scheme req)))
:port (if (profile/force-ssl?)
(profile/https-port)
(profile/http-port))
:path "/new"
:query (:query-string req)}))
:msg "You're unauthorized to make documents in this subdomain. Please request access."})}))))
hraberg/deuce
(ns deuce.emacs.callproc
(:use [deuce.emacs-lisp :only (defun defvar) :as el])
(:require [clojure.core :as c]
[clojure.string :as s]
[clojure.java.io :as io]
[clojure.java.shell :as sh]
[deuce.emacs.buffer :as buffer]
[deuce.emacs.data :as data]
[deuce.emacs.editfns :as editfns])
(:import [java.io File])
(:refer-clojure :exclude []))
If optional parameter ENV is a list, then search this list instead of
`process-environment', and return t when encountering a negative entry
(an entry for a variable with no value)."
(if-not env
(System/getenv variable)
(throw (IllegalArgumentException. "doesn't yet support env argument"))))
typedclojure/typedclojure
(ns ^:no-doc typed.clj.ext.clojure.core__doseq
"Typing rules clojure.core/doseq"
(:require [clojure.core.typed.contract-utils :as con]
[clojure.core.typed.errors :as err]
[typed.clj.checker.check :refer [check-expr]]
[typed.clj.checker.parse-unparse :as prs]
[typed.clj.analyzer.passes.emit-form :as emit-form]
[typed.clj.analyzer.utils :as ana-utils]
[typed.clj.ext.clojure.core__for :as ext-for]
[typed.clj.ext.clojure.core__let :as ext-let]
[typed.cljc.analyzer :as ana2]
[typed.cljc.checker.check.let :as let]
[typed.cljc.checker.check-below :as below]
[typed.cljc.checker.check.if :as if]
[typed.cljc.checker.filter-ops :as fo]
[typed.cljc.checker.lex-env :as lex]
[typed.cljc.checker.var-env :as var-env]
[typed.cljc.checker.type-rep :as r]
[typed.cljc.checker.type-ctors :as c]
[typed.cljc.checker.cs-gen :as cgen]
[typed.cljc.checker.utils :as u]
[typed.cljc.checker.check.unanalyzed :refer [defuspecial]]))
(defuspecial defuspecial__doseq
"defuspecial implementation for clojure.core/doseq"
[{ana-env :env :keys [form] :as expr} expected]
(let [_ (assert (<= 2 (count form)) form)
[args-syn & body-syns] (next form)
{:keys [new-syms expanded-bindings prop-env ana-env reachable]}
(ext-for/check-list-comprehension-binder
{:form form
:args-syn args-syn
:ana-env ana-env
:prop-env (lex/lexical-env)})
expr (-> expr
(update :form
(fn [form]
(-> (map-indexed
(fn [i args-syn]
;; add back short-circuited args
(if (= 1 i)
expanded-bindings
args-syn))
form)
(with-meta (meta form))))))]
(if-not reachable
(assoc expr
u/expr-type (below/maybe-check-below
(r/ret r/-nil
(fo/-false-filter))
expected))
(let [cbody (var-env/with-lexical-env prop-env
(-> `(do ~@body-syns)
(ana2/unanalyzed ana-env)
check-expr))
expr (-> expr
(update :form
(fn [form]
(-> form
vec
(subvec 0 2)
(conj (emit-form/emit-form cbody))
list*
(with-meta (meta form))))))]
(assoc expr
u/expr-type (below/maybe-check-below
(r/ret r/-nil
(fo/-false-filter))
expected))))))
finnishtransportagency/harja
(ns harja.tyokalut.makrot
(:require [clojure.core.async :as async]
[taoensso.timbre :as log]))
(defmacro go-loop-timeout
"Lukee asioita annetusta kanavasta kuten go-loop, mutta lopettaa
lukemisen annetun timeoutin jälkeen ja sulkee kanavan. Jos käsittelyssä
tapahtuu virhe, se lokitetaan ja kanava suljetaan."
[{:keys [timeout on-timed-out]
:or {timeout 10000 on-timed-out nil}} [name chan-to-read-from] & body]
`(let [timeout# (async/timeout ~timeout)
chan# ~chan-to-read-from
lue# #(async/alts!! [chan# timeout#])]
(try
(loop [[v# ch#] (lue#)]
(if-not v#
(do
(async/close! chan#)
(when (= ch# timeout#)
(do
;; Imetään tyhjäksi kanava, jotta pending puts
;; menevät läpi.
(async/go-loop []
(when (async/<! chan#)
(recur)))
~on-timed-out)))
(let [~name v#]
~@body
(recur (lue#)))))
(catch Throwable t#
(log/warn t# "Virhe go-loop-timeout lohkossa!")
(async/close! chan#)))))