evaluating syntax transformer threw unbound location first
Panicz Maciej Godek
godek.maciek@gmail.com
Sat Dec 14 01:25:00 GMT 2013
Hello,
I've been trying to comfort myself with a macro to
describe apps for android. After some trials and errors
I concluded that the resulting code should look more
or less like this:
(activity
app
(on-create-view
(let* ((short-view ::int 0)
(long-view ::int 1)
(app ::android.widget.ViewFlipper
(view-flipper))
(show (lambda(view)
((as android.widget.ViewFlipper app):setDisplayedChild
view))))
(app:addView
(button text: "Go to view 2"
typeface: android.graphics.Typeface:SERIF
on-click-listener: (lambda _ (show long-view))))
(app:addView
(button text: "Go to view 1"
typeface: android.graphics.Typeface:SANS_SERIF
on-click-listener: (lambda _ (show short-view))))
(as android.view.View app))))
it works fine, but I wished that the code could be generated
from the following, more concise description:
(define-application-views app
(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)))))
I therefore wrote a macro to help me achieve this. I'm
not particularly fluent with syntax-case macros, but since
there were some strange issues regarding define-macro
(it was problematic to use "(this)" in the code generated
by them), I had to resort to the syntax-case system.
I eventually came up with the following code:
(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
(let* (#,@(datum->syntax
stx
(map (lambda (name+view id)
`(,(first name+view) ::int ,id))
(syntax->datum #'names+views)
(iota (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
#'activity-name):addView
,(second name+view)))
(syntax->datum #'names+views)))
(as android.view.View activity-name)))))))))
I also defined a few helper macros, so to make the example
complete (albeit in reverse), I hereby provide the full header:
(require 'android-defs)
(require 'srfi-1)
(require 'srfi-2)
(define-syntax define-syntax-rule
(syntax-rules ()
((_ (name args ...) body)
(define-syntax name
(syntax-rules ()
((name args ...)
body))))))
(define-syntax-rule (button args ...)
(android.widget.Button (this) args ...))
(define-syntax-rule (text-view args ...)
(android.widget.TextView (this) args ...))
(define-syntax-rule (view-flipper args ...)
(android.widget.ViewFlipper (this) args ...))
The macro did work with the syntax-case system in Guile Scheme,
but when I tried to build it (using the "android-kawa" framework
that I've found here: https://github.com/abarbu/android-kawa),
I got the following error:
.../app.scm:87:1: evaluating syntax transformer
'define-application-views' threw unbound location first
is there any way I could introspect that error further?
Thanks in advance,
Panicz
More information about the Kawa
mailing list