[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Unintended double-renaming inside nested syntax definitions
From: |
flynn16 |
Subject: |
Unintended double-renaming inside nested syntax definitions |
Date: |
Wed, 9 Jan 2019 07:58:24 +0100 (CET) |
Hello, all:
To avoid typing repeated parameters, I am trying to define a temporary macro
inside a macro definition. Here is a minimal working example.
;; #lang racket
;; (require srfi/9)
;; Guile
(use-modules (srfi srfi-9))
;; Chicken
;; (use (srfi 9))
;; Gauche
;; (use srfi-9)
(define-syntax accept-outer-params
(syntax-rules ()
[(_ name constructor-def pred fields ...)
(begin
(define-syntax my-define
(syntax-rules ()
[(my-define)
(define-record-type name
constructor-def
pred
fields ...)]))
(my-define)
)]))
(accept-outer-params
anime
(make-anime title year)
is-anime?
(title anime-title)
(year anime-year))
When macro (my-define) tries to access the parameters owned by macro
`accept-outer-params`, the original record name does not quite register. This
oddity is also seem in Racket and Gauche.
$ guile
GNU Guile 2.2.3
Copyright (C) 1995-2017 Free Software Foundation, Inc.
Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.
Enter `,help' for help.
scheme@(guile-user)> (load "bug.scm")
scheme@(guile-user)> anime-
anime-9ef486c4698d7f7 anime-year-18f1e33ed1649828
anime-title-5a25865893f9be3
scheme@(guile-user)> make-a
make-anime-24d72f5439f4a18 make-array
make-arbiter make-autoload-interface
CHICKEN Scheme -- works, so is this an improvement or a bug?
$ csi bug.scm
CHICKEN
(c) 2008-2017, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.12.0 (rev 6ea24b6)
linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
compiled 2017-02-19 on yves.more-magic.net (Linux)
; loading bug.scm ...
#;1> anime-title
#<procedure (anime-title83 x87)>
#;2> make-anime
#<procedure (make-anime79 title80 year81)>
Racket -- says `make-anime` is not defined and does not let me reference
`make-anime.0`.
$ racket
Welcome to Racket v6.11.
> (enter! "bug.scm")
"bug.scm"> anime-
anime-title.0 anime-year.0
"bug.scm"> make-a
make-anime.0 make-arity-at-least
Gauche 0.9.5 -- does not run
$ gosh bug.scm
*** ERROR: unbound variable: #<identifier user#anime.6f9f3e00>
While loading "./bug.scm" at line 32
Stack Trace:
_______________________________________
0 anime
[unknown location]
Here is the reference diagram.
(define-syntax accept-outer-params
(syntax-rules ()
[(_ name constructor-def pred fields ...)
(begin \___________________________________
(define-syntax my-define |
(syntax-rules () | cross-scope reference,
[(my-define) | doesn't work
(define-record-type name . . . |
|______________|
. . .
(define-syntax accept-outer-params
(syntax-rules ()
[(_ name constructor-def pred fields ...)
(begin
(define-syntax my-define
__________________________
(syntax-rules () / |
[(my-define n c p f . etc) | same-scope reference,
(define-record-type n c p f . etc)])) | works, but more typing
|__________________|
(my-define name constructor-def pred fields ...))]))
I tried `let-syntax` but it introduces a new scope, and the record definitions
will not be available at the top level, as a result. Any way to define
temporary syntax rules?
-- Flynn
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Unintended double-renaming inside nested syntax definitions,
flynn16 <=