my all time favorite J fork

inl_z_ =: (cocurrent@] ".@] [)"1 0

'add 2' inl tbl

Henry's suggestion makes more sense as you described your objects.

Where inl is more convenient is if tbl is a list of objects, in which case inl 
executes the string in all of them.


but if tbl is just one object, then my code is equivalent to

add__tbl 2


another way to keep the flow of your dsl, but losing to keyword


add=: 4 : 0
data__y =:data__y+x
y

)

2 add 2 add tbl


----- Original Message -----
From: Joe Bogner <[email protected]>
To: [email protected]
Cc: 
Sent: Saturday, November 7, 2015 9:07 PM
Subject: [Jprogramming] invoking object verbs without polluting global  
namespace

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