constructor with pre-allocated memory

Peter Feigl craven@gmx.net
Sat Jul 7 05:58:00 GMT 2012


Hello fellow Schemers!

I have a question regarding Android and the (very nice) kawa extended
syntax for object construction. In Android, if a list is displayed to
the user, the interface gives the programmer either a null-pointer
(meaning the view object has to be constructed from scratch) or an
existing object pointer (meaning this could be filled in with data,
saving the extra garbage collection and new allocation of another
object).
Right now, I just use 

(<android.widget.TextView> context text: "some text" textSize: 12 
                           textColor: someColor)

to create a new object. It would however be much preferable to have some
sort of macro that automatically checks whether a given value is #!null
or not, and fills in the object or creates a new one:

(auto-fill pointer <android.widget.TextView> context text: "hello" ...)

This should expand to

(if (eq? #!null pointer)
    (<android.widget.TextView> context text: "some text" textSize: 12 
                           textColor: someColor)
    (begin
      (pointer:setText "some text")
      (pointer:setTextSize 12)
      (pointer:setTextColor someColor)))

Is this even possible, given the  text: "hello"  syntax automatically
searches for setText and calls that? Does kawa support unhygienic
macros?

I'd be very glad about any comments on how to make this work, it would
provide another major benefit over "normal" java code :)

Thanks for any help,

Peter



More information about the Kawa mailing list