Public Vars

Back

the-ns (clj)

(source)

function

(the-ns x)
If passed a namespace, returns it. Else, when passed a symbol, returns the namespace named by it, throwing an exception if not found.

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//))))))

(require '[clojure.string :as s])
(deftest namespaced-maps
  (is (= #:a{1 nil, :b nil, :b/c nil, :_/d nil}
         #:a {1 nil, :b nil, :b/c nil, :_/d nil}
         {1 nil, :a/b nil, :b/c nil, :d nil}))
  (is (= #::{1 nil, :a nil, :a/b nil, :_/d nil}
         #::  {1 nil, :a nil, :a/b nil, :_/d nil}
         {1 nil, :clojure.test-clojure.reader/a nil, :a/b nil, :d nil} ))
  (is (= #::s{1 nil, :a nil, :a/b nil, :_/d nil}
         #::s  {1 nil, :a nil, :a/b nil, :_/d nil}
         {1 nil, :clojure.string/a nil, :a/b nil, :d nil}))
  (is (= (read-string "#:a{b 1 b/c 2}") {'a/b 1, 'b/c 2}))
  (is (= (binding [*ns* (the-ns 'clojure.test-clojure.reader)] (read-string "#::{b 1, b/c 2, _/d 3}")) {'clojure.test-clojure.reader/b 1, 'b/c 2, 'd 3}))
  (is (= (binding [*ns* (the-ns 'clojure.test-clojure.reader)] (read-string "#::s{b 1, b/c 2, _/d 3}")) {'clojure.string/b 1, 'b/c 2, 'd 3})))
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]))

  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)))
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/find-ns [t/Sym :-> (t/Nilable t/Namespace)]
cc/create-ns [t/Sym :-> t/Namespace]
#?@(:cljs [] :default [
cc/remove-ns [t/Sym :-> t/Namespace]
cc/ns-map [(t/U t/Sym t/Namespace) :-> t/Sym]
cc/ns-aliases [(t/U t/Sym t/Namespace) :-> (t/Map t/Sym t/Namespace)]
cc/the-ns [(t/U t/Sym t/Namespace) :-> t/Namespace]
cc/in-ns [t/Sym :-> nil]
cc/import [t/Any :* :-> nil]
])
cc/namespace [(t/U t/Sym t/Keyword) :-> (t/Nilable t/Str)]
cc/ns-name [(t/U t/Sym t/Namespace) :-> t/Sym]
cc/name [(t/U t/Str t/Named) :-> t/Str]
cc/identity (t/All [x] [x :-> x
                        :filters {:then (! (t/U nil false) 0)
                                  :else (is (t/U nil false) 0)}
                        :object {:id 0}])
cc/gensym [(t/? (t/U t/Sym t/Str)) :-> t/Sym]
#?@(:cljs [] :default [
cc/intern [(t/U t/Sym t/Namespace) t/Sym (t/? t/Any) :-> t/AnyVar]
])