如何列出命名空间的函数? [英] How to list the functions of a namespace?

查看:95
本文介绍了如何列出命名空间的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何列出Clojure命名空间的所有函数。我做了一些研究,但我还没有。我已经找到了如何使用show方法列出一个Java类的方法:

I would like to know how to list all functions of a Clojure namespace. I've done some research but I'm not there yet. I already found out how to list the methods of a Java class using the show method:

(show java.awt.Graphics)

要列出Clojure命名空间的函数,我已经尝试过show方法,如下所示:

To list the functions of a Clojure namespace I've tried the show method like this:

(show 'clojure.contrib.repl-utils)

这显示了一些Java类方法,但不是我正在寻找的 doc show

This shows some Java class methods, but not the ones I'm looking for like doc and show. How can I get those?

推荐答案

我通常叫

(keys (ns-publics 'foo))

由命名空间导出 foo ;例如 clojure.contrib.monads 这会返回

to list Vars exported by the namespace foo; e.g. for clojure.contrib.monads this returns

(defmonad censor m-when-not m+write+m maybe-m maybe-t ...)

code> ... 代表了更多)。

(the ... stands for quite a lot more).

更广泛地说, ns - 其中列出了Vars by命名空间,并附加了一些附加条件:

More generally, there's a bunch of functions whose names start in ns- which list Vars by namespace, with certain additional criteria attached:


  1. p> ns-map - all的最一般函数返回由符号(实际上不是命名空间限定的符号)键入的映射,其中对应于每个符号的值
  1. ns-map -- the most general function of all, returns a map keyed by symbols (non-namespace-qualified symbols actually), where the value corresponding to each symbol is the Var or class that symbol resolves to in the given namespace.

ns-interns - 在给定的命名空间中符号解析的Var或类。例如 ns-map ,但仅包括在给定命名空间中内置的Vars(与来自可从给定命名空间访问的其他命名空间的Vars相反,因为使用参考调用或来自 clojure.core 的Vars的隐式引用。

ns-interns -- like ns-map, but includes only the Vars interned in the given namespace (as opposed to Vars from other namespaces which are accessible from the given namespace due to a use or refer call or the implicit referral of Vars from clojure.core.

ns-publics - like ns-interns ,但仅包含非私有变量。

ns-publics -- like ns-interns, but includes only the non-private Vars.

ns- imports ns-map ,但仅包含值对应于Java类的条目。

ns-imports -- like ns-map, but includes only the entries whose values correspond to Java classes.


b $ b

还有 ns-aliases ,其中列出了在引用来自其他命名空间的Vars时可用作速记别名的符号;例如如果调用(require'[clojure.contrib.math:as math]) ns-aliases 使用 math (符号)的键,其值将是实际的命名空间 clojure.contrib.math 。这些映射不包括在 ns-map 返回的映射中。

There's also ns-aliases which lists symbols which can be used as shorthand aliases when referring to Vars from other namespaces; e.g. if you call (require '[clojure.contrib.math :as math]), ns-aliases will include an entry with the key of math (the symbol), whose value will be the actual namespace clojure.contrib.math. These mapping are not included in the map returned by ns-map.

这篇关于如何列出命名空间的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