[Prev][Next][Index][Thread]

Re: DUIM: define frame q?



On Mon, 06 Dec 1999 16:31:56 -0700, in comp.lang.dylan you wrote:

> Suppose I have a define frame with a table, like:
> 
> define frame <template-frame> (<simple-frame>)
>   pane main-pane (frame)
>   make (<table-control>, ...);
> 
> What I want to do is provide keyword arguments for the table via the
> frame instantiation, like:
> 
> start-frame (make (<template-frame>, 
>                                      headings: my-headings, 
>                                      generators: my-generators, 
>                                      items: my-items));
> 
> and have the passed in arguments be used for the headings:, generators:,
> and items: arguments to make (<table-control>). But I can't figure out a
> straightforward syntax for this.
> 
> The 3 alternatives I have thought of:
> 
> 1) stuff the values into global variables that are referenced in the
> define frame (YUCK!)
> 
> 2) don't use define frame; build the frame using nested calls to make
> and passing the values to make (<table-control>) where appropriate (kind
> of complicated)
> 
> 3) create my own macro???
> 
> Part of my problem is that I haven't worked through the multiple levels
> of macro expansion kicked off by define frame. So I don't understand the
> underlying classes/methods generated and how they fit together.

OK so the first thing to understand is that the "pane clause" defines a
function for filling in a slot. The parameter list for the function is the
thing in parens. So when creating the pane you are given the frame object.

Its now just a matter of connecting the dots:

	(.) you want to give the options as keyword arguments
	    when making the frame

	(.) you want to use that information to build the table control

	(.) you have access to the frame object when building the table
	    control

=> (.) put the info in slots in the frame

	define frame <template-frame> (<simple-frame>)
          slot my-headings = #f, init-keyword: headings:;
	  pane main-pane (frame)
	    make (<table-control>, headings: frame.my-headings, ...);
	...

Of course having a slot for each argument you want to pass in to make the
subordinate pane can be expensive, so you could put all the frame's keyword
arguments into a slot (with an initialize method) and pull them out as
required:

	define frame <template-frame> (<simple-frame>)
          slot frame-initargs = #();
	  pane main-pane (frame)
	    make (<table-control>, headings: get-initarg(frame, headings:),
	          ...);
	...
	
Or you could use a hack and assume that inappropriate keyword arguments are
not checked and do something like:

	define frame <template-frame> (<simple-frame>)
          slot frame-initargs = #();
	  pane main-pane (frame)
	    apply(make, <table-control>, frame-initargs(frame));
	...
	

Or you could get the user to put all the table-control init-args in a special
nested initarg:

	define frame <template-frame> (<simple-frame>)
          slot table-initargs = #(), init-keyword: table-initargs:;
	  pane main-pane (frame)
	    apply(make, <table-control>, table-initargs(frame));
	...

Etc.

__Jason

(FTR LispWorks CAPI has a special syntax for mapping frame initargs to pane
initargs.)


Follow-Ups: References: