Back
symbol (clj)
(source)function
(symbol name)
(symbol ns name)
Returns a Symbol with the given namespace and name. Arity-1 works
on strings, keywords, and vars.
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 invalid-symbol-value
(is (thrown-with-msg? Exception #"Invalid token" (read-string "##5")))
(is (thrown-with-msg? Exception #"Invalid token" (edn/read-string "##5")))
(is (thrown-with-msg? Exception #"Unknown symbolic value" (read-string "##Foo")))
(is (thrown-with-msg? Exception #"Unknown symbolic value" (edn/read-string "##Foo"))))
logseq/logseq
(ns frontend.pubsub
"All mults and pubs are collected to this ns.
vars with suffix '-mult' is a/Mult, use a/tap and a/untap on them. used by event subscribers
vars with suffix '-pub' is a/Pub, use a/sub and a/unsub on them. used by event subscribers
vars with suffix '-ch' is chan used by event publishers."
{:clj-kondo/config {:linters {:unresolved-symbol {:level :off}}}}
#?(:cljs (:require-macros [frontend.pubsub :refer [def-mult-or-pub chan-of]]))
(:require [clojure.core.async :as a :refer [chan mult pub]]
[clojure.core.async.impl.protocols :as ap]
[malli.core :as m]
[malli.dev.pretty :as mdp]
[clojure.pprint :as pp]))
(defmacro def-mult-or-pub
"define following vars:
- `symbol-name`-ch for event publisher.
- `symbol-name`-mult or `symbol-name`-pub for event subscribers.
- `symbol-name`-validator is malli schema validator
def -pub var when `:topic-fn` exists otherwise -mult var"
[symbol-name doc-string malli-schema & {:keys [ch-buffer topic-fn]
:or {ch-buffer 1}}]
(let [schema-validator-name (symbol (str symbol-name "-validator"))
schema-name (symbol (str symbol-name "-schema"))
ch-name (symbol (str symbol-name "-ch"))
mult-or-pub-name (if topic-fn
(symbol (str symbol-name "-pub"))
(symbol (str symbol-name "-mult")))
doc-string* (str doc-string "\nMalli-schema:\n" (with-out-str (pp/pprint malli-schema)))]
`(do
(def ~schema-name ~malli-schema)
(def ~schema-validator-name (m/validator ~malli-schema))
(def ~ch-name ~doc-string* (chan-of ~malli-schema ~schema-validator-name ~ch-buffer))
~(if topic-fn
`(def ~mult-or-pub-name ~doc-string* (pub ~ch-name ~topic-fn))
`(def ~mult-or-pub-name ~doc-string* (mult ~ch-name))))))
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 ClojureScript
(let [mdata (aapi/resolve &env v)
arglists (second (get-in mdata [:meta :arglists]))
sym (symbol (c/name v))
andsym (symbol "&")
procarg #(if (= % andsym) % (gensym "param"))]
(if (pos? (count arglists))
`(def
~(with-meta sym (:meta mdata))
(fn ~@(for [args arglists]
(let [args (map procarg args)]
(if (some #(= andsym %) args)
(let [[sargs dargs] (split-with #(not= andsym %) args)]
`([~@sargs ~@dargs] (apply ~v ~@sargs ~@(rest dargs))))
`([~@args] (~v ~@args)))))))
`(def ~(with-meta sym (:meta mdata)) ~v)))
nextjournal/clerk
(ns nextjournal.clerk.atom
"Demo of Clerk's two-way bindings."
{:nextjournal.clerk/visibility {:code :hide :result :hide}}
(:require [clojure.core :as core]
[nextjournal.clerk :as clerk]))
(def transform-var
(comp (clerk/update-val symbol)
clerk/mark-presented))
nextjournal/clerk
(ns viewers.controls
"Demo of Clerk's two-way bindings."
{:nextjournal.clerk/visibility {:code :show :result :show}}
(:require [clojure.core :as core]
[nextjournal.clerk :as clerk]
[nextjournal.clerk.viewer :as viewer]))
(def transform-var
(comp clerk/mark-presented
(clerk/update-val (fn [v] (viewer/->ViewerEval (list 'resolve (list 'quote (symbol v))))))))
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)))