thanks for the ideas.

Henry,

add__tbl 4 add__tbl 2

Is the right way to go except for two thoughts:

1. I was hoping to avoid the visual clutter of having __tbl on each call
2. A call could return a new instance of the object which would need
to be invoked against, that's why I was using CURRENT to resolve the
current instance in the chain (which can be changed by a verb)

Pascal,

inl is a useful. I tinkered with it and it could be a viable option
too. It will have a problem if a method returns a new instance of the
object I think

Aside from that, this is pretty close:

The main thing I dislike about is having to quote the expression,
because I may use quotes within that. I could use double quote (") as
the identifier and replace with double single quotes before executing
though.

'"foo" exp' would become '''foo'' exp'

Sidebar: The plot dsl is along the lines of what I would like to
accomplish but for another object. I was just interested in seeing if
the commands could be entered without being quoted and dispatched
appropriately without having a name in the global locale for each cmd.

coclass 'table'

create=: 3 : 0
data=:y
)

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

sub=: 4 : 0
data=:data-x
)


to=: ''

coclass 'base'

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

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

'5 add 2 add to' inl tbl

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

'2 sub 1 add 2 add to' inl tbl2




Messing around with copath, it seems like I can refer to items in base too

'base' copath 'table'
 copath 'table'
┌────┐
│base│
└────┘

A=: 5
'A sub 1 add 2 add to' inl tbl2

I'm still not sure this is a good idea but  it's been interesting to
learn more about locales

On Sat, Nov 7, 2015 at 11:03 PM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to