On Mon, Jul 25, 2011 at 1:50 PM, Justin Tirrell <[email protected]>
> Currently, I have written it with a variable that I can use in my
grid
> locale and increment after each query. For example:
>
> ".('mygrid',(":currgrid),' =:conew ''jgtkgrid''')
> NB. currgrid is an integer that is incremented after each query
> ".('create__mygrid',":currgrid)
> ".('handler__mygrid',(":currgrid),' =: 3 : handlerdef')

I do not know what problem you are trying to solve by using
auto-increment names to hold your locales.  So I cannot suggest an
alternative there.

That said, I can suggest a cleaner way of doing what you are currently doing.

First, you can define a wrapper for getting at the names you are using:

mygrid=:3 :0
  'mygrid',":y
:
  x,'__mygrid',":y
)

Then, you can rephrase the above sentences like this:

   (mygrid currgrid) =:conew 'jgtkgrid'
   NB. currgrid is an integer that is incremented after each query
   ('create' mygrid currgrid)~ ''
   ('handler' mygrid currgrid)=: 3 :handlerdef

The key insights here are:

1. You can use a string to refer to a variable being assigned.
2. You can use a string to refer to a verb to be consumed.

For assignment, when using an expression to compute the name you are
assigning to, you should put that expression in parenthesis.

The operator which lets you use a string to refer to a verb name is ~

That said,
   ('handler' mygrid currgrid)=: 3 :handlerdef

would probably be better handled by creating a definition for handler
in a class that inherits from jgtkgrid.  In otherwords:

coclass'mygtkgrid'
  coinsert'jgtkgrid'
  handler=: handlerdef_base_ f.

Though it would be clearer, I think, to use the literal definition of
handlerdef_base_ instead of putting it where you do not need it and
referring to it indirectly.

Also note that you need to end your class definition.  This will
either be the end of file, or the begining of a new class definition
or a cocurrent'base' statement.

Also, the sequence
   (mygrid currgrid) =:conew 'jgtkgrid'
   NB. currgrid is an integer that is incremented after each query
   ('create' mygrid currgrid)~ ''

would be better implemented as:
   (mygrid currgrid) =: '' conew 'jgtkgrid'

This works because when conew is given a left argument, the create
method in your class is run with that as its argument.

And if you only need that one line, you could even do without the
'mygrid' verb, leaving you with:

   ('mygrid',":currgrid) =: '' conew 'jgtkgrid'


I hope this helps,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to