[ruote:2288] RE: ruby dsl

6 views
Skip to first unread message

John Mettraux

unread,
May 17, 2010, 10:19:43 AM5/17/10
to ruote

On Mon, May 17, 2010 at 10:04:47AM -0400, Cappelaere Patrice wrote:
> John,
>
> Just curious but what was the reasoning behind writing your own ruby_dsl parser? and not use ParseTree and its s-expressions?
>
> The reason I ask (if you really want to know)...I am trying to extend a participant to be a DSL for spectral image processing. So I really want to define an algorithm (aka a process) in a similar manner... and then use that within a workflow...
>
> I was trying to visualize with ruote-fluo to quickly show the equivalence of representation... this would make it very seamless.
>
> This would also allow full arithmetic operations...
>
> b1 = band(23)
> b2 = band(24)
> c = b1 + b2
> d = b1 > 0...
>
> Thanks,
> Pat.

Hello Patrice,

> Just curious but what was the reasoning behind writing your own ruby_dsl
> parser? and not use ParseTree and its s-expressions?

Well, I did not write a parser, I'm using an internal DSL.

http://github.com/jmettraux/ruote/blob/ruote2.1/lib/ruote/parser/ruby_dsl.rb

I'm ready to change its name if it's too misleading.


Best regards,

--
John Mettraux - http://jmettraux.wordpress.com

--
you received this message because you are subscribed to the "ruote users" group.
to post : send email to openwfe...@googlegroups.com
to unsubscribe : send email to openwferu-use...@googlegroups.com
more options : http://groups.google.com/group/openwferu-users?hl=en

Cappelaere Patrice

unread,
May 17, 2010, 11:00:45 AM5/17/10
to openwfe...@googlegroups.com
John,

Sorry for screwing up the thread...
Yes, I am talking about that ruby_dsl.rb.
Its purpose is basically to return a parse tree for your DSL, right? so why not use ParseTree?

[There is a bunch of issues with set expressions... that I was not sure to bring up before I got an exchange going]
Thanks,
Pat.

John Mettraux

unread,
May 17, 2010, 7:13:19 PM5/17/10
to openwfe...@googlegroups.com

On Mon, May 17, 2010 at 11:00:45AM -0400, Cappelaere Patrice wrote:
>
> Yes, I am talking about that ruby_dsl.rb.
> Its purpose is basically to return a parse tree for your DSL, right? so why not use ParseTree?

Hello,

because my ruby_dsl takes as input ruby blocks and not strings of ruby code.

At one extreme, consider :

---8<---
pdef = Ruote.process_definition do
sequence do
alpha
bravo
end
end

engine.launch(pdef)
--->8---

Should I turn the block back into a String before passing it to ParseTree ?


> [There is a bunch of issues with set expressions... that I was not sure to bring up before I got an exchange going]

Bring it on.

Cappelaere Patrice

unread,
May 17, 2010, 10:28:31 PM5/17/10
to openwfe...@googlegroups.com
John,

Well... parser.rb takes a definition (from a file, string...) creates a new instance of a Ruote::Parser, calls parse...
calls ruby_eval... which eventually calls the ruby_dsl.
Coming from ruote_fluo, it is a JSON string parsed to a tree back to ruby...

So there is quite a bit of transformation involving strings here....

I would love to be able to use more ruby code within a pdef like...
and pass it to ruote_fluo to display as a workflow

pdef = Ruote.process_definition do
sequence do
x = some_function(3 + ${f:v})
y = 1 + 5 / 6
alpha x, y
bravo
end
end

actually in my case it would be more like:
pdef = Ruote.algorithm_definition do
sequence do
x = some_function(3 + ${f:v})
y = 1 + 5 / 6
alpha x, y
end
end

and then use those algos as subprocess....

Does this make sense?

Pat.

John Mettraux

unread,
May 17, 2010, 10:37:46 PM5/17/10
to openwfe...@googlegroups.com

On Mon, May 17, 2010 at 10:28:31PM -0400, Cappelaere Patrice wrote:
> John,
>
> Well... parser.rb takes a definition (from a file, string...) creates a new instance of a Ruote::Parser, calls parse...
> calls ruby_eval... which eventually calls the ruby_dsl.
> Coming from ruote_fluo, it is a JSON string parsed to a tree back to ruby...
>
> So there is quite a bit of transformation involving strings here....

Please re-read the example I passed in

http://groups.google.com/group/openwferu-users/msg/c4befb96480e71bb

And tell me when parse is called.


> I would love to be able to use more ruby code within a pdef like...
> and pass it to ruote_fluo to display as a workflow
>
> pdef = Ruote.process_definition do
> sequence do
> x = some_function(3 + ${f:v})
> y = 1 + 5 / 6
> alpha x, y
> bravo
> end
> end
>
> actually in my case it would be more like:
> pdef = Ruote.algorithm_definition do
> sequence do
> x = some_function(3 + ${f:v})
> y = 1 + 5 / 6
> alpha x, y
> end
> end
>
> and then use those algos as subprocess....
>
> Does this make sense?

