How do I find what module to import for a given binding?

I’m trying to use sin but I have no idea what module I need to import to use it. I can find a reference to it in the Guile Reference Manual but that doesn’t mention the module sin is in. How do I figure this out?

In R7RS-small, sin is provided by the (scheme inexact) module. Refer to the spec for full details.

In Guile, sin is part of the default environment, implicitly via (guile) for “impure” modules. However, Hoot 0.4.1 doesn’t implement this module yet. Hoot 0.5.0 will have some amount of Guile compatibility in this regard.

Hope this helps!

Thanks for answering that specific case of the question, @dthompson , but how about the general case? When looking at some code that uses a function foo, how do working scheme programmers find out which module it came from?

“Ask Dave T.” has worked several times now, but it doesn’t seem like a scalable approach :slight_smile:

When you’re at the Guile REPL (i.e. not compiling with Hoot), you can use the ,apropos command to search for a name and get information about bindings that match.

For example, here’s a REPL session where I import SRFI-1 and then check where the reduce procedure comes from:

scheme@(guile-user)> ,use (srfi srfi-1)
scheme@(guile-user)> ,apropos reduce
(srfi srfi-1): reduce-right	#<procedure reduce-right (f ridentity lst)>
(srfi srfi-1): reduce	#<procedure reduce (f ridentity lst)>

Run ,help to get a full list of REPL commands. Again, this is for development with the Guile VM only where you have an interactive session.

Hm. It looks like you have to tell the computer the answer (,use (srfi srfi-1)) before you ask the question (,apropos reduce).

Suppose I’ve got a body of scheme code, and a function call to (blort) on line 125 of file xyz.scm. How do I find where blort is defined?

Do working scheme programmers really manually copy all the use-module stuff from the top of xyz.scm into the repl and then ask ,apropos blort?

No, that’s not how we do things. I was only importing a module as a demonstration to get some non-default stuff into my REPL environment but I suppose that just caused additional confusion. I’ll try another way.

Let’s say that module (bloop) imports and calls blort from somewhere. To find out exactly where, I’d so this:

scheme@(guile-user)> ,m (bloop)
scheme@(bloop)> ,a blort
(zort): blort	#<procedure blort (x)>

I use ,m to enter the (bloop) module and then run ,a (shorthand for ,apropos) to discover that blort comes from the zort module.

1 Like