Android REPL - add* syntax-sugar not available in constructor

Per Bothner per@bothner.com
Tue Jan 31 23:30:00 GMT 2012


On 01/31/2012 04:15 AM, teyc wrote:
> (*activity*:runOnUiThread
>    (runnable
>      (lambda ()
>        (try-catch
>          (*activity*:setContentView
>            (android.widget.LinearLayout *activity*
>              orientation: android.widget.LinearLayout:VERTICAL
>              view: (android.widget.TextView *activity* text: "Hello")
>              view: (android.widget.Button *activity* text: "Click"
>                     on-click-listener:
>                       (lambda (v) ((android.widget.Toast:makeText *activity*
> "Clicked Me" andoird.widget.Toast:LENGTH_LONG):show))))
>          (e java.lang.Exception
>            (android.util.Log:v "kawa-hello" e))))))
>
> Is this is hard limitation, since kawa has to generate an anonymous class on
> the fly to handle the event?

Yes, at least as currently implemented.

However, it should be doable to use java.lang.reflect.Proxy, as long as the
requested type is an interface (rather than an abstract class).  The 
idea would
be to write a utility class ProcedureInvocationHandler that implements
InvocationHandler by calling applyN on the procedure.

> Is there anyway I can use a precompiled MouseAdapter class that would invoke
> a closure? I tried something like the following:
>
>
> ; a job that is posted on a UI thread.
> (define-simple-class Job (java.lang.Runnable)
>      (result type: java.lang.Object init-value: #!null)
>      ;((*init*) #!void
>      ;   (display "Init Job"))
>      (form init-keyword: form:)
>      ((*init* (form0 :: java.lang.Object))
>          (set! form form0))
>      ((run) :: #!void
>          (synchronized (this)
>              (if (not (eq? #!null form))
>                  (set! result (eval form (interaction-environment))))
>              (sleep 2.0)
>              (notify))
>      ))
>
> but the verifier didn't like it (perhaps the code is too dynamic?)

I don't why the verifier didn't like it, but using eval seems wrong.
Why not use apply instead?

It should be possible to have a pre-built MouseAdapter class, and
somehow tell the compiler to use it.  My preferred way to do this
would be adding something like Scala's "views": A declaration telling Kawa
that when it has an expression of type T in a context requiring an
interface I then giving a recipe (function) for converting T to I.
But I don't have time for that at this time.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/



More information about the Kawa mailing list