Finding function definitions?

35 views
Skip to first unread message

Tobin Fricke

unread,
Aug 21, 2005, 3:19:13 PM8/21/05
to si...@googlegroups.com
Is there an easy way to find the definition of a given function, other
than grepping through the .scm files? For instance, if I want to look at
the implementation of "partial" or "D", is there an easy way to find it?

Secondly, in scmutils, we can do something like

(define g (literal-function 'g (-> (X Real Real) Real)))

Then we can do something like (print-expression g) and the output is
simply, "g". Is there a way to ask scmutils to print everything it knows
about a function, such as in this case something like "g: Real X Real -->
Real"?

thanks,
Tobin


Tobin Fricke

unread,
Aug 22, 2005, 11:06:55 AM8/22/05
to si...@googlegroups.com
On Sun, 21 Aug 2005, Tobin Fricke wrote:

> Is there an easy way to find the definition of a given function, other
> than grepping through the .scm files? For instance, if I want to look at
> the implementation of "partial" or "D", is there an easy way to find it?

I should have RTFM. Here's from "beginner.txt":

Documentation

There are important sources of documentation that you should know
about. The Scheme system is extensively documented using the Emacs
info system. To get to the info system, type C-h i.

If at any time in a Scheme-mode buffer you want to know the possible
completions of a symbol, just type C-M-i (or M-<tab>). This will pop
up an Edwin window that shows all symbols known by the system
beginning with your initial segment.

You may also want to know the arguments to a procedure. If the cursor
is after the procedure name in an expression, you can type M-A
(meta-shift-a) and a description of the arguments will appear in the
Edwin command-line minibuffer (at the bottom of your Edwin window).

If you want to see the definition of any procedure (including any
non-primitive system procedure) you may use the pretty printer (the pp
procedure). For example:

(pp fib)
(named-lambda (fib n)
(if (< n 2)
n
(+ (fib (- n 1)) (fib (- n 2)))))

(pp Lagrangian->Hamiltonian)
(named-lambda (Lagrangian->Hamiltonian-procedure the-Lagrangian)
(lambda (H-state)
(let ((t (time H-state))
(q (coordinate H-state))
(p (momentum H-state)))
(define (L qdot)
(the-Lagrangian (up t q qdot)))
((Legendre-transform-procedure L) p))))

The prinout from pp may not be exactly what you typed in, because the
internal representation of your procedure may be "compiled".

--tobin
Reply all
Reply to author
Forward
0 new messages