Re: [proto] My own lambda for MSM / wish list

2011-03-14 Thread Gordon Woodhull

On Mar 14, 2011, at 5:28 PM, Christophe Henry wrote:

>> .. the talk from Matt Calabrese last year at boostcon with the
>> MPL/Fusion hybrid
>> using decltype and auto. I think this is an interesting venture all in
>> all and should
>> be extended.

Personally, I think it's interesting but I like having a different syntax for 
metaprogramming than for run-time programming; I think it makes things more 
clear.  

I don't actually think having a different syntax will make metaprogramming any 
less difficult for newbies to understand.

But I still would like to help out, if possible, just cuz it's neat stuff.  :-)
___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto


Re: [proto] So I heard proto make AST ...

2010-08-10 Thread Gordon Woodhull

Thanks Joel,

This is food for thought!

On Aug 10, 2010, at 2:47 AM, joel falcou wrote:

On 10/08/10 05:24, Gordon Woodhull wrote:


I wonder if Dan Marsden's Traversal library would solve this out of  
the box? http://boost-spirit.com/dl_docs/traversal/html/traversal/introduction.html

Oh nice link, I didn't knew that :o
The way I would solve it is to create an adapter that makes a Proto  
tree look like a graph...  Like Boost.Graph, Metagraph is designed  
to allow adapting any metadata that is already graphlike to have a  
graph API.  (This wasn't the right approach for MSM because there's  
nothing in those tables that immediately answers "what are the  
edges for this vertex?")


If there is interest, I could probably pull this together pretty  
quickly, as Proto already has such an expressive API.  Then we'd  
immediately have inefficient implementations of DFS & BFS and I  
could see if there's a good way to factor out the color map stuff  
to make it speedy.

We're looking at two challenge in Proto :
-> traversing the AST type at compile-time to apply meta-function  
onto tree node


I just committed an example which does this part.  See end of message.

-> traversing the AST value at run-time to apply function onto tree  
node


This requires a Fusion/BGL interface, which I haven't thought out  
yet.  Probably just means moving a parameter from the <> to () as  
usual. :-D



for example here is my current use-cases:

- walkign through a proto AST to apply a visitor onto node/leaf :  
turn the AST on array into the same AST with pointer element before  
evaluation


Yes, I imagine that's the most common use case.  How hard can that  
Fusion/BGL interface be?



- turning the AST into a DAG


Yay!

Stjepan Rajko and I talked about doing this in order to allow Proto  
expressions to define graph metadata.


Maybe you'd kind of cut and paste the Proto tree into an mpl graph  
while looking for vertices with duplicate IDs.  Should work just as  
well on graphs with cycles.


This way you'd end up with sort of a graph metadata overlay over the  
Proto tree.  Each vertex would contain metadata instructions for how  
to get to the corresponding Proto node in the expression, and each  
edge would be vertex+child#.  No extra runtime data needed, if I'm not  
mistaken.


You could also imagine doing this with a Fusion graph somehow, if you  
wanted to add runtime data...  but I don't grok the Fusion/Proto  
allocation/reference magic yet, so I'm not quite sure what I'm saying.


- applying a visitor performing osme kind of reduction on the tree  
startign form the leaf to evaluate the value of the AST in a given  
point of evaluation


Postorder traversal?  I guess the trick is in what you produce:  
annotating the existing nodes, easy, vs building something new, maybe  
not so.


- for a given assign node (lhs = rhs) check if the lhs data address  
is somewhere in the terminal of rhs. This is basically our trickiest  
runtime algorithm in nt2 that helps us detetcing alias in expression  
without having ppl using alias(x) function.


Again, DFS with a Fusion/BGL interface.

- detecting pattern in the AST (like a+b*c) and repalce all of them,  
recurisvely into another (here by madd(a,b,c)). It's currently done  
with special grammar and it's maybe better to do it like this but we  
never know.


Haha, I haven't thought about graph pattern matching for a while,  
though that's where I started with graphs 15 years ago.


Special-purpose Proto grammars/transforms are probably the best way to  
modify Proto expressions, but like you say, we never know.  Maybe  
something cool could be done with graph transformations of fusionish  
graph data.


Let me see if I am starting to understand the Proto/Fusion memory  
model.  You end up with the original expression as one object, and  
then a bunch of new AST nodes holding references into the original  
expression, right?


I'm from the old guard w/r to tree, so I'm mostly thinking in  
visitor. But if you care to show me how iterators can be used, I'm  
open to suggestion.


Cool.  Visitors are way more powerful.

If you go with iterators you end up creating different iterator types  
for every kind of traversal.  But then they don't muck with your  
control flow.  Here is a good message describing that approach, from  
one of the boost::tree discussions.  (There have been a few valiant  
attempts.)

http://lists.boost.org/Archives/boost/2005/03/83203.php


So, here's how far I got tonight: there's
sandbox/metagraph/libs/metagraph/example/proto_adaptor.cpp
which does compile-time traversal of the Proto expression _1*12/_2,  
printing this nice error message showing that the preorder traversal  
worked (in reverse order):


proto_adaptor.cpp:132: error: No match for 'assertion_failed(
m

Re: [proto] So I heard proto make AST ...

2010-08-09 Thread Gordon Woodhull

Hi Joel, Christophe, Eric,
I think you should talk to Gordon Woodhull. He's building a  
metagraph

>> (among others) library, which I am going to use in msm for
>> compile-time calculations and fsm analysis. This means there  
will be
>> temporarily a metagraph library inside msm as proof of concept  
until

>> there can be a review.
>> Maybe he can adapt this library for proto analysis?
>>

>Oh yeah, will save me some time indeed.
>Mayeb we shoudl invite him over here ?

I just sent him a mail. BTW the metagraph library is in the sandbox,
and a potential usage with msm was sent by Gordon on the devel list
just at the end of the BoostCon.

Sorry for the slow response - been on vacation offline.

For sure, trees are on my roadmap, as metagraph is a library that  
attempts to generalize all things graphlike.  But I can't claim to  
have the best solution yet.


The tree can be thought of as a special case of the graph where each  
vertex has exactly one in-edge (or zero, if it's a root).


The nice thing about traversing trees is that you don't have to worry  
about cycles, so you don't need a color map if you know your tree is  
connected - way more efficient.


I wonder if Dan Marsden's Traversal library would solve this out of  
the box? http://boost-spirit.com/dl_docs/traversal/html/traversal/introduction.html


The way I would solve it is to create an adapter that makes a Proto  
tree look like a graph...  Like Boost.Graph, Metagraph is designed to  
allow adapting any metadata that is already graphlike to have a graph  
API.  (This wasn't the right approach for MSM because there's nothing  
in those tables that immediately answers "what are the edges for this  
vertex?")


If there is interest, I could probably pull this together pretty  
quickly, as Proto already has such an expressive API.  Then we'd  
immediately have inefficient implementations of DFS & BFS and I could  
see if there's a good way to factor out the color map stuff to make it  
speedy.


The main API debate when it comes to traversals is "visitors or  
iterators?"  Currently metagraph takes the visitor approach from  
Boost.Graph, which are more general and expressive, but iterators are  
often more convenient.  Any opinions here?  AFAIK we don't have  
coroutines or continuations in C++ metaprogramming to make the  
inversion of control easier.  ;-)


Thoughts?

Gordon


___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto