* Strange error from syntax transformer
@ 2015-09-02 22:40 Panicz Maciej Godek
2015-09-03 7:02 ` Mark H Weaver
0 siblings, 1 reply; 2+ messages in thread
From: Panicz Maciej Godek @ 2015-09-02 22:40 UTC (permalink / raw)
To: guile-user@gnu.org
[-- Attachment #1: Type: text/plain, Size: 3056 bytes --]
Hi,
As I wrote in another post, I've cut out some more mature pieces of my
personal library to a separate module. The module uses (ice-9 match)
library and replaces the lambda binding with mlambda (the greek letter came
from emacs, but they're just regular words):
(define-syntax mlambda
(λ (stx)
(syntax-case stx ()
((_ (first-arg ... last-arg . rest-args) . body)
(and (every identifier? #'(first-arg ... last-arg))
(or (identifier? #'rest-args) (null? #'rest-args)))
#'(λ (first-arg ... last-arg . rest-args) . body))
((_ arg body ...)
(or (identifier? #'arg) (null? #'arg))
#'(λ arg body ...))
((_ args body ...)
#'(match-lambda* (args body ...)))
)))
For the reason explained below, it also wraps the regular "lambda" form as
"primitive-lambda":
(define-syntax primitive-lambda
(syntax-rules ()
((_ . whatever)
(λ . whatever))))
So I have another module that uses this one. It defines, among the other
things, the following macro:
(define-syntax supply
(syntax-rules ()
((_ (((<to-do-something-with> . <args>) <do-what> ...) ...) . <actions>)
(let ((handlers (make-hash-table))
(unsupported (λ details
(apply throw 'unsatisfied-demand
details))))
(hash-set! handlers (quote <to-do-something-with>)
(λ <args> <do-what> ...))
...
(catch 'demand
(λ () . <actions>)
(primitive-lambda (key go-on demand . the-args)
(go-on (apply (hash-ref handlers demand unsupported)
the-args))))))))
it requires a "demand" function to be useful:
(define (demand to-do-something-with . args)
(call/cc (λ (go-on)
(apply throw 'demand go-on to-do-something-with args))))
When I try to expand that macro, e.g. by using the following form, it works
alright.
(let ((people '()))
(supply (((free person)
(set! people (cons person people))))
(let ((the-person 'Nelson-Mandela))
(demand 'free the-person)))
people)
However, if I replace the primitive-lambda with regular lambda (which
should refer to mlambda from (ice-9 nice-9)), I get the following error:
ice-9/psyntax.scm:728:15: In procedure join-wraps:
ice-9/psyntax.scm:728:15: In procedure car: Wrong type argument in position
1 (expecting pair): #(syntax-object the-args
((m-o6xyC1TbsJRwjxP9561LW$-9754 top) #(ribcage \
() () ()) shift #(ribcage #(dummy <to-do-something-with> <args> <do-what>
<actions>) #((m-o6xyC1TbsJRwjxP9561LW$-9334 top) (top) (top) (top) (top))
#("l-o6xyC1TbsJRwjxP\
9561LW$-9339" "l-o6xyC1TbsJRwjxP9561LW$-9340"
"l-o6xyC1TbsJRwjxP9561LW$-9341" "l-o6xyC1TbsJRwjxP9561LW$-9342"
"l-o6xyC1TbsJRwjxP9561LW$-9343")) #(ribcage () () ()) #(ri\
bcage #(x) #((m-o6xyC1TbsJRwjxP9561LW$-9334 top))
#("l-o6xyC1TbsJRwjxP9561LW$-9336"))) (hygiene extra common))
Anyone has a clue what is going on here?
Regards,
M.
[-- Attachment #2: Type: text/html, Size: 4232 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Strange error from syntax transformer
2015-09-02 22:40 Strange error from syntax transformer Panicz Maciej Godek
@ 2015-09-03 7:02 ` Mark H Weaver
0 siblings, 0 replies; 2+ messages in thread
From: Mark H Weaver @ 2015-09-03 7:02 UTC (permalink / raw)
To: Panicz Maciej Godek; +Cc: guile-user
Panicz Maciej Godek <godek.maciek@gmail.com> writes:
> However, if I replace the primitive-lambda with regular lambda (which
> should refer to mlambda from (ice-9 nice-9)), I get the following error:
>
> ice-9/psyntax.scm:728:15: In procedure join-wraps:
> ice-9/psyntax.scm:728:15: In procedure car: Wrong type argument in position
> 1 (expecting pair): #(syntax-object the-args
[...]
This turned out to be a bug in our macro expander, introduced in commit
aa3819aa343b0ba39b3e6ca4fbf90f15a8e36cdf and fixed on the stable-2.0
branch by commit 3bda6eb9dfb14cf088e58de99825296a171ff4bf.
Thanks!
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-09-03 7:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-02 22:40 Strange error from syntax transformer Panicz Maciej Godek
2015-09-03 7:02 ` Mark H Weaver
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).