[Cuis] Why or why not OMeta? (was Re: Brainstorming question: what non-trivial uses can you think of for an object-based parser? (strings not invited))
Thierry Goubier
thierry.goubier at gmail.com
Sat May 23 11:46:56 CDT 2015
Hi Frank,
Le 23/05/2015 18:16, Frank Shearar a écrit :
>
> I finally found it: I once implemented pattern matching with OMeta:
> http://www.lshift.net/blog/2011/05/15/algebraic-data-types-and-ometa2/
>
> Given a standard binary tree implementation with Tree whose subclasses
> are Node, Leaf or Empty, I could write:
>
> depth =
> {#Empty} -> [0]
> | {#Leaf anything} -> [1]
> | {#Node depth:l depth:r} -> [(l max: r) + 1]
>
> sum =
> {#Empty} -> [0]
> | {#Leaf anything:v} -> [v]
> | {#Node sum:l sum:r} -> [l + r]
>
> which, I think, is pretty neat.
Yes, it is.
Thanks,
Thierry
More information about the Cuis
mailing list