This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: using lambda to implement one method interface
- From: Sonny To <son dot c dot to at gmail dot com>
- To: Kawa mailing list <kawa at sourceware dot org>
- Date: Sun, 17 Sep 2017 08:38:04 -0700
- Subject: Re: using lambda to implement one method interface
- Authentication-results: sourceware.org; auth=none
- References: <CAJxjsJvHAbQWoV+Y5Lu+JJ=C-g=zYUvAXmHAAzKx_=19SG944g@mail.gmail.com>
this works
(let ((handler (android.os.Handler (android.os.Looper:getMainLooper)))
)
(handler:post (lambda ()
(android.util.Log:i "scm" "run me")))
)
this is non-intuitive. why doesn't it work if i bind the lambda to a
symbol? seems like a bug to me
On Sun, Sep 17, 2017 at 8:32 AM, Sonny To <son.c.to@gmail.com> wrote:
> follwing docs at https://www.gnu.org/software/kawa/Anonymous-classes.html
>
> (let ((handler (android.os.Handler (android.os.Looper:getMainLooper)))
> (runnable (lambda ()
> (android.util.Log:i "scm" "run me"))))
> (handler:post runnable)
> )
>
> that doesn't seem to work. Do I need to give type hints to be able to do this?
>
> I'm getting this error:
>
> #|.....44|# #|.....45|# #|.....46|# #|.....47|# /dev/stdin:46:17:
> warning - type function is incompatible with required type
> java.lang.Runnable
> java.lang.ClassCastException: don't know how to coerce
> gnu.expr.LambdaExp$Closure to java.lang.Runnable
> at gnu.bytecode.ObjectType.coerceFromObject(ObjectType.java:180)
> at gnu.kawa.functions.Convert.apply2(Convert.java:38)
> at gnu.mapping.Procedure2.applyToObject(Procedure2.java:62)
> at java.lang.reflect.Method.invoke(Native Method)
> at gnu.mapping.CallContext$ReflectMethodHandle.invokeExact(CallContext.java:726)
> at gnu.mapping.Procedure.applyToConsumerDefault(Procedure.java:75)
> at java.lang.reflect.Method.invoke(Native Method)
> at gnu.mapping.CallContext$ReflectMethodHandle.invokeExact(CallContext.java:726)
> at gnu.mapping.CallContext.runUntilDone(CallContext.java:586)
> at gnu.mapping.CallContext.getFromContext(CallContext.java:616)
> at gnu.expr.Expression.eval(Expression.java:52)
> at gnu.expr.ApplyExp.apply(ApplyExp.java:161)
> at gnu.expr.LetExp.apply(LetExp.java:72)
> at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:281)
> at gnu.expr.ModuleExp.evalModule(ModuleExp.java:211)
> at kawa.Shell.run(Shell.java:283)
> at kawa.Shell.run(Shell.java:196)
> at kawa.Shell.run(Shell.java:183)
> at kawa.TelnetRepl.apply0(TelnetRepl.java:25)
> at gnu.mapping.RunnableClosure.run(RunnableClosure.java:75)
> at java.lang.Thread.run(Thread.java:764)