[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Does declaration order matter in guile?

From: wolf
Subject: Does declaration order matter in guile?
Date: Sun, 12 Feb 2023 19:46:59 +0100


I had encountered interesting thing yesterday, which challenged my
understanding of guile (scheme). I always assumed that order of definitions in
scheme does not matter, as long as everything if defined when it is running.

So this should (and does) work:

    (define (x) (y))
    (define (y) (display "foo\n"))

However, then I wanted to used SRFI-9. I did use similar pattern, and it
failed. The test code for that is:

    (use-modules (srfi srfi-9))
    (define (x y)
      (display (foo y))
    (define-record-type q
      (make-q foo)
      (foo foo))
    (x (make-q "1"))

The error I got was:

    In ice-9/boot-9.scm:
      1752:10  7 (with-exception-handler _ _ #:unwind? _ # _)
    In unknown file:
               6 (apply-smob/0 #<thunk 7fa9a5866340>)
    In ice-9/boot-9.scm:
        724:2  5 (call-with-prompt ("prompt") #<procedure 7fa9a5872080 …> …)
    In ice-9/eval.scm:
        619:8  4 (_ #(#(#<directory (guile-user) 7fa9a5869c80>)))
    In ice-9/boot-9.scm:
       2836:4  3 (save-module-excursion #<procedure 7fa9a585b300 at ice-…>)
      4388:12  2 (_)
    In /tmp/q/srfi-9.scm:
         4:11  1 (x _)
         4:11  0 (x _)
    /tmp/q/srfi-9.scm:4:11: In procedure x:
    Wrong type to apply: #<syntax-transformer foo>

When I move the (define-record-type ...) call above (define (x...) it starts to

Also, I could not help to notice that when I use R6RS records it does work
regardless of the order:

    (use-modules (rnrs records syntactic))
    (define (x y)
      (display (q-foo y))
    (define-record-type q (fields foo))
    (x (make-q "1"))

So, I have few questions I would like to ask:

1. When does order matter? What is going on here?
2. Why does guile recommend SRFI-9 over the R6RS records? They seem less
   verbose and more robust. At least to novice like me.
3. What does guile implement by default? There are --r6rs and --r7rs arguments,
   what scheme is used when neither is supplied? R5RS? Sorry if this is stupid
   question, the scheme landscape seems... complicated.
4. Is the (install-r6rs!) global and affecting all reading from that point on
   or is it scoped to the file being currently read? I ask because I am curious
   if I can mix files using R6RS and R7RS in one program.

Thank you very much,

There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]