Macros for Android

Per Bothner per@bothner.com
Thu Jul 26 07:51:00 GMT 2012


On 07/26/2012 12:29 AM, craven@gmx.net wrote:
> That gives me the following version:
>
> (define-syntax-case
>    do-in-background ()
>    ((_ dib-param dib opu-param opu params)
>     #`(let* ((async-task :: <android.os.AsyncTask>
>                          (object (<android.os.AsyncTask>)
>                                  ((doInBackground dib-param :: <java.lang.Object[]>) :: <java.lang.Object>
>                                    dib)
>                                  ((onProgressUpdate opu-param :: <java.lang.Object[]>)
>                                    opu))))
>         (<android.os.AsyncTask>:execute async-task (apply <java.lang.Object[]> params)))))
>
> which ... gives the error:
>
> test.scm:235:7: missing method name

The problem is that object.scanClassDef doesn't handle
a syntax object - just raw symbols.  This is a bug (maybe not if
you're a super-hard-core hygiene purist).

A work-around is to make sure object.scanClassDef gets a raw
symbol.  The following seems to work:

(defmacro do-in-background (dib-param dib opu-param opu params)
   `(let* ((async-task :: <android.os.AsyncTask>
  		      (object (<android.os.AsyncTask>)
  			      ((#,'doInBackground ,dib-param :: <java.lang.Object[]>) :: 
<java.lang.Object>
  			       ,@dib)
  			      ((#,'onProgressUpdate ,opu-param :: <java.lang.Object[]>)
  			       ,@opu))))
      (<android.os.AsyncTask>:execute async-task (<java.lang.Object[]> 
,@params))))

> Using EXPAND with OBJECTX instead of OBJECT shows that the macro itself
> seems to work fine. Could there be some unfortunate interaction between
> OBJECT and the macro?

I wouldn't say that.  The expand macro does not support ObjectExp
(or from what I can tell ClassExp).  See unrewrite in syntaxutils.scm.
Instead, we end up in the gnu.expr.LambdaExp case, since ObjectExp
(and ClassExp and ModuleExp) inherit from LambdaExp).
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/



More information about the Kawa mailing list