This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: evaluating syntax transformer threw unbound location first
- From: Panicz Maciej Godek <godek dot maciek at gmail dot com>
- To: Per Bothner <per at bothner dot com>
- Cc: kawa at sourceware dot org
- Date: Sat, 14 Dec 2013 19:07:54 +0100
- Subject: Re: evaluating syntax transformer threw unbound location first
- Authentication-results: sourceware.org; auth=none
- References: <CAMFYt2ZnTnpc7FXhFhUpcD3=uyyWT+q4nkfNjjPLo-RyBcAMKA at mail dot gmail dot com> <52AC04DB dot 2070700 at bothner dot com>
> You can always add a:
> ex.printStackTrace();
> before the:
> return tr.syntaxError("evaluating syntax transformer '"
>
> I'd also try replacing first by car, to see if the issue
> is the (require 'srfi-1) not working as expected.
Thanks. I did replace everything from srfi with core functions,
and the "unbound location" error was solved (I have to admit
that decoding the error message was a littie bit tricky, because
I thought that the transformer threw unbound location first,
that is, before the evaluation ;] It would be helpful if the
symbol was put in quotes or was otherwise distinguished
typographically)
The macro that I sent had some other mistakes, but after
some corrections I got this:
(define-syntax define-application-views
(lambda (stx)
(syntax-case stx (show)
((define-application-views activity-name . names+views)
(with-syntax ((show (datum->syntax #'define-application-views 'show)))
#`(activity
activity-name
(on-create-view
(letrec (#,@(datum->syntax
stx
(letrec ((range (lambda(start end)
(if (= start end)
'()
`(,start
,@(range (+ 1 start) end))))))
(map (lambda (name+view id)
`(,(car name+view) ::int ,id))
(syntax->datum #'names+views)
(range 0 (length (syntax->datum
#'names+views))))))
(activity-name ::android.widget.ViewFlipper
(view-flipper))
(show
(lambda (view)
((as android.widget.ViewFlipper
activity-name):setDisplayedChild
view))))
#,@(datum->syntax
stx
(map (lambda(name+view)
`((as android.widget.ViewFlipper
,(syntax->datum #'activity-name)):addView
,(cadr name+view)))
(syntax->datum #'names+views)))
(as android.view.View activity-name)))))))))
Now I use the macro in the following way:
(expand/step #'(define-application-views mrok
(short-view
(button text: "Go to view 2"
typeface: android.graphics.Typeface:SERIF
on-click-listener: (lambda (_) (show long-view))))
(long-view
(button text: "Go to view 1"
typeface: android.graphics.Typeface:SANS_SERIF
on-click-listener: (lambda (_) (show short-view)))))
When I expand it using Racket's macro expander, it results with
the following code:
(activity
mrok
(on-create-view
(letrec ((short-view ::int 0)
(long-view ::int 1)
(mrok ::android.widget.ViewFlipper (view-flipper))
(show (lambda (view) ((as android.widget.ViewFlipper mrok)
:setDisplayedChild view))))
((as android.widget.ViewFlipper mrok)
:addView
(button
text:
"Go to view 2"
typeface:
android.graphics.Typeface:SERIF
on-click-listener:
(lambda (_) (show long-view))))
((as android.widget.ViewFlipper mrok)
:addView
(button
text:
"Go to view 1"
typeface:
android.graphics.Typeface:SANS_SERIF
on-click-listener:
(lambda (_) (show short-view))))
(as android.view.View mrok))))
After I manually remove white spaces before :setDisplayedChild and
:addView, it works just as expected. However, when I use Kawa
to expand it, I get the following error:
"no declaration seen for unquote"
It refers to the line of the macro definition containing the code:
,(syntax->datum #'activity-name)):addView
(which is strange, because the unquote is used from within
quasiquote there)
When I expand the code with Kawa's expander (from syntax-utils),
the unquotes indeed remain in the resulting code:
(activity mrok
(on-create-view
(let
((short-view #!undefined) (long-view #!undefined) (mrok #!undefined)
(show #!undefined))
(begin (set short-view 0) (set long-view 1) (set mrok (view-flipper))
(set show
(lambda (view)
((: (as android.widget.ViewFlipper mrok) (quote setDisplayedChild))
view)))
((:
(as android.widget.ViewFlipper
(unquote
(syntax->datum
(let
((#!null
((quote kawa.lang.TemplateScope kawa.lang.TemplateScope.make()))))
((quote
java.lang.Object
kawa.lang.SyntaxTemplate.execute(java.lang.Object[],kawa.lang.TemplateScope))
(quote kawa.lang.SyntaxTemplate@6d3f7281) (quote #!null) #!null)))))
(quote addView))
(button text: Go to view 2 on-click-listener:
(lambda (_) (show long-view))))
((:
(as android.widget.ViewFlipper
(unquote
(syntax->datum
(let
((#!null
((quote kawa.lang.TemplateScope kawa.lang.TemplateScope.make()))))
((quote
java.lang.Object
kawa.lang.SyntaxTemplate.execute(java.lang.Object[],kawa.lang.TemplateScope))
(quote kawa.lang.SyntaxTemplate@6076ab2f) (quote #!null) #!null)))))
(quote addView))
(button text: Go to view 1 on-click-listener:
(lambda (_) (show short-view))))
(as android.view.View mrok)))))
What is the reason of this discrepancy and how could one possibly
overcome it?
Regards,
Panicz