guile-user
[Top][All Lists]
Advanced

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

Closure, syntax and load ...


From: Manuel Giraud
Subject: Closure, syntax and load ...
Date: 30 Aug 2001 11:50:30 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

Maybe this function is not only Guile specific, but there is something
I don't understand here. Consider two files "foo.scm" and "bar.scm" to
be in the same directory. 

Here is the first version :
 
      ;;; foo.scm
      
      (use-syntax (ice-9 syncase))
      
      ;;; Closure
      (define f 0)
      
      (let ()
        
      ;; a function, ...
      (define square
        (lambda (x)
          (* x x)))
      
      ;; a syntax that call this function, ...
      (define-syntax foo
        (lambda (x)
          (syntax-case x ()
                       ((_ a)
                        (syntax (square a))))))
      
      ;; and, an variable that use this syntax.
      (set! f (foo 6)))
      
      (display f)
      (newline)
      ;;; end of foo.scm

This one works perfectly and display "36" as expected.
Now the second version : 

      ;;; foo.scm
      
      (use-syntax (ice-9 syncase))
      
      ;;; Closure
      (define f 0)
      
      (let ()
        
      ;; a function, ...
      (define square
        (lambda (x)
          (* x x)))
      
      ;; a syntax loaded from "bar.scm" that call this function, ...
      (load "bar.scm")      

      ;; and, an variable that use this syntax.
      (set! f (foo 6)))
      
      (display f)
      (newline)
      ;;; end of foo.scm


      ;;; bar.scm
        
      (define-syntax foo
        (lambda (x)
          (syntax-case x ()
                       ((_ a)
                        (syntax (square a))))))

      ;;; end of bar.scm

This one says me that square is unbound when I use it foo : I really
don't understand this behaviour (I'm running guile 1.4 : maybe too
old).

-- 
Jake:"See those berries? That's our breakfast! See that stream? That's
our drinking water!"
Daria:"See that skeleton? That's our future." 
-From "The Teachings Of Don Jake." 

_Manuel Giraud_



reply via email to

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