Gauche > Archives > 2026/04/15| << 2026/04/14 | Back to the chat room | 2026/04/16 >> |
;; env-lookup-int が異なる変数に同一のmacro(やsyntax?)を返すケースが出てきたため、free-identifier=? が #t になってしまいます
(let-syntax ((foo (syntax-rules ())))
(let-syntax ((bar foo))
(let-syntax ((f (er-macro-transformer
(^ (form rename id=?)
(id=? 'foo 'bar)))))
(f))));; あとinternal error出ました
(letrec-syntax ((foo (syntax-rules ()))
(bar foo))
42)
*** ERROR: [internal] cenv-lookup returned weird obj: (syntax-rules ())
While compiling: foo
While compiling: (letrec-syntax ((foo (syntax-rules ())) (bar foo)) 42)gosh> (let-syntax ((dummy (begin
(define x 42)
(syntax-rules ()))))
#f)
#f
gosh> x
42;; こんなのも
(define-syntax def
(syntax-rules ()
(_ (define foo 1))))
(let ()
(def)
(let-syntax ((dummy (begin
;; コメントを外すと動く
;; (define x #f)
(def)
(syntax-rules ()))))
42))
*** ERROR: syntax-error: the form can appear only in the toplevel: (#<identifier user#define.31a76c0> #<identifier user#foo.31a7680> 1)
While compiling: (begin (def) (syntax-rules ()))
While compiling: (let () (def) (let-syntax ((dummy (begin (def) (syntax-rules ())))) 42))(let-syntax ((dummy (begin
(define x 42)
(syntax-rules ()))))
#f)
===
(let ()
(define x 42)
(let-syntax ((dummy (syntax-rules ())))
#f))##;; こういう理解
(let-syntax ((x (begin
(define x1 42)
...
(syntax-rules ())))
(y (begin
(define y1 42)
...
(syntax-rules ()))))
#f)
===
(let ()
(begin
(define x1 42)
...
(begin
(define y1 42)
...
(let-syntax ((x (syntax-rules ()))
(y (syntax-rules ())))
#f))))ML読んでたら、この挙動の説明と共に https://srfi-email.schemers.org/srfi-147/msg/4958409/ > The reasons for these rules are: > 1) This SRFI should be implementable in R7RS-small. > 2) The rules should be as intuitive as possible. > 3) Sophisticated custom macro transformers (as the one in SRFI 148) とあったので、とにかくR7RS-smallの範囲で実装できることを重視したかった(のとSRFI148で必要になるのかな?)と思いました。これが直感的とは到底思えませんが。#
| << 2026/04/14 | Back to the chat room | 2026/04/16 >> |