Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
469 views
in Technique[技术] by (71.8m points)

scheme - Is there a way to view a function's source code from within the Racket REPL?

I'm currently trying to dive into Racket/Scheme a bit. I have an instance of the (X)REPL running next to my editor, which helps me immensely to explore the language. However, I can't seem to find an XREPL command or macro (or whatever) which would show me the source code of a function.

All the needed parts seem to be there:

XREPL's describe command knows the file:

-> ,describe string-join
; `string-join' is a bound identifier,
;   defined in racket/string.rkt
;   required directly

and get-collects-search-dirs knows the path:

-> (require setup/dirs)
-> (get-collects-search-dirs)
'(#<path:/home/richard/.racket/5.2.1/collects>
  #<path:/usr/local/lib/racket/collects>)

And on the reflection side of things we have:

-> (procedure-arity string-join)
2

But it all stops short of being useful if all you want to know is how to call the function. Is there a way to access the function's implementation, or at least the parameter names?

Or, which would also work for me - some kind of in-REPL plain text equivalent of the documentation that help opens?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm not sure if this applies to Racket, but in MIT scheme there are a couple built-in procedures that will get you close. (Below, proc just stands for any procedure)

  1. (procedure-arity proc) as you mentioned will give you the number of arguments
  2. (pa proc) will print the argument list
  3. (pp proc) will print the body of the procedure

This will work for many of the built in procedures as well any that you define yourself, but if you try to call any of these on a special form like define or set! you will get an error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...