[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 |
Hello,
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"))
(x)
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))
(newline))
(define-record-type q
(make-q foo)
q?
(foo foo))
(x (make-q "1"))
The error I got was:
Backtrace:
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
works.
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))
(newline))
(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,
W.
--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.
signature.asc
Description: PGP signature
- Does declaration order matter in guile?,
wolf <=