Module 如何找到球拍模块中所有功能的列表?
我知道我可以阅读文档,但因为这需要我将注意力从编辑器和REPL转移开,我希望能够看到我正在使用的模块提供的函数列表 Racket中是否有类似于Ruby的Module 如何找到球拍模块中所有功能的列表?,module,racket,Module,Racket,我知道我可以阅读文档,但因为这需要我将注意力从编辑器和REPL转移开,我希望能够看到我正在使用的模块提供的函数列表 Racket中是否有类似于Ruby的Foo.methods()?该函数提供模块表达式中的名称列表 > (require racket/date) > (module->exports 'racket/date) ;module name is passed not the module '() '((0 (julian/scalinger->strin
Foo.methods()
?该函数提供模块表达式中的名称列表
> (require racket/date)
> (module->exports 'racket/date) ;module name is passed not the module
'()
'((0
(julian/scalinger->string ())
(date->julian/scalinger ())
(find-seconds ())
(date-display-format ())
(date->string ())
(date*->seconds ())
(date->seconds ())
(current-date ())))
参考:
由于module->exports
返回两个值,因此需要define values
来捕获函数列表和宏列表,以便在其他地方使用:
; my-module.rkt
#lang racket
(provide (all-defined-out))
(define-syntax while
#|
Macros do not allow documentation strings
While macro from StackOverflow.
http://stackoverflow.com/questions/10968212/while-loop-macro-in-drracket
|#
(syntax-rules ()
((_ pred? stmt ...)
(do () ((not pred?))
stmt ...))))
(define my-const 9)
(define (prn a)
"Prints the passed value on a new line"
(printf "\n~a" a))
(define (my-func a)
"Another documentation string"
(prn a))
引用于:
;some-other-file.rkt
#lang racket
(require "my-module.rkt")
(define-values (functions-and-constants macros)
(module->exports '"my-module.rkt"))
答复:
> functions-and-constants
'((0 (my-const ()) (my-func ()) (prn ())))
> macros
'((0 (while ())))
如果使用,则可以使用descripe
命令获取更有用的格式化信息:
Welcome to Racket v6.1.0.3.
-> ,describe racket/date
; `racket/date' is a module,
; located at <collects>/racket/date.rkt
; imports: <collects>/racket/base.rkt, <collects>/racket/contract/base.rkt,
; <collects>/racket/promise.rkt.
; direct syntax exports: current-date, date*->seconds,
; date->julian/scalinger, date->seconds, date->string, date-display-format,
; find-seconds, julian/scalinger->string.
欢迎来到Racket v6.1.0.3。
->,描述球拍/日期
; `“球拍/日期”是一个模块,
; 位于/racket/date.rkt
; 导入:/racket/base.rkt,/racket/contract/base.rkt,
; /racket/promise.rkt。
; 直接语法导出:当前日期,日期*->秒,
; 日期->julian/scalinger,日期->秒,日期->字符串,日期显示格式,
; 查找秒,julian/scalinger->string。
谢谢,这很有用。它更类似于IRB上下文,因为xrepl在程序中不可用。我在回答中添加了一个编程使用示例。