I get the error Ill-formed expression for this syntax definition:
(define-syntax ? (syntax-rules () ((? arg) (let ((val arg)) (display "+++ ") (write 'arg) (display ": ") (write val) (newline) val))))
Can anybody tell me what is wrong? Guile accepts the definition.
Afficher les réponses par date
Are you loading the syntax-rules library before you run this?
Try again with `gsi -:s`.
More information: http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Sp...
On 10/31/11 at 05:23pm, Vok Vojwo wrote:
I get the error Ill-formed expression for this syntax definition:
(define-syntax ? (syntax-rules () ((? arg) (let ((val arg)) (display "+++ ") (write 'arg) (display ": ") (write val) (newline) val))))
Can anybody tell me what is wrong? Guile accepts the definition. _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
To access the "define-syntax" form, you need to start gsi with the option -:s like this
gsi -:s
or, once gsi is loaded, evaluate:
(load "~~lib/syntax-case")
Marc
On 2011-10-31, at 12:23 PM, Vok Vojwo wrote:
I get the error Ill-formed expression for this syntax definition:
(define-syntax ? (syntax-rules () ((? arg) (let ((val arg)) (display "+++ ") (write 'arg) (display ": ") (write val) (newline) val))))
Can anybody tell me what is wrong? Guile accepts the definition. _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
2011/10/31 Marc Feeley feeley@iro.umontreal.ca:
To access the "define-syntax" form, you need to start gsi with the option -:s like this
gsi -:s
or, once gsi is loaded, evaluate:
(load "~~lib/syntax-case")
Is there a reason why this is not part of Gambit Scheme? Is it not recommended to use hygienic macros?
syntax-case does all kinds of things, not just to add syntax-case support. It is essentially a Scheme-to-Scheme compiler in itself. I don't remember exactly what it changes, but I think for one that it doesn't fully support Gambit's DSSSL parameter lists.
On 2011-11-10, at 6:42 AM, Per Eckerdal wrote:
syntax-case does all kinds of things, not just to add syntax-case support. It is essentially a Scheme-to-Scheme compiler in itself. I don't remember exactly what it changes, but I think for one that it doesn't fully support Gambit's DSSSL parameter lists.
Indeed. You can view the syntax-case implementation as offering a new language layer which hides (most of) the syntactic layer offered by Gambit. So when you load syntax-case you get hygienic macros, but you lose things too, in particular the source code is rewritten and the decompilation of code deviates from what the user wrote (variables are renamed, for example, which is a pain when debugging). The comments at the top of lib/syntax-case.scm, copied below, give some details.
Another reason syntax-case is not "built-in" to Gambit is that syntax-case.scm is *HUGE*. Once compiled, it is comparable to the size of the interpreter itself (which contains the whole runtime system and library functions):
% ls -lh lib/syntax-case.o1 gsi/gsi -rwxr-xr-x 1 feeley feeley 3.9M Oct 22 14:56 gsi/gsi -rwxr-xr-x 1 feeley feeley 3.0M Nov 10 10:13 lib/syntax-case.o1
This bloat is unacceptable.
I would like Gambit to have an integrated compact implementation of hygienic macros. I am considering implementing this with all the other R7RS changes, if the new spec is acceptable.
Marc
;; This file can be used to replace the builtin macro expander of the ;; interpreter and compiler. Source code correlation information ;; (filename and position in file) is preserved by the expander. The ;; expander mangles non-global variable names and this complicates ;; debugging somewhat. Note that Gambit's normal parser processes the ;; input after expansion by the syntax-case expander. Since the ;; syntax-case expander does not know about Gambit's syntactic ;; extensions (like DSSSL parameters) some of the syntactic ;; extensions cannot be used. On the other hand, the syntax-case ;; expander defines some new special forms, such as "module", ;; "alias", and "eval-when".
;; You can simply load this file at the REPL with: ;; ;; (load "syntax-case") ;; ;; For faster macro processing it is worthwhile to compile the file ;; with the compiler. You can also rename this file to "gambcext.scm" ;; and put it in the Gambit "lib" installation directory so that it is ;; loaded every time the interpreter and compiler are started. ;; ;; Alternatively, the expander can be loaded from the command line ;; like this: ;; ;; % gsi ~~lib/syntax-case - ;; > (pp (lambda (x y) (if (< x y) (let ((z (* x x))) z)))) ;; (lambda (%%x0 %%y1) ;; (if (< %%x0 %%y1) ((lambda (%%z2) %%z2) (* %%x0 %%x0)) (void)))