gpt4 book ai didi

clojure - Clojure 中的自省(introspection)

转载 作者:行者123 更新时间:2023-12-03 15:09:39 25 4
gpt4 key购买 nike

在 Clojure 中进行自省(introspection)的最佳方法是什么?有没有类似 Python 的 dir功能?我对查找与我交互操作的 java 类上可用的方法特别感兴趣,但我也有兴趣找出 Clojure 中与自省(introspection)相关的任何可用方法。

最佳答案

Michiel Borkent 和 Dave Ray 涵盖了互操作选项。

为了发现 Clojure 函数,clojure.repl 中有几个选项。命名空间(默认情况下可能已经引用到您的 REPL 中)。

dir :

=> (require 'clojure.set)
nil
=> (dir clojure.set)
difference
index
intersection
join
map-invert
project
rename
rename-keys
select
subset?
superset?
union

apropos :
=> (apropos #"^re-")
(re-pattern re-matches re-matcher re-groups re-find re-seq)

find-doc :
=> (find-doc #"^re-")
-------------------------
clojure.core/re-find
([m] [re s])
Returns the next regex match, if any, of string to pattern, using
java.util.regex.Matcher.find(). Uses re-groups to return the
groups.
-------------------------
clojure.core/re-groups
([m])
Returns the groups from the most recent match/find. If there are no
nested groups, returns a string of the entire match. If there are
nested groups, returns a vector of the groups, the first element
being the entire match.
-------------------------
....

关于clojure - Clojure 中的自省(introspection),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8435555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com