array_of_hashes = [ {}, {} ]
specific_array_of_hashes = [ {'key' => 'value}, {:k => :v} ]
specific_array_of_hashes_2 = [ {:k => :v} ]
specific_array_of_hashes.is_shaped_like? array_of_hashes #=> true
so, something like pattern matching in ml languages. any concepts on how to
do that in ruby for arbitrary objects?
cheers.
-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
Isn't there a Ruby project that allows one to run regexen over object
hierarchies?
James
--
http://www.ruby-doc.org - The Ruby Documentation Site
http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
> Ara.T.Howard wrote:
>>
>> i've been toying with an idea lately and thinking about how one would crawl
>> an
>> object graph to determine if it matched a specifc object. for instance
>>
>>
>> array_of_hashes = [ {}, {} ]
>>
>> specific_array_of_hashes = [ {'key' => 'value}, {:k => :v} ]
>> specific_array_of_hashes_2 = [ {:k => :v} ]
>>
>> specific_array_of_hashes.is_shaped_like? array_of_hashes #=> true
>>
>> so, something like pattern matching in ml languages. any concepts on how
>> to
>> do that in ruby for arbitrary objects?
>>
>
> Isn't there a Ruby project that allows one to run regexen over object
> hierarchies?
dunno... i seem to recall something too but searching the raa didn't bring up
any hits?
I was selling some folks on Ruby recently, and mentioned this project,
and I swore I had saved off the initial announcement because it struck
me as one of those things that did solve any immediate problems but
seemed so slick that I knew it would come in handy.
Now I can't find it. :(
I think you're looking for Reg:
http://rubyforge.org/projects/reg/
Reg is a library for pattern matching in ruby data structures. Reg
provides Regexp-like match and match-and-replace for all data structures
(particularly Arrays, Objects, and Hashes), not just Strings.
Phil
>
> I think you're looking for Reg:
>
> http://rubyforge.org/projects/reg/
>
> Reg is a library for pattern matching in ruby data structures. Reg
> provides Regexp-like match and match-and-replace for all data structures
> (particularly Arrays, Objects, and Hashes), not just Strings.
Yes! Thanks.
James
thanks phil! downloading now...
From my communications with Caleb, I believe he'll be changing
the interface to look more like Regexp. This will help in
places where you have ducked-type places that deal with
Regexp-like objects. An example is some of the scan_pattern*
methods I'll be adding to Cursor (not released yet). I think
he might add the ability to operate on a Cursor directly also,
but I'm not sure about that. A Cursor by the way is something
generic that can look kind of like a Array, String, IO, C++
iterator, Java stream, etc. all rolled into one API. I have
many derived classes that operate on a variety of sequential
data structures.
In addition I'm putting together Grammar which will also be
able to operate on any sequential data structure - as long as
you can give it a subset of the Cursor API. You'll be able to
write a lexer (operates on characters) and a parser (operates
on tokens) in a uniform way. Similar to ANTLR, but more
unification.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
We eagerly await the release of Grammar.
Phil