Think of tbl as an instance.  You can use methods defined for it with

add__tbl 4 add__tbl 2

Read add__tbl as 'add in tbl', meaning the verb add defined in the path of the name tbl.

add__tbl 2

executes in the locale tbl, running the verb add which is defined in the class of which tbl is an instance.

The z locale is not involved.

Henry Rich

On 11/7/2015 9:07 PM, Joe Bogner wrote:
I'm playing with the idea of a domain specific language against a
object that will have a fair amount of state.

The syntax will be something like

4 add 2 add to tbl

or ideally

add 4 add 2 to tbl

I think the latter will have difficulty implementing but would be
preferred if possible.

There will be many verbs in the dsl (maybe 10-15).

Below is a proof of concept that works fine. I think using the 'to' to
set a global to the current locale is kind of hacky, but I can live
with that.

My bigger concern is making each of the table methods public in the z
locale. Is there a way to dispatch them to the table/CURRENT locale
without making clobbering other verbs in the z/base locale? My
research suggests the answer is no, but was interested in any clever
solutions. I'd also like to avoid adding many more keywords (such as
modifier to intercept the call and convert it)


Alternatively, I considered passing a string of the dsl and chopping
it apart and interpreting it, but I liked the idea of avoiding the
string argument if possible.

Thanks
Joe



coclass 'table'

create=: 3 : 0
data=:y
)

add=: 4 : 0
data=:data+x
)


coclass 'base'



to =: 3 : 'CURRENT=: y'
add =: 4 : 'x add__CURRENT '''''

tbl=:(i.10) conew 'table'

2 add 2 add to tbl

tbl2=:(i.5) conew 'table'

5 add to tbl2
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


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

Reply via email to