Back
meta (clj)
(source)variable
(meta obj)
Returns the metadata of obj, returns nil if there is no metadata.
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 t-Explicit-line-column-numbers
(is (= {:line 42 :column 99}
(-> "^{:line 42 :column 99} (1 2)" read-string meta (select-keys [:line :column]))))
(are [l c s] (= {:line l :column c} (-> s str->lnpr read meta (select-keys [:line :column])))
42 99 "^{:line 42 :column 99} (1 2)"
1 99 "^{:column 99} (1 2)")
(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])))))
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]))))))
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!))
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)))))))
cognitect-labs/aws-api
(ns s3-examples
(:require [clojure.core.async :as a]
[clojure.spec.alpha :as s]
[clojure.spec.gen.alpha :as gen]
[clojure.java.io :as io]
[clojure.repl :as repl]
[cognitect.aws.client.api :as aws]))
;; http-request and http-response are in metadata
(meta *1)
(meta *1)
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]))
(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 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)
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))))
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)))