Showing posts with label Guile. Show all posts
Showing posts with label Guile. Show all posts

Thursday, March 10, 2011

Building Guile 2.0 on the Mac

Introduction

Guile 2.0 was just released in February so neither Fink nor MacPorts have support for it yet. There's no reason to wait, though. It's easy to build Guile from the source distribution. The only problem is that Mac OS X is missing several of the libraries that Guile needs, so they must be compiled and installed first.

In the step-by-step directions below, I have you rerun configure after each step rather than trying to compile and install all the libraries first. That's because your system may have fewer or more missing libraries than mine and rerunning configure will tell you what you need to do next.

Note that you'll need to be root or use sudo when running make install.

Step-by-step instructions

  1. Go to the Gnu Guile Web site and download the latest stable release (2.0.0 as of this writing).
  2. Untar the source into the directory where Guile will live, change into that directory and run configure. Unless you have a current Gnu multiple precision library installed, configure will return an error saying:
    Gnu MP 4.1 or greater not found, see README
    
  3. If you don't get this error, you already have Gnu MP installed; go on to step 4.

    a. Otherwise, retrieve Gnu MP from the GMP Web site. I used the latest stable release, GMP 4.3.2 but there is also a “performance release,” GMP 5.0.1.

    b. Run configure with the build option:

    ./configure --build=x86_64-apple-darwin10
    

    If you don't specify the build option, the MP library will be built for a generic x86 system and the Guile configure script will fail again with the same error. If x86_64-apple-darwin10 does not describe your system, check the Guile config.log file to see what it's expecting.

    c. Run make check. This will exercise the library and make sure everything was built correctly.

    d. Run make install

  4. Change back to the Guile directory and rerun configure. The next error will tell you the next missing library. I got
    configure: error: GNU libunistring is required, please install it.
    

    a. Retrieve libunistring from the libunistring Web site and untar it into a working directory.

    b. Do the usual configure / make / make install dance to make and install the library.

  5. Return to the Guile directory and rerun configure. This time configure will complain about a missing pkg-config script. If you don't get this error go on to step 6.

    a. Retrieve pkg-script from the pkg-config Wiki.

    b. Untar it into a working directory and run configure / make / make install.

  6. Return to the Guile directory and rerun configure. This time configure will complain about a missing libffi. If you did not get this error, go on to step 7.

    a. Retrieve the library from the libffi Web site.

    b. Untar the library into a working directory and run configure / make / make install.

  7. Return to the Guile directory and rerun configure. The configure script will complain about a missing BDW-gc library.

    a. Go to http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/ and down load the source for Version 7.1. Note that the stable version does not compile on the Mac.

    b. Untar the source into a working directory and do the usual configure / make / make check / make install. At some point (either during the make or the make check you might get an error complaining that the ucontext routines are deprecated and that you need to specify _XOPEN_SOURCE. I did this by editing the source for mach_dep.c and including the statement

    #define _XOPEN_SOURCE
    

    right before the

    #include <ucontext.h>
    
  8. Return to the Guile directory and rerun configure. This time configure should finish normally and you can try compiling Guile. If you get an error about the missing symbol _rl_get_keymap_name, you will need to go to the readline library Web page and get the latest version of the library. Before you build the library, delete or rename the libreadline that is in /usr/lib. That version of the library is the BSD version supplied by Apple and is no longer compatible. Then build and install the new libreadline with the usual configure / make / make install. Return to the Guile directory and run make clean. Then rerun the make. If you don't run the make clean Guile may sigfault when you try to run it. Check out your build by running make check and then do the make install. At this point you should have a working version of Guile 2.0.

Saturday, March 5, 2011

Geiser

Having installed Guile 2.0, I was finally able to try out Geiser. For those who came in late, Geiser is an Emacs mode that provides a Slime-like IDE for Scheme. I've been yearning for something like Geiser for a long time. As I explained in Dragged kicking and screaming to Emacs (Pt. 1) (Pt. 2), I moved from being a lifelong Vi user to Emacs specifically to have a comfortable Lisp/Scheme hacking environment. Slime fills the bill nicely for CL, but until Geiser there was nothing as nice for Guile, my preferred Scheme dialect.

Here are some of the features of Geiser taken from the on-line documentation:

  • Form evaluation in the context of the current file's module
  • Macro expansion
  • File/module loading and/or compilation
  • Namespace-aware identifier completion (including local bindings, names visible in the current module, and module names)
  • Autodoc: the echo area shows information about the signature of the procedure/macro around the point automatically
  • Jump to definition of identifier at point
  • Access to documentation (including docstrings when the implementation supports it)
  • Listings of identifiers exported by a given module
  • Listings of callers/callees of procedures
  • Rudimentary support for debugging (when the REPL provides a debugger [which Guile does, of course —jcs ]) and error navigation
  • Support for multiple, simultaneous REPLs

Another useful feature is that Geiser starts automatically as soon as you enter a scheme buffer. You can then evaluate whatever portion of the buffer you like and a quick C-c C-z pops you into the REPL—very nice.

I've just started playing around with Geiser but so far everything looks well done. The only problem I've found is that Geiser does not load the .guile file and there isn't any way of making it do so. The idea is that you should use the .guile-geiser file instead, but that doesn't work for me. That's presumably because my .guile loads a reasonably complex environment including my version of autoload functions. I was able to work around this problem by putting a local copy of geiser-guile.el in my init.el file after the form loading geiser. In this copy, I removed the -q switch in the geiser-guile--parameters function by replacing the line

"-q" "-L" ,(expand-file-name "guile/" geiser-scheme-dir)

with the line

"-L" ,(expand-file-name "guile/" geiser-scheme-dir)

I wrote and submitted a patch to allow the -q switch to be a configuration option, so perhaps the problem will go away in future versions.

If you're a Guile user, Geiser is well worth trying out. I think it's better than anything else that's available for Guile.

Update: Fixed broken links
Update 2: The newest version of Geiser now supports loading .guile