It makes sense for you, in your project.

For me, it makes for crowded process definitions. Such calculations are better when placed in a participant that may be re-used by multiple process definitions.

Cappelaere Patrice

unread,
May 17, 2010, 10:52:11 PM5/17/10
to openwfe...@googlegroups.com
Since you asked:

Ruote.process_definition :name => 'my def 2', :revision => 0 do
sequence do

set :field=>'red', :value=>3
set :field=>'green', :value=>4
set :field=>'blue', :value=>band(4)

# crashes set :field=>'blue' do
# band :number=> 4
#end

composite_visible :r=>'${f:red}', :g=>'${f:green}', :b=>'${f:blue}'
end
end

create a file in public to hold that definition and load it in ruote_fluo
first two sets do not show up
third set shows up as "band 4"
fourth commented set crashes

Thanks,
Pat.

[Note: wouldn't it be nice to be able to define the variables and then use them directly?
like:

red = band :number=>5
green = band :number=>4
blue = band :number=>3

composite_visible :r=>red :g=>green, :b=>blue


On May 17, 2010, at 7:13 PM, John Mettraux wrote:

>

Cappelaere Patrice

unread,
May 17, 2010, 11:05:23 PM5/17/10
to openwfe...@googlegroups.com
John,

I did read the example... in the case of ruote_fluo...If you take that definition and put it in a file,,, I pretty much described what happens, I thought.

The point was to show that you may want to expose more of what is happening at the workflow level rather than hide it in a participant (which would not be obvious to the casual reader). This is why you want to use workflows after all.

Why couldn't I use a workflow to design an algorithm and the many processing steps?
This would be really cool.... soooo close!.

Great work as always!
V/R,
Pat.

Cappelaere Patrice

unread,
May 17, 2010, 11:15:20 PM5/17/10
to openwfe...@googlegroups.com
Here is another one.
On Ruote_Fluo side, you can add a set expression to a sequence
set :field=>'x',:value=>'3'

But it gets displayed as: set :field=>'x',:value=>'3':'null'

and as_ruby returns: 
set ":field=>'x',:value=>'3'"

as_xml:
	<set ref=":field=&gt;'x',:value=&gt;'3'"/>


V/R,
Pat.


On May 17, 2010, at 7:13 PM, John Mettraux wrote:

John Mettraux

unread,
May 17, 2010, 11:24:00 PM5/17/10
to openwfe...@googlegroups.com

On Mon, May 17, 2010 at 10:52:11PM -0400, Cappelaere Patrice wrote:
> Since you asked:
>
> Ruote.process_definition :name => 'my def 2', :revision => 0 do
> sequence do
>
> set :field=>'red', :value=>3
> set :field=>'green', :value=>4
> set :field=>'blue', :value=>band(4)
>
> # crashes set :field=>'blue' do
> # band :number=> 4
> #end
>
> composite_visible :r=>'${f:red}', :g=>'${f:green}', :b=>'${f:blue}'
> end
> end
>
> create a file in public to hold that definition and load it in ruote_fluo
> first two sets do not show up
> third set shows up as "band 4"
> fourth commented set crashes

ruote-fluo is not meant to display/edit process definition where you call ruby function at "define time".

Sorry for the lack of warning signals about that.


> [Note: wouldn't it be nice to be able to define the variables and then use them directly?
> like:
>
> red = band :number=>5
> green = band :number=>4
> blue = band :number=>3
>
> composite_visible :r=>red :g=>green, :b=>blue

Sorry, but ruote is not interpreting ruby directly, it's interpreting process definition expressed as

[ expression_name, attribute_hash, children_expression_array ]

As I've said previously, "parser" is a poor choice, "generator" would be better.

Ruote is not parsing ruby code, it is executing ruby code to generate process definition trees.

Now, that leaves you free to come up with a generator that takes as input any dialect you want.

John Mettraux

unread,
May 17, 2010, 11:29:59 PM5/17/10
to openwfe...@googlegroups.com

On Mon, May 17, 2010 at 11:05:23PM -0400, Cappelaere Patrice wrote:
>
> I did read the example... in the case of ruote_fluo...If you take that definition and put it in a file,,, I pretty much described what happens, I thought.

Interesting, for me, when I put it into ruote-fluo, I get :

http://ruote.s3.amazonaws.com/alpha_bravo.png

Oh wait, let me guess, you put "engine.launch(pdef)" part with it too ?


> The point was to show that you may want to expose more of what is happening at the workflow level rather than hide it in a participant (which would not be obvious to the casual reader). This is why you want to use workflows after all.

What is not obvious about

sequence do
calculate_next_trajectory
emit_trajectory
end

?

Do you remember that ruote is totally asynchronous ? Why do you want to slap around synchronous calculations right in the middle of a process definition ?

Programming is about building "higher" abstraction levels.


> Why couldn't I use a workflow to design an algorithm and the many processing steps?
> This would be really cool.... soooo close!.

Lean the tool, use participants.

John Mettraux

unread,
May 17, 2010, 11:38:15 PM5/17/10
to openwfe...@googlegroups.com

On Mon, May 17, 2010 at 11:15:20PM -0400, Cappelaere Patrice wrote:
>
> Here is another one.
> On Ruote_Fluo side, you can add a set expression to a sequence
> set :field=>'x',:value=>'3'
>
> But it gets displayed as: set :field=>'x',:value=>'3':'null'
>
> and as_ruby returns:
> set ":field=>'x',:value=>'3'"
>
> as_xml:
> <set ref=":field=&gt;'x',:value=&gt;'3'"/>

Interesting,

for this one :

Ruote.process_definition do
sequence do
alpha
_set :field => 'f', :value => 'v'
bravo
end
end

I get :

http://ruote.s3.amazonaws.com/rf_set_field.png

as XML :

<?xml version="1.0" encoding="UTF-8"?>
<define>
<sequence>
<alpha/>
<set field="f" value="v"/>
<bravo/>
</sequence>
</define>

as JSON :

["define",{},[["sequence",{},[["alpha",{},[]],["set",{"field":"f","value":"v"},[]],["bravo",{},[]]]]]]


Issue closed.

John Mettraux

unread,
May 18, 2010, 2:42:49 AM5/18/10
to openwfe...@googlegroups.com

On Mon, May 17, 2010 at 10:28:31PM -0400, Cappelaere Patrice wrote:
>
> Well... parser.rb takes a definition (from a file, string...) creates a new instance of a Ruote::Parser, calls parse...
> calls ruby_eval... which eventually calls the ruby_dsl.

Actually parse() is called, but since the input is a syntax tree, it exits directly :

http://github.com/jmettraux/ruote/blob/ruote2.1/lib/ruote/parser.rb#L52

No ruby_eval.


Best regards.

Cappelaere Patrice

unread,
May 18, 2010, 8:55:39 AM5/18/10
to openwfe...@googlegroups.com
John,

You are right "parser" is a poor choice. I was just using your class name (Ruote::Parser) and I certainly understand what ruby_dsl does.
I agree that I can have my own DSL that can live happily with process definitions so I do not have to hide them inside participants. That's fine too. But there seems to me that there are some major similarities... :) ... that could be leveraged... may be later...

Pat.

Cappelaere Patrice

unread,
May 18, 2010, 9:03:15 AM5/18/10
to openwfe...@googlegroups.com
John,

On May 17, 2010, at 11:29 PM, John Mettraux wrote:


On Mon, May 17, 2010 at 11:05:23PM -0400, Cappelaere Patrice wrote:

I did read the example... in the case of ruote_fluo...If you take that definition and put it in a file,,, I pretty much described what happens, I thought.

Interesting, for me, when I put it into ruote-fluo, I get :

 http://ruote.s3.amazonaws.com/alpha_bravo.png

Oh wait, let me guess, you put "engine.launch(pdef)" part with it too ?

nope!



The point was to show that you may want to expose more of what is happening at the workflow level rather than hide it in a participant (which would not be obvious to the casual reader).  This is why you want to use workflows after all.

What is not obvious about

 sequence do
   calculate_next_trajectory
   emit_trajectory
 end

What's not obvious is what's inside of those participants.  I might as well hide the whole thing as a participant and what I have is a simple asynchronous RPC call to a web processing service.


Do you remember that ruote is totally asynchronous ? Why do you want to slap around synchronous calculations right in the middle of a process definition ?

Programming is about building "higher" abstraction levels.


Oh yes, I remember that.  But sequences are done in step manner.
Yes I know what Programming is about and agree with your statement. Programming is also about communication of intent for the customers that will have to work with the system.  Sometimes they may want to know what is going on.


Why couldn't I use a workflow to design an algorithm and the many processing steps?
This would be really cool.... soooo close!.

Lean the tool, use participants.

That's really a low blow!  You were probably not having a good day?

Pat.

Cappelaere Patrice

unread,
May 18, 2010, 9:16:48 AM5/18/10
to openwfe...@googlegroups.com
John,

On May 17, 2010, at 11:38 PM, John Mettraux wrote:


On Mon, May 17, 2010 at 11:15:20PM -0400, Cappelaere Patrice wrote:

Here is another one.
On Ruote_Fluo side, you can add a set expression to a sequence
set :field=>'x',:value=>'3'

But it gets displayed as: set :field=>'x',:value=>'3':'null'

and as_ruby returns:
set ":field=>'x',:value=>'3'"

as_xml:
<set ref=":field=&gt;'x',:value=&gt;'3'"/>

Interesting,

for this one :

 Ruote.process_definition do
   sequence do
     alpha
     _set :field => 'f', :value => 'v'
     bravo
   end
 end


I must have missed the notice that "set" had been replaced by "_set"
Must have been distracted by this: http://ruote.rubyforge.org/exp/set.html
Sorry!


I get :

 http://ruote.s3.amazonaws.com/rf_set_field.png

as XML :

 <?xml version="1.0" encoding="UTF-8"?>
 <define>
   <sequence>
     <alpha/>
     <set field="f" value="v"/>
     <bravo/>
   </sequence>
 </define>

as JSON :

 ["define",{},[["sequence",{},[["alpha",{},[]],["set",{"field":"f","value":"v"},[]],["bravo",{},[]]]]]]


Issue closed.

Too bad that we have those underscored keywords... It does not read as well...
But I guess that the process definitions are not meant to be read by the user.
Pat.


John Mettraux

unread,
May 18, 2010, 9:21:43 AM5/18/10
to openwfe...@googlegroups.com

On Tue, May 18, 2010 at 09:03:15AM -0400, Cappelaere Patrice wrote:
>
> >> Why couldn't I use a workflow to design an algorithm and the many processing steps?
> >> This would be really cool.... soooo close!.
> >
> > Learn the tool, use participants.
>
> That's really a low blow! You were probably not having a good day?

Still the same day.

Still the same scenario.

Cappelaere-sama complains because the tools cannot drive screws and I then have to explain to him in lengthy details that it's a hammer.

--
John Mettraux - http://jmettraux.wordpress.com

John Mettraux

unread,
May 18, 2010, 9:27:07 AM5/18/10
to openwfe...@googlegroups.com

On Tue, May 18, 2010 at 09:16:48AM -0400, Cappelaere Patrice wrote:
>
> On May 17, 2010, at 11:38 PM, John Mettraux wrote:
>
> >
> > On Mon, May 17, 2010 at 11:15:20PM -0400, Cappelaere Patrice wrote:
> >>
> >> Here is another one.
> >> On Ruote_Fluo side, you can add a set expression to a sequence
> >> set :field=>'x',:value=>'3'
> >>
> >> But it gets displayed as: set :field=>'x',:value=>'3':'null'
> >>
> >> and as_ruby returns:
> >> set ":field=>'x',:value=>'3'"
> >>
> >> as_xml:
> >> <set ref=":field=&gt;'x',:value=&gt;'3'"/>
> >
> > Interesting,
> >
> > for this one :
> >
> > Ruote.process_definition do
> > sequence do
> > alpha
> > _set :field => 'f', :value => 'v'
> > bravo
> > end
> > end
> >
>
> I must have missed the notice that "set" had been replaced by "_set"
> Must have been distracted by this: http://ruote.rubyforge.org/exp/set.html
> Sorry!

I will fix that.

> > I get :
> >
> > http://ruote.s3.amazonaws.com/rf_set_field.png
> >
> > as XML :
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <define>
> > <sequence>
> > <alpha/>
> > <set field="f" value="v"/>
> > <bravo/>
> > </sequence>
> > </define>
> >
> > as JSON :
> >
> > ["define",{},[["sequence",{},[["alpha",{},[]],["set",{"field":"f","value":"v"},[]],["bravo",{},[]]]]]]
> >
> >
> > Issue closed.
>
> Too bad that we have those underscored keywords... It does not read as well...
> But I guess that the process definitions are not meant to be read by the user.

Thanks for complaining.

Sorry for not being better at managing your expectations and for wasting your precious time.


Kind regards,

--
John Mettraux - http://jmettraux.wordpress.com

John Mettraux

unread,
May 18, 2010, 7:51:11 PM5/18/10
to openwfe...@googlegroups.com

On Tue, May 18, 2010 at 10:21:43PM +0900, John Mettraux wrote:
>
> On Tue, May 18, 2010 at 09:03:15AM -0400, Cappelaere Patrice wrote:
> >
> > >> Why couldn't I use a workflow to design an algorithm and the many processing steps?
> > >> This would be really cool.... soooo close!.
> > >
> > > Learn the tool, use participants.
> >
> > That's really a low blow! You were probably not having a good day?
>
> Still the same day.
>
> Still the same scenario.
>
> Cappelaere-sama complains because the tool cannot drive screws and I then have to explain to him in lengthy details that it's a hammer.

Hello Patrice,

I am sorry. I was harsh with you and lacked patience.


Kind regards,
Reply all
Reply to author
Forward
0 new messages