[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: define-module, #:export and export
From: |
yarl baudig |
Subject: |
Re: define-module, #:export and export |
Date: |
Fri, 6 Jan 2023 14:31:43 +0100 (CET) |
>
> That is also my understanding, confirmed by
>
> $ cat lib.scm
> (define-module (lib)
> #:export (test))
>
> (define-syntax test
> (lambda (sintax)
> (syntax-case sintax ()
> ((test id)
> (datum->syntax sintax (free-identifier=? #'id #'thing))))))
>
> $ cat test.scm
> (define-module (main)
> #:use-module (lib)
> #:export (thing)
> )
>
> (display (test thing))
> (newline)
>
> (define thing 5)
>
> $ guile3.0 -L . test.scm
> #f
>
>
> If you comment out #:export (thing), the result changes to #t.
>
> To put it perhaps more simply, the use of #:export causes Guile to
> understand early that there will be a variable 'thing' in this module,
> and makes the identifier 'thing' refer to this variable that is not yet
> defined. However, hygiene implies that you want to be able to use
> keywords as if they were not keywords if they are rebound, e.g. the
> 'else' here doesn't cause the cond clause to be taken:
>
> (let ((else #f)) (cond (#f 'bla) (else 'foo) (#t 'bar)))
> $1 = bar
>
> The way this is done is by comparing with the original identifier given
> to syntax-rules. Technically, they are compared with free-identifier=? .
> This means that a use of the identifier matches the keyword iff both are
> unbound, or both are bound to the same lexical binding. However, this
> isn't the case here, as the keyword in the macro was unbound, but at the
> point of use, it has been bound by #:export.
>
> Honestly, I think it is better to choose a different way of writing
> these macros that avoids this confusing issue. Try defining the
> operations at the same time as the enum so that the macro giving an enum
> member refers to the bindings of the operators. If you give more context
> on what you're trying to do, we could help more.
>
> Best,
> Jean
>
>
Thank you both. I am trying to process this. I (re-)read 6.8 Macros and read
tspl4. I don't understand why you use "datum->syntax".
I heard your suggestion. I am only trying to grasp things for now. I realize I
don't know enough (on guile and on guix) to go on a concrete goal yet.
I need to work more on this in order to understand but I wanted to thank you
for answering that quickly!
- define-module, #:export and export, yarl baudig, 2023/01/04
- Re: define-module, #:export and export, Maxime Devos, 2023/01/04
- Re: define-module, #:export and export, Jean Abou Samra, 2023/01/04
- Re: define-module, #:export and export,
yarl baudig <=
- Re: define-module, #:export and export, Maxime Devos, 2023/01/06
- Re: define-module, #:export and export, Jean Abou Samra, 2023/01/07
- Re: define-module, #:export and export, yarl baudig, 2023/01/08
- Re: define-module, #:export and export, Jean Abou Samra, 2023/01/08
- Re: define-module, #:export and export, yarl baudig, 2023/01/08
- Re: define-module, #:export and export, Jean Abou Samra, 2023/01/08
- Re: define-module, #:export and export, yarl baudig, 2023/01/13