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

前端 未结 3 1622
梦谈多话
梦谈多话 2020-12-19 07:38

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. Howeve

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-19 08:24

    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.

提交回复
热议问题