[plt-scheme] using macros to create new widgets in MrEd
Stephen De Gabrielle wrote:
> Hi, I've been fiddling with composing widgets, and I thought I'd have
> a try at making a macro to make the code a little easier to read;
>
> I've come up with a solution that allows me to specify a container and
> two child widgets in the form
> ;; make-widget : classname container-class function function -> class
>
> I'd prefer to have something like;
> ;; define-widget new-widget-classname container-class container-args
> sub-widget1% args1 subwidget2% args2)
> eg
> (define-widget double-button% horizontal-panel% '() button% '([label
> label1]) button% '([label label1] [stretchable-width #t]))
>
> My problem is I can't work out how to use the args1 list.
> As you can see below I have tried apply as in
> (apply new sub-widget% (parent this) sub-widget-args)
> but 'new' isn't a function.
>
> Any suggestions?
>
> Cheers,
> Stephen
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
(define-syntax define-widget1
(syntax-rules ()
((_ new-widget-classname (args ...))
(new new-widget-classname args ...))))
(define-syntax define-widget2
(syntax-rules ()
((_ new-widget-classname args)
(new new-widget-classname . args))))