From: wolf <wolf@wolfsden.cz>
To: guile-user@gnu.org
Subject: Does declaration order matter in guile?
Date: Sun, 12 Feb 2023 19:46:59 +0100 [thread overview]
Message-ID: <Y+k0I0W+HfTYF1N3@ws> (raw)
[-- Attachment #1: Type: text/plain, Size: 2578 bytes --]
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.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2023-02-12 18:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-12 18:46 wolf [this message]
2023-02-12 19:52 ` Does declaration order matter in guile? Taylan Kammer
2023-02-13 8:05 ` Sascha Ziemann
2023-02-13 10:44 ` Dr. Arne Babenhauserheide
2023-02-13 17:07 ` Maxime Devos
2023-02-14 20:00 ` wolf
2023-02-14 20:26 ` Dr. Arne Babenhauserheide
2023-02-13 17:10 ` Maxime Devos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y+k0I0W+HfTYF1N3@ws \
--to=wolf@wolfsden.cz \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).