PROLOGUE

tree-il is a type and it's used by the Guile compiler

it's an intermediate language, substantially

The product of the first pass of compilation is made of such tree-il records

tree-il records are regular scheme records, nothig special

the values produced by the first pass of the compilation are trees
in which the nodes are these tree-il records

In Guile there's a procedure to visit a tree made of tree-il records.

It visit the tree depth first

and it' s a fold procedure along the lines of the fold functions that the Guile manual discusses about SXML transforming

I can't find the link now because the Guile manual is so counterintuitive that any research in it is a punishment

Show thread

in simple words, when a child node gets visited, that's a recursion step and in such step
the visited child node gets passed to a "down" procedure that you have to provide yourself

together with an "accumulator" value that is the result of previous recursion steps

Show thread

When the leaf of a branch gets reached, the procedure steps up again, along the same branch.

And when it steps back on a node that was already visited when going down along the branch,
the node gets passed as an argument to an "up" procedure that you're supposed to provide yourself

Together with the accumulator, that's the same accumulator as before

Show thread

WHAT I WANT TO DO

I'd like to build a tree that has the exact same shape of the tree made of tree-il records

BUT I want my tree to be made of cons cells and vectors. No more

So lists, alists and vectors.

But no more.

Don't ask me why. Please take the problem I'm posing as good

Show thread

THE PROBLEM

When going _down_ along a branch, I konw what to do

I can add the visited node as a child of the previously visite dnode

The problem is when stepping _up_

Because in the accumulator I think I should track the fact that the visiting process is currently
on a node that is a step up in regard to the previous visiting step

Shouldn't I ?

I don't know how to do this

Show thread
Follow

In I would have represented my accumulator as a map and I would have marked the "current" node with a key value couple, with something along the lines of

{... {... {... #:current? ...} ...} ...}

Clojure maps are immutable so a new map would be created at every recursion step

But behind the curtains, the structure gets not replicated as a whole, but rather versioned

and the new versions share some memory with the previous ones

This is what happens with vanilla list processing in scheme

Show thread

In such a facility doesn't exist, as far as I understand

Should that not work, in Clojure there are also the so called zippers

Neither zippers are available in Guile, as far as I understand

So how do I do this ?

Show thread

How do I replicate a tree-il based tree in vanilla cons cells ?

maybe I should take a look at lenses ?

gitlab.com/a-sassmannshausen/g

I still didn't study them

Show thread
Sign in to participate in the conversation
social.device5.co.uk

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!