Re: syntax tree manipulation

2014-07-03 Thread James Reeves
You may want to take a look at seqexp  and
zip-visit .

- James


On 3 July 2014 17:12, Brian Craft  wrote:

> What clojure tools should I be considering for doing syntax tree
> manipulations? In general, I'm recursively matching patterns in subtrees
> and rewriting them. The patterns are usually more complex than, say,
> core.match patterns (e.g. match subtree having vector that contains term,
> and split the term out of the vector and put in its own subtree).
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: syntax tree manipulation

2014-07-03 Thread Timothy Baldridge
Zippers, clojure core functions work great if you don't need to query up
the tree as well as down.

For situations where I want pattern-matching like semantics, with the
ability to do arbitrary queries, I've reached for core.logic and/or
Datomic. It's pretty trivial to have some code that turns a tree into
datoms and then you can use core.logic to do joins against that and query.
At that point you've also re-invented parts of Datomic, so if that's an
option (the free version has a in-memory DB), you might consider that.

I've use all of this to query and update DOM like structures in CLJS as
well as query XML data on the server.

Timothy


On Thu, Jul 3, 2014 at 10:30 AM,  wrote:

> If I understand your question correctly, you want to manipulate a deeply
> nested tree-like data structure, right? If that's correct, then perhaps a
> combination of clojure.zip and multimethods will suit your needs. Zippers
> provide a facility to transform (possibly) deeply nested immutable data
> structures in a way that "feels" like you are editing the data structure in
> place when you are actually not. To only manipulate the nodes that match a
> certain pattern, I would suggest writing a multimethod that allows you to
> identify a certain "class" of nodes that necessitate a type of
> modification. That way as you learn more about how your code needs to be
> structured to fit the needs of your data you can add new multimethod
> implementations to fit your needs. The default implementation should
> probably just move to the next loc in the zipper without modifying
> anything.
>
>
> On Thursday, July 3, 2014 12:12:35 PM UTC-4, Brian Craft wrote:
>>
>> What clojure tools should I be considering for doing syntax tree
>> manipulations? In general, I'm recursively matching patterns in subtrees
>> and rewriting them. The patterns are usually more complex than, say,
>> core.match patterns (e.g. match subtree having vector that contains term,
>> and split the term out of the vector and put in its own subtree).
>>
>>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: syntax tree manipulation

2014-07-03 Thread adrian . medina
If I understand your question correctly, you want to manipulate a deeply 
nested tree-like data structure, right? If that's correct, then perhaps a 
combination of clojure.zip and multimethods will suit your needs. Zippers 
provide a facility to transform (possibly) deeply nested immutable data 
structures in a way that "feels" like you are editing the data structure in 
place when you are actually not. To only manipulate the nodes that match a 
certain pattern, I would suggest writing a multimethod that allows you to 
identify a certain "class" of nodes that necessitate a type of 
modification. That way as you learn more about how your code needs to be 
structured to fit the needs of your data you can add new multimethod 
implementations to fit your needs. The default implementation should 
probably just move to the next loc in the zipper without modifying 
anything. 

On Thursday, July 3, 2014 12:12:35 PM UTC-4, Brian Craft wrote:
>
> What clojure tools should I be considering for doing syntax tree 
> manipulations? In general, I'm recursively matching patterns in subtrees 
> and rewriting them. The patterns are usually more complex than, say, 
> core.match patterns (e.g. match subtree having vector that contains term, 
> and split the term out of the vector and put in its own subtree).
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.