With the current master branch of Gambit, given the files:
==> foo.scm <== (define-macro (hello) '(display "Hello world\n"))
==> foo.sld <== (define-library (foo) (export hello) (import (scheme base) (gambit)) (include "foo.scm"))
The following error occurs:
$ gsi .
(import (foo)) (hello)
*** ERROR IN (stdin)@2.2 -- Unbound variable: foo#hello
Using ##define-macro instead of define-macro has the same effect, as do `gsi -:r7rs .`, using (load "foo.scm") instead of (import (foo)), and using the compiler instead of the interpreter. However, copy/pasting the define-macro form into the REPL works fine. Exporting procedures (instead of macros) works fine. What is the best current practice for exporting macros?
Afficher les réponses par date
On Oct 17, 2019, at 8:14 AM, Lassi Kortela lassi@lassi.io wrote:
With the current master branch of Gambit, given the files:
==> foo.scm <== (define-macro (hello) '(display "Hello world\n"))
==> foo.sld <== (define-library (foo) (export hello) (import (scheme base) (gambit)) (include "foo.scm"))
The following error occurs:
$ gsi .
(import (foo)) (hello)
*** ERROR IN (stdin)@2.2 -- Unbound variable: foo#hello
Using ##define-macro instead of define-macro has the same effect, as do `gsi -:r7rs .`, using (load "foo.scm") instead of (import (foo)), and using the compiler instead of the interpreter. However, copy/pasting the define-macro form into the REPL works fine. Exporting procedures (instead of macros) works fine. What is the best current practice for exporting macros?
Currently Gambit’s define-library is compatible with the R7RS define-library and thus supports macros defined with syntax-rules. So this will work:
==> foo.scm <== (define-syntax hello (syntax-rules () ((_) (display "Hello world\n"))))
If you want to use macros defined with define-macro, you need to put them in the file foo#.scm and use the primitive modules (i.e. foo.scm and foo#.scm files).
We would like to make the two module systems coexist more seamlessly, so any ideas on how to do that are welcome.
Marc
Currently Gambit’s define-library is compatible with the R7RS define-library and thus supports macros defined with syntax-rules. So this will work:
==> foo.scm <== (define-syntax hello (syntax-rules () ((_) (display "Hello world\n"))))
Ah, you explained it before but I forgot this detail. Sorry about that.
The particular place this came up is SRFI 177. Unfortunately, `keyword-call` from the SRFI cannot be implemented using syntax-rules since it should translate ordinary Scheme symbols into SRFI 88 keyword objects that are compatible with Gambit's native keyword argument syntax. This would make it fully interoperable with Gambit-native keyword arguments.
It's possible to do the translation using syntax-case like this:
(symbol->keyword (syntax->datum keyword-as-ordinary-symbol))
define-macro is also good enough if there's an easy way to export the macro.
If you want to use macros defined with define-macro, you need to put them in the file foo#.scm and use the primitive modules (i.e. foo.scm and foo#.scm files).
The practical use case would be people doing (import (srfi 177)) and not caring how the details are implemented. So if there's some way to graft the primitive module onto the library after the fact, or for the (define-library (srfi 177)) form to say that (import (srfi 177)) should also import the primitive module, those would be perfectly fine options. Or if the primitive module can be accessed via (import (srfi 177)) without having a (define-library ...) at all. Whatever works :)
We would like to make the two module systems coexist more seamlessly, so any ideas on how to do that are welcome.
I'm sympathetic to these issues. Making different module systems co-exist is not easy. In some cases it could rule out strict standards conformance if a practical result is desired (e.g. is it conformant to export unhygienic macros from a define-library? things like that.)
On Oct 17, 2019, at 9:04 AM, Lassi Kortela lassi@lassi.io wrote:
Currently Gambit’s define-library is compatible with the R7RS define-library and thus supports macros defined with syntax-rules. So this will work: ==> foo.scm <== (define-syntax hello (syntax-rules () ((_) (display "Hello world\n"))))
Ah, you explained it before but I forgot this detail. Sorry about that.
The particular place this came up is SRFI 177. Unfortunately, `keyword-call` from the SRFI cannot be implemented using syntax-rules since it should translate ordinary Scheme symbols into SRFI 88 keyword objects that are compatible with Gambit's native keyword argument syntax. This would make it fully interoperable with Gambit-native keyword arguments.
It's possible to do the translation using syntax-case like this:
(symbol->keyword (syntax->datum keyword-as-ordinary-symbol))
define-macro is also good enough if there's an easy way to export the macro.
If you want to use macros defined with define-macro, you need to put them in the file foo#.scm and use the primitive modules (i.e. foo.scm and foo#.scm files).
The practical use case would be people doing (import (srfi 177)) and not caring how the details are implemented. So if there's some way to graft the primitive module onto the library after the fact, or for the (define-library (srfi 177)) form to say that (import (srfi 177)) should also import the primitive module, those would be perfectly fine options. Or if the primitive module can be accessed via (import (srfi 177)) without having a (define-library ...) at all. Whatever works :)
That is currently the case… an (import foo) will look for foo.scm, and the (import foo) will expand to
(##demand-module foo) (##include "/the/module’s/path/foo#.scm") ;; if that file exists
We would like to make the two module systems coexist more seamlessly, so any ideas on how to do that are welcome.
I'm sympathetic to these issues. Making different module systems co-exist is not easy. In some cases it could rule out strict standards conformance if a practical result is desired (e.g. is it conformant to export unhygienic macros from a define-library? things like that.)
Expressive power vs. interoperability with other Schemes. All Schemes make the compromise that suits them.
Marc
Has the syntax-case module for Gambit bit-rotted? I know it had trouble interacting with DSSSL lambda-list keywords, but I doubt if it blocks the ordinary kind.
Define-macro is TRULY EVIL and shouldn't be used anywhere you don't absolutely have to, even where it is available. As far as I know, the only other Schemes that have both keyword objects and lack another low-level macro system besides define-macro are S7 and STKlos, neither of which are particularly popular today.
On Thu, Oct 17, 2019 at 10:19 AM Marc Feeley feeley@iro.umontreal.ca wrote:
On Oct 17, 2019, at 9:04 AM, Lassi Kortela lassi@lassi.io wrote:
Currently Gambit’s define-library is compatible with the R7RS
define-library and thus supports macros defined with syntax-rules. So this will work:
==> foo.scm <== (define-syntax hello (syntax-rules () ((_) (display "Hello world\n"))))
Ah, you explained it before but I forgot this detail. Sorry about that.
The particular place this came up is SRFI 177. Unfortunately,
`keyword-call` from the SRFI cannot be implemented using syntax-rules since it should translate ordinary Scheme symbols into SRFI 88 keyword objects that are compatible with Gambit's native keyword argument syntax. This would make it fully interoperable with Gambit-native keyword arguments.
It's possible to do the translation using syntax-case like this:
(symbol->keyword (syntax->datum keyword-as-ordinary-symbol))
define-macro is also good enough if there's an easy way to export the
macro.
If you want to use macros defined with define-macro, you need to put
them in the file foo#.scm and use the primitive modules (i.e. foo.scm and foo#.scm files).
The practical use case would be people doing (import (srfi 177)) and not
caring how the details are implemented. So if there's some way to graft the primitive module onto the library after the fact, or for the (define-library (srfi 177)) form to say that (import (srfi 177)) should also import the primitive module, those would be perfectly fine options. Or if the primitive module can be accessed via (import (srfi 177)) without having a (define-library ...) at all. Whatever works :)
That is currently the case… an (import foo) will look for foo.scm, and the (import foo) will expand to
(##demand-module foo) (##include "/the/module’s/path/foo#.scm") ;; if that file exists
We would like to make the two module systems coexist more seamlessly,
so any ideas on how to do that are welcome.
I'm sympathetic to these issues. Making different module systems
co-exist is not easy. In some cases it could rule out strict standards conformance if a practical result is desired (e.g. is it conformant to export unhygienic macros from a define-library? things like that.)
Expressive power vs. interoperability with other Schemes. All Schemes make the compromise that suits them.
Marc
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list
Has the syntax-case module for Gambit bit-rotted?
It's not usable right now. Gambit has acquired a lot of new features in a short time period so some patience and support from us users is in order :)
I know it had trouble interacting with DSSSL lambda-list keywords, but I doubt if it blocks the ordinary kind.
No knowledge of that. SRFI 177 keyword-lambda needs to be able to expand into (lambda (... #!key ...) ...) unless there is a shortcut that avoids using the `#!key` read syntax. The current define-macro version handles #!key fine. As far as I can tell it has no unintentional variable capture unless the caller has redefined `lambda`.
Define-macro is TRULY EVIL and shouldn't be used anywhere you don't absolutely have to, even where it is available.
A strong message from the captured variable liberation front :)
As far as I know, the only other Schemes that have both keyword objects and lack another low-level macro system besides define-macro are S7 and STKlos
As far as I can tell, Bigloo doesn't have hygienic macros more powerful than syntax-rules. Note that Gambit also has syntax-rules.
If you want to use macros defined with define-macro, you need to put them in the file foo#.scm and use the primitive modules (i.e. foo.scm and foo#.scm files).
Thanks! It was easy to do this way (I put the macros in 177#.scm and added an empty 177.scm so Gambit finds it; not an issue).
On Fri, Oct 18, 2019 at 7:05 AM Lassi Kortela lassi@lassi.io wrote:
As far as I can tell, Bigloo doesn't have hygienic macros more powerful
than syntax-rules. Note that Gambit also has syntax-rules.
I have updated https://bitbucket.org/cowan/r7rs-wg1-infra/src/default/SyntaxDefinitions.md with some derived information like "who has define-macro only", "who doesn't have low-level hygienic macros", etc.
John Cowan http://vrici.lojban.org/~cowan cowan@ccil.org Winter: MIT, / Keio, INRIA, / Issue lots of Drafts. So much more to understand! / Might simplicity return? (A "tanka", or extended haiku)