public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Problem with macro that expands to define-simple-class
@ 2012-09-05  8:40 craven
  2012-09-05 16:08 ` Per Bothner
  0 siblings, 1 reply; 2+ messages in thread
From: craven @ 2012-09-05  8:40 UTC (permalink / raw)
  To: kawa mailing list

I've run into a problem with a syntax-rules macro that expands to a
DEFINE-SIMPLE-CLASS statement:

(define-syntax define-simple-database-helper 
  (syntax-rules ()
    ((_ name log-name version (table-name create-statement) ...)
     (define-simple-class name
  (<android.database.sqlite.SQLiteOpenHelper>)
       ((*init* (context :: <Context>))
       (invoke-special <android.database.sqlite.SQLiteOpenHelper> (this) '*init* context log-name #!null version))
       ((onCreate (db :: <android.database.sqlite.SQLiteDatabase>)) ::
  void
  (for-each (lambda (sql)
                (db:execSQL sql))
                              (list create-statement ...)))
       ((onUpgrade (db :: <android.database.sqlite.SQLiteDatabase>) (old-version :: int) (new-version :: int))
  (for-each (lambda (name)
                (db:execSQL (format "drop table if exists ~a" name)))
                              (list table-name ...))
                              (onCreate db))))))

Usage would be like this:

(define-simple-database-helper "games" "database" 1
  ("categories" "create table categories (_id text primary key, name text not null);")
  ("games" "create table games (_id text primary key, name text not null);"))

But loading the definition into svn kawa as of right now and using
(require 'syntax-utils) and EXPAND shows:

(let ((games #!undefined))
 (set games (lambda (*init* onCreate onUpgrade) #!null)))

Is there a way to write this macro (using syntax-rules)?

Thanks for any help!

Peter

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Problem with macro that expands to define-simple-class
  2012-09-05  8:40 Problem with macro that expands to define-simple-class craven
@ 2012-09-05 16:08 ` Per Bothner
  0 siblings, 0 replies; 2+ messages in thread
From: Per Bothner @ 2012-09-05 16:08 UTC (permalink / raw)
  To: craven; +Cc: kawa mailing list

On 09/05/2012 01:40 AM, craven@gmx.net wrote:
> I've run into a problem with a syntax-rules macro that expands to a
> DEFINE-SIMPLE-CLASS statement:

First, note that the expand utility has to do a complicated job of
"decompiling" a macro expansion, and the implementation is incomplete.
Spcifically, I don't believe it handles ClassExp, which is what
define-simple-class expands to.

Secondly, I notice you bind the macro parameter name to the string "games".
This is used for the class name.  Kawa allows this, but it probably
shouldn't, and it has not been tested much if at all.  Instead use
an identifier (symbol):

(define-simple-database-helper games "database" 1 ...)
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-09-05 16:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-05  8:40 Problem with macro that expands to define-simple-class craven
2012-09-05 16:08 ` Per Bothner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).