Object pattern matching

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?

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

===============================================================================

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?

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

dunno... i seem to recall something too but searching the raa didn't bring up
any hits?

cheers.

-a

···

On Sun, 21 Aug 2005, James Britt wrote:

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?

--

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

===============================================================================

Ara.T.Howard wrote:

···

On Sun, 21 Aug 2005, James Britt wrote:

...

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. :frowning:

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

In article <43076BDE.2070103@neurogami.com>,

···

James Britt <james_b@neurogami.com> wrote:

Ara.T.Howard wrote:

On Sun, 21 Aug 2005, James Britt wrote:

...

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. :frowning:

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

Phil Tomson wrote:
...

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...

-a

···

On Sun, 21 Aug 2005, Phil Tomson wrote:

In article <43076BDE.2070103@neurogami.com>,
James Britt <james_b@neurogami.com> wrote:

Ara.T.Howard wrote:

On Sun, 21 Aug 2005, James Britt wrote:

...

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. :frowning:

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

--

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

===============================================================================

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.

···

--- "Ara.T.Howard" <Ara.T.Howard@noaa.gov> wrote:

On Sun, 21 Aug 2005, Phil Tomson wrote:

> In article <43076BDE.2070103@neurogami.com>,
> James Britt <james_b@neurogami.com> wrote:
>> Ara.T.Howard wrote:
>>> On Sun, 21 Aug 2005, James Britt wrote:
>>>
>>>> ...
>>>>
>>>> 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. :frowning:
>>
>>
>
> 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.

From my communications with Caleb, I believe he'll be changing
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around

In article <20050820192807.34008.qmail@web36115.mail.mud.yahoo.com>,

···

Eric Mahurin <eric_mahurin@yahoo.com> wrote:

--- "Ara.T.Howard" <Ara.T.Howard@noaa.gov> wrote:

On Sun, 21 Aug 2005, Phil Tomson wrote:
=20
> In article <43076BDE.2070103@neurogami.com>,
> James Britt <james_b@neurogami.com> wrote:
>> Ara.T.Howard wrote:
>>> On Sun, 21 Aug 2005, James Britt wrote:
>>>
>>>> ...
>>>>
>>>> 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. :frowning:
>>
>>
>
> 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.

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.

We eagerly await the release of Grammar.

Phil