unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Does declaration order matter in guile?
@ 2023-02-12 18:46 wolf
  2023-02-12 19:52 ` Taylan Kammer
  2023-02-13 17:10 ` Maxime Devos
  0 siblings, 2 replies; 8+ messages in thread
From: wolf @ 2023-02-12 18:46 UTC (permalink / raw)
  To: guile-user

[-- 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 --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-02-14 20:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-12 18:46 Does declaration order matter in guile? wolf
2023-02-12 19:52 ` 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

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).