Previous: , Up: Configuring Guile for Guile-CV   [Contents][Index]


Configuring Guile’s raised exception system

Guile’s core raised exception printers call simple-format, which is inadequate for Guile-CV images - or for that matter, for any work that involves very large data structure manipulations - even very small images (see the related footnote of the previous section, it explains how ‘inadequate’ this default is for Guile-CV images).

Unfortunately, Guile does not provide an easy mechanism to alter its core raised exception printers. This leaves us with no other option but making some changes to the module where those are defined, namely the (ice-9 boot-9) Guile’s core module, which then needs to be (re)compiled and (re)installed6.

As the (ice-9 boot-9) Guile’s core module has changed from 2.0, 2.2 to 3.0, and still is subject to change any time in the future, we can’t provide a ‘one patch for all’ solution.

Instead, we describe the steps to manually update your local version. However if you think it is ‘too much’ for you, get in touch with us, and we will guide you or provide a ‘ready to use module’, depending on your version of Guile.

So, let’s first figure out where the (ice-9 boot-9) resides on your system7, in a guile session, enter the following:

(string-append (%package-data-dir) "/" (effective-version))
⇒
$2 = "/opt3/share/guile/3.0"

The above returned value is an example of course, just proceed with the value returned by your system. So, the file we need to edit, in our example, is here:

/opt3/share/guile/3.0/ice-9/boot-9.scm

Edit the above file and:

  1. Search for the line (define format simple-format), and below, add a line containing (define exception-format simple-format), so now your version of the file looks like this:
    (define format simple-format)
    (define exception-format simple-format)
    
  2. Replace all occurences of '(format ' using '(exception-format ' [note and meticulously respect the presence of the leading open paren ’(’ and the trailing space ’ ’ in both the search and replace expressions].

    Save the file.

  3. Compile the file - in the following lines, substitute /opt3 by your $prefix value, 3.0 by your guile (effective-version) as well as $HOME:
    cd /opt3/share/guile/3.0/ice-9
    guild compile boot-9.scm
    -|
    ;;; note: source file /opt3/share/guile/3.0/ice-9/boot-9.scm
    ;;;       newer than compiled /opt3/lib/guile/3.0/ccache/ice-9/boot-9.go
    wrote `$HOME/.cache/guile/ccache/3.0-LE-8-3.A/opt3/share/guile/3.0/ice-9/boot-9.scm.go'
    

    Note that the target (compiled) filename is boot-9.scm.go - not boot-9.go.

  4. Install the compiled file:
    cp $HOME/.cache/guile/ccache/3.0-LE-8-3.A/opt3/share/guile/3.0/ice-9/boot-9.scm.go \
       /opt3/lib/guile/3.0/ccache/ice-9/boot-9.go
    

Finally, once the above is completed, add the following lines8 to your $HOME/.guile or, if you are working in a multi-user environmet, to the file named init.scm in the so-called Guile global site directory (the previous subsection lists the terminal command you need to run to see where that directory is on your system):

(define %n-char-limit 400)
(define %n-char-limit-fmt-expr
  (simple-format #f "~~~a@y" %n-char-limit))

(define (rewrite-fmt fmt tell)
  (let loop ((f "")
             (b 0))
    (let ((next (string-contains-ci fmt tell b)))
      (if next
          (loop (if (or (zero? next)
                        (not (char=? #\~ (string-ref fmt (- next 1)))))
                    (string-append f
                                   (substring fmt b next)
                                   %n-char-limit-fmt-expr)
                    f)
                (+ next 2))
          (string-append f (substring fmt b))))))

(when (defined? 'exception-format)
  (set! exception-format
        (lambda (port fmt0 . args)
          (apply (@ (ice-9 format) format)
                 port
                 (rewrite-fmt (rewrite-fmt fmt0 "~s") "~a")
                 args))))

Feel free to adapt the %n-char-limit value to your own taste.

You are now ready to use Guile-CV!


Footnotes

(6)

Special thanks to Daniel Llorens, who proposed these changes, without which it would just be impossible to work with Guile-CV - or for that matter, any work that involves very large data structure manipulations.

(7)

You need write privileges to modify this module, contact your admin if you’re not in charge of the system you are working on.

(8)

Early versions of Guile-CV used to recommend an exception-format setting based on truncated-print, which works as expected if you are using Guile 2.0 or 2.2, but using Guile 3.0, a raised exception would lead to a series of ‘Unwind-only stack overflow exception’ and exit Guile abruptly.


Previous: Configuring Guile’s repl-print procedure, Up: Configuring Guile for Guile-CV   [Contents][Index]