Back
cons (clj)
(source)variable
(cons x seq)
Returns a new seq where x is the first element and seq is
the rest.
Examples
penpot/penpot
(ns app.main.ui.icons
(:require
[clojure.core :as c]
[cuerdas.core :as str]
[rumext.v2]))
(defmacro collect-icons
[]
(let [ns-info (:ns &env)]
`(cljs.core/js-obj
~@(->> (:defs ns-info)
(map val)
(filter (fn [entry] (-> entry :meta :icon)))
(mapcat (fn [{:keys [name] :as entry}]
[(-> name c/name str/camel str/capital) name]))))))
clojure/core.async
;; The clojure.core.async namespace contains the public API.
(require '[clojure.core.async :as async :refer :all])
;; Data is transmitted on queue-like channels. By default channels
;; are unbuffered (0-length) - they require producer and consumer to
;; rendezvous for the transfer of a value through the channel.
;; Instead of the explicit thread and blocking call, we use a go block
;; for the producer. The consumer uses a go block to take, then
;; returns a result channel, from which we do a blocking take.
noprompt/meander
(ns multimethods
(:refer-clojure :exclude [defmethod defmulti])
(:require
#?(:clj [clojure.core :as clj] :cljs [cljs.core :as cljs])
[meander.epsilon :as m]))
(defmacro defmethod
[mf [& lhr] & body]
(swap! cache_ assoc-in [mf lhr] body)
(let [ptrns (get @cache_ mf)]
`(-set-fn ~(with-meta mf {:tag `MultiMeanderFn})
(fn [& ~'argsv]
(m/match ~'argsv
~@(loop [[[l r] & more] ptrns xs []]
(if l
(recur more (conj xs l (cons `do r)))
xs)))))))
mikera/core.matrix
WARNING: because they lack efficient indexed access, sequences will perform badly for most
array operations. In general they should be converted to other implementations before use."
(:require [clojure.core.matrix.protocols :as mp]
[clojure.core.matrix.implementations :as imp]
#?(:clj [clojure.core.matrix.macros :refer [scalar-coerce error]]))
#?(:clj (:import [clojure.lang ISeq])
:cljs (:require-macros [clojure.core.matrix.macros :refer [scalar-coerce error]])))
(extend-protocol mp/PImplementation
ISeq
(implementation-key [m] :sequence)
(meta-info [m]
{:doc "Core.matrix implementation for Clojure ISeq objects"})
(new-vector [m length]
(mp/new-vector [] length))
(new-matrix [m rows columns]
(mp/new-matrix [] rows columns))
(new-matrix-nd [m dims]
(mp/new-matrix-nd [] dims))
(construct-matrix [m data]
(mp/coerce-param [] data))
(supports-dimensionality? [m dims]
true))
(extend-protocol mp/PDimensionInfo
ISeq
(dimensionality [m]
(inc (mp/dimensionality (first m))))
(is-vector? [m]
(== 0 (mp/dimensionality (first m))))
(is-scalar? [m]
false)
(get-shape [m]
#?(:cljs (js/console.log (str "shape of seq: " m)))
(cons (count m) (mp/get-shape (first m))))
(dimension-count [m x]
(if (== x 0)
(count m)
(mp/dimension-count (first m) (dec x)))))
(extend-protocol mp/PMapIndexed
ISeq
(element-map-indexed
([ms f]
(mapv (fn [i m] (mp/element-map-indexed m #(apply f (cons i %1) %&)))
(range (count ms)) ms))
([ms f as]
(let [[ms as] (mp/broadcast-compatible ms as)]
(mapv (fn [i m a]
(mp/element-map-indexed m #(apply f (cons i %1) %&) a))
(range (count ms)) ms (mp/get-major-slice-seq as))))
([ms f as more]
(let [[ms as & more] (apply mp/broadcast-compatible ms as more)] ; FIXME
(mapv (fn [i m a & mr]
(mp/element-map-indexed m #(apply f (cons i %1) %&) a mr))
(range (count ms)) ms
(mp/get-major-slice-seq as)
(map mp/get-major-slice-seq more)))))
(element-map-indexed!
([m f]
(error "Sequence arrays are not mutable!"))
([m f a]
(error "Sequence arrays are not mutable!"))
([m f a more]
(error "Sequence arrays are not mutable!"))))
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]))
This limit serves to catch infinite recursions for you before they cause
actual stack overflow in C, which would be fatal for Emacs.
You can safely make it considerably larger than its default value,
if that proves inconveniently small. However, if you increase it too far,
Emacs could overflow the real C stack, and crash.
(defvar max-specpdl-size nil
"*Limit on number of Lisp variable bindings and `unwind-protect's.
If Lisp code tries to increase the total number past this amount,
an error is signaled.
You can safely use a value considerably larger than the default value,
if that proves inconveniently small. However, if you increase it too far,
Emacs could run out of memory trying to make the stack bigger.
But condition (i) is considered obsolete, so for most purposes this is
equivalent to `custom-variable-p'."
)
DATA should be a list. Its elements are printed as part of the error message.
See Info anchor `(elisp)Definition of signal' for some details on how this
error message is constructed.
If the signal is handled, DATA is made available to the handler.
See also the function `condition-case'."
(el/throw error-symbol data))
(defun funcall (function &rest arguments)
"Call first argument as a function, passing remaining arguments to it.
Return the value that function returns.
Thus, (funcall 'cons 'x 'y) returns (x . y)."
(apply function arguments))
(defun macroexpand (form &optional environment)
"Return result of expanding macros at top level of FORM.
If FORM is not a macro call, it is returned unchanged.
Otherwise, the macro is expanded and the expansion is considered
in place of FORM. When a non-macro-call results, it is returned.
The second optional arg ENVIRONMENT specifies an environment of macro
definitions to shadow the loaded ones for use in file byte-compilation."
;; Not sure how this is supposed to work even after reading eval.c, attempts to mimic observed behavior.
;; It is used in conjunction with cl-macroexpand-all, and should not expand into "raw" Clojure.
(let [shadow (into {} (map #(vector (data/car %) (data/cdr %)) environment))
shadow #(shadow % (shadow (str %)))
unshadowed-form ((fn shadow-walker [form]
(if-let [expander (shadow form)]
(if (= '(true) (data/cdr-safe expander))
(cons (first (data/car expander))
(map #(list 'quote %) (rest (data/car expander))))
(expander form))
(if (and (seq? form)
(not= 'quote (first form)))
(cons/maybe-seq (map shadow-walker form))
form))) form)
expansion (if-let [m (and (seq? form) (-> (el/fun (first form)) meta))]
(if (and (:macro m) (= (the-ns 'deuce.emacs-lisp) (:ns m)))
unshadowed-form
(macroexpand-1 unshadowed-form))
unshadowed-form)]
;; Protect against eq check in cl-macroexpand-all
(if (= form expansion)
form
expansion)))