We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpProcessing Implementations › ruby-processing and context-free
Page Index Toggle Pages: 1
ruby-processing and context-free (Read 3717 times)
ruby-processing and context-free
May 13th, 2009, 8:34am
 
Hi,

I see on Jashkenas website that he is using a Ruby DSL implementation of context-free inside ruby-processing.  Does anyone knows if this DSL is released stuff, part of ruby-processing or not available at all?  It's a neat idea!!  Isn't it?!

L-P
Re: ruby-processing and context-free
Reply #1 - May 13th, 2009, 7:37pm
 
Hey L-P.

The context-free library is a little thing that I wrote a year ago -- I've been meaning for a long time to finish it, document it, and release it as a contributed Ruby-Processing library, but never quite managed to get around to it. However, the library works as you see it on the website, if you feel like playing with context-free-ish grammars...
Re: ruby-processing and context-free
Reply #2 - May 14th, 2009, 8:19am
 
I'm probably doing it wrong because I get errors:

I copied the code from your webpage, placed it in two files, context-free.rb and contextual_tree.rb.  I then try to run contextual_tree with ruby-processing...  says undefined method 'context_free' for #<Processing::App:Contextual:Contextual Tree>, contextual_tree.rb line 12.

I tried various things...and I am wondering what is the "load_ruby_library" method...  why not just require and include?

Thanks!

L-P
Re: ruby-processing and context-free
Reply #3 - May 14th, 2009, 4:41pm
 
Hey L-P.

Here's a packaged directory of two context-free sketches, a greyscale version of the tree one, and a little citygrid one. For the tree, try sliding the random number seeder, and clicking again to redraw. Clicking will also redraw the citygrid. To run them, unzip the folder and "rp5 run tree.rb"

http://s3.amazonaws.com/jashkenas/ruby_processing_gallery/contextual.zip

Have fun.
Re: ruby-processing and context-free
Reply #4 - May 15th, 2009, 9:17am
 
Thanks!
Great!

the city works good,
but the tree throws an error... I'll look around it, but here it is anyway:

Exception in thread "Animation Thread" tree.rb:12:in `setup_the_trees': stack level too deep (SystemStackError)
     from (eval):7:in `call'
     from (eval):7:in `seed'
     from tree.rb:15:in `setup_the_trees'
     from (eval):7:in `call'
     from (eval):7:in `seed'
     from tree.rb:15:in `setup_the_trees'
     from (eval):7:in `call'
     from (eval):7:in `seed'
      ... 402 levels...
     from tree.rb:86:in `draw_it'
     from tree.rb:62:in `setup'
     from :1
     ...internal jruby stack elided...
     from Sketch.setup_the_trees((eval):7)
     from Proc.call((eval):7)
     from Processing::ContextFree.seed(tree.rb:15)
     from Sketch.setup_the_trees((eval):7)
     from Proc.call((eval):7)
     from Processing::ContextFree.seed(tree.rb:15)
     from Sketch.setup_the_trees((eval):7)
     from Proc.call((eval):7)
     ... and this goes on for a hundred lines...
Re: ruby-processing and context-free
Reply #5 - May 15th, 2009, 9:54am
 
Try making the size of the tree sketch a little smaller, and hope it doesn't blow the stack.

This brings up one of the more interesting questions about the whole context-free DSL experiment. The rules, as they exist right now, call each other recursively by name. The sketch calls seed, which splits off in three directions each calling seed which calls seed, etc, shrinking the size each time, until it reaches a certain threshold of invisibility and we decide to stop. In this way the tree is drawn. It would be awfully nice if we could transform the recursive calls into loops, but I'm not certain that this can be done, in general, for context free sketches, because they're certainly not tail-recursive, and may decide to affect external state somewhere deep down. Anyway, if we can figure out a way to have the context-free library run the rules in loops, there won't be any concern about stack blowout, and you could make the sketches as large and intricate as you please.

For a different workaround, you can try increasing the java stack size. Create a "data" folder next to all the sketches and the library, and add a "java_args.txt" file in there that reads "-Xss8M". That should give you breathing room.

Re: ruby-processing and context-free
Reply #6 - May 15th, 2009, 3:31pm
 
Thanks,
Increasing the java stack size completely did it, it works now,

I'll give a bit more thought to context-free before answering on your other questions as I am still new to this programming paradigm, but I already find it useful, so I think its a neat idea to push it in the ruby-processing implementation, there is certainly a way to have context-free match the ruby way,
will hopefully be back with new useful ideas after I get hold of context-free a bit more.

L-P
Re: ruby-processing and context-free
Reply #7 - May 29th, 2009, 1:29pm
 
I finally got to understand context free, in its context-free-art implementation at least.
So I dived back in the implementation of context free for rp5.
I must admit I haven't had the result I expected yet, like when I try to call basic shapes from my first rules it doesn't work...

Before diving more deeply in the code, modifying it and seeing what could be done to implement the whole thing as iterative or looping structures I'd like to know what is your actual idea for the library...
Would you like to have contributers, are you ready to redesign part of the DSL, what do you think?
Anyway, It's a fun idea overall!

L-P
Re: ruby-processing and context-free
Reply #8 - May 31st, 2009, 9:14pm
 
Yo L-P.

Thank's for pushing this line of inquiry. I've started up a separate project for the "context_free" library on GitHub, and I'd love to rework the DSL, figure out how to do it iteratively without having to parse the code outside of Ruby, and generally make the thing ship-shape. Please feel free to fork it and go nuts. I've also got four sample sketches included, and if you or anyone else feels like contributing more, that'd be fantastic. The code is available here, and there's a todo list in the readme:

http://github.com/jashkenas/context_free
Re: ruby-processing and context-free
Reply #9 - Jun 1st, 2009, 8:09am
 
Great!

github is such a great tool for collaboration!
I had already started to get some idea together, I'll soon fork and try them inside your implementation.
Thanks!

L-P
Page Index Toggle Pages: 1