You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to clo...@googlegroups.com
I am trying to work with a tree representation using vectors where the first element is the node value and the rest are the children as suggested here:
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to clo...@googlegroups.com
To use the zipper library you have to be able to provide branch? children and make-node functions that apply to your data structure.
I don't see a way to provide a meaningful branch? or children function for the structure you describe. Vector? will not work as branch? as it will not return true if passed the first element in a vector, and next will not work as it will not return the children if passed the first element of a vector.
It looks to me like you don't get past the first element because the call to z/next fails both (and (branch? loc)(down loc)), (right loc) and (up loc) and therefore marks the first element as the end of the of the structure.
Is there a compelling reason for not using the vector-zip structure for your specific use-case?
dabd
unread,
Nov 27, 2013, 12:19:06 AM11/27/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to clo...@googlegroups.com
I'm not sure what you mean by not being able to provide a meaningful branch?.
I would like to represent a tree such a this:
1
/ \
23
/ \
45
How can I achieve this using zippers?
Carlo Zancanaro
unread,
Nov 27, 2013, 12:19:09 AM11/27/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to clo...@googlegroups.com
On Tue, Nov 26, 2013 at 08:30:15PM -0800, martin_clausen wrote:
> To use the zipper library you have to be able to provide branch? children
> and make-node functions that apply to your data structure.
>
> I don't see a way to provide a meaningful branch? or children function for
> the structure you describe. Vector? will not work as branch? as it will not
> return true if passed the first element in a vector, and next will not work
> as it will not return the children if passed the first element of a vector.
Your issue was that your original `make-node` function didn't return a
vector, it returned a ConsCell (with a vector as its tail). This meant
that your new node no longer returned true for "children", that is it
identified itself as a leaf.
By making `make-node` return a vector (vec turns any sequable thing into
a vector) your `make-node` now returns a valid branch node, so z/next
behaves as you want it to.
Carlo
dabd
unread,
Nov 27, 2013, 1:19:05 AM11/27/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to clo...@googlegroups.com
Thanks. Do you think the call to z/edit in my code could be simplified? To edit a branch node I have to use conj to build a node only to pass it to make-node which will break it apart again.
Martin Clausen
unread,
Nov 27, 2013, 1:26:12 AM11/27/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to clo...@googlegroups.com
You are right, but why is this a problem? The zipper works as intended
and if you need to detect leaf nodes, that kan be done by checking for
the presence of a non-empty value of the children key.
dabd
unread,
Nov 27, 2013, 11:10:36 AM11/27/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to clo...@googlegroups.com
Shouldn't be a practical problem just wondering if it's correct given the zipper definition requirements.