Back
alter-meta! (clj)
(source)function
(alter-meta! iref f & args)
Atomically sets the metadata for a namespace/var/ref/agent/atom to be:
(apply f its-current-meta args)
f must be free of side-effects
Examples
penpot/penpot
#_:clj-kondo/ignore
(ns app.common.data.macros
"Data retrieval & manipulation specific macros."
(:refer-clojure :exclude [get-in select-keys str with-open min max])
#?(:cljs (:require-macros [app.common.data.macros]))
(:require
#?(:clj [clojure.core :as c]
:cljs [cljs.core :as c])
[app.common.data :as d]
[cljs.analyzer.api :as aapi]
[cuerdas.core :as str]))
;; Code for Clojure
(let [vr (resolve v)
m (meta vr)
n (:name m)
n (with-meta n
(cond-> {}
(:dynamic m) (assoc :dynamic true)
(:protocol m) (assoc :protocol (:protocol m))))]
`(let [m# (meta ~vr)]
(def ~n (deref ~vr))
(alter-meta! (var ~n) merge (dissoc m# :name))
;; (when (:macro m#)
;; (.setMacro (var ~n)))
~vr))))
clojure/core.typed
(ns ^:no-doc clojure.core.typed.import-macros
(:require [clojure.core :as core]))
;copied from ClojureScript
(defmacro import-macros [ns [& vars]]
(core/let [ns (find-ns ns)
vars (map (core/fn [vsym]
{:pre [(symbol? vsym)]
:post [(instance? clojure.lang.Var %)]}
(let [v (ns-resolve ns vsym)]
(assert v (str "Internal error: " vsym " does not exist"))
v))
vars)
syms (map (core/fn [^clojure.lang.Var v]
{:pre [(instance? clojure.lang.Var v)]
:post [(symbol? %)]}
(core/-> v .sym (with-meta {:macro true})))
vars)
defs (map (core/fn [sym var]
{:pre [(symbol? sym)
(instance? clojure.lang.Var var)]}
`(do (def ~sym (deref ~var))
;for AOT compilation
(alter-meta! (var ~sym)
merge
(dissoc (meta ~var) :ns :name)
{:macro true})))
syms vars)]
`(do ~@defs
:imported)))
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))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
cc/reset-meta! [clojure.lang.IReference (t/Nilable (t/Map t/Any t/Any)) :-> (t/Nilable (t/Map t/Any t/Any))]
cc/alter-meta!
(t/All [b :..]
[clojure.lang.IReference
[(t/Nilable (t/Map t/Any t/Any)) b :.. b :->
(t/Nilable (t/Map t/Any t/Any))] b :.. b :-> (t/Nilable (t/Map t/Any t/Any))])
typedclojure/typedclojure
(ns ^:no-doc clojure.core.typed.import-macros
(:require [clojure.core :as core]))
;copied from ClojureScript
(defmacro import-macros [ns [& vars]]
(core/let [ns (find-ns ns)
vars (map (core/fn [vsym]
{:pre [(symbol? vsym)]
:post [(instance? clojure.lang.Var %)]}
(let [v (ns-resolve ns vsym)]
(assert v (str "Internal error: " vsym " does not exist"))
v))
vars)
syms (map (core/fn [^clojure.lang.Var v]
{:pre [(instance? clojure.lang.Var v)]
:post [(symbol? %)]}
(core/-> v .sym (with-meta {:macro true})))
vars)
defs (map (core/fn [sym var]
{:pre [(symbol? sym)
(instance? clojure.lang.Var var)]}
`(do (def ~sym (deref ~var))
;for AOT compilation
(alter-meta! (var ~sym)
merge
(dissoc (meta ~var) :ns :name)
{:macro true})))
syms vars)]
`(do ~@defs
:imported)))