Node:Intro to Using Guile Modules, Next:, Up:Guile Modules

5.5.1 Intro to Using Existing Modules

Guile comes with a lot of useful modules, for example for string processing or command line parsing. Additionally, there exist many Guile modules written by other Guile hackers, but which have to be installed manually.

Existing modules have to be placed in places where Guile looks for them by default or in colon-separated directories in the environment variable GUILE_LOAD_PATH. When this variable is set, those directories are searched first, then the the default. The following command shows the complete list of directories searched:

guile -c '(write %load-path) (newline)'

Suppose you want to use the procedures and variables exported by the module (ice-9 popen), which provides the means for communicating with other processes over pipes. Add the following line to your currently running Guile REPL or the top of your script file.

(use-modules (ice-9 popen))

This will load the module and make the procedures exported by (ice-9 popen) automatically available. The next step could be to open a pipe to ls and read the contents of the current directory, one line at a time.

(define p (open-input-pipe "ls -l"))
(read-line p)
"total 30"
(read-line p)
"drwxr-sr-x    2 mgrabmue mgrabmue     1024 Mar 29 19:57 CVS"