If you're looking for Ruby libraries specifically, check out: http://treetop.rubyforge.org/ (Treetop uses PEGs rather than parser combinators, but like pyparsing it integrates very well with its host language.)
Treetop I had not heard of. It looks interesting.
Well the "golden oldie" equivalent in the Perl world is Parse::RecDescent (http://search.cpan.org/dist/Parse-RecDescent/).
A new kid on the block is Regexp::Grammars (http://search.cpan.org/dist/Regexp-Grammars/), which is heavily based on Perl 6 rules/grammar (http://en.wikipedia.org/wiki/Perl_6_rules).
def a(x):
def b():
print x
return b
Not sure what a prototypical ruby usecase would be.Guido's take: http://www.artima.com/weblogs/viewpost.jsp?thread=147358
Arcieri's take: http://www.unlimitednovelty.com/2009/03/indentation-sensitiv...
It's not hard if we disallow statements, and make everything into an expression that returns a value -- something that Ruby does right. The value of a block of statements is just the value of the last statement in the block.
So, whether you call it a function, or a method, or a lambda, or a block, whitespace with multi-line expressions can be made to work.
The commonly-cited lambda-with-multiple-prints example, in CoffeeScript:
count: ->
print 'one'
print 'two'
print 'three' f = lambda x:(
x if (
x**2 > 10 or x**2 < 5
)
else x**3
) def some_method(x, &block)
yield x
end
then to call it:
some_method "hey" { |v| print v }
That might not look like much, but it allows you to create methods that can extend the language expressively and then use them without extra crufty syntax or sigils obstructing their meaning.I'm sure ruby is great once you're initiated, but despite >10 years of programming and having learned basic, c, pascal, lisp, java, c++, python, perl, bash, php and javascript, I have no idea what code does.
Don't mean to harsh, just an observation.
get "/hi" do |url|
print url
end
?