Created
August 18, 2019 19:25
-
-
Save rgchris/b84ecc4e3929ff0a683a3e2131adcfc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
Title: "Walk through a VID tree (non-recursive)" | |
Author: "Christopher Ross-Gill" | |
Date: 18-Aug-2019 | |
Comment: "Goes backwards - most prominent faces first" | |
] | |
Rebol [ | |
Comment: "Works in Rebol 2 as well" | |
] | |
walk-through: func [ | |
face [object!] invoke [any-function!] | |
/local parents stack | |
][ | |
parents: make block! 5 ; arbitrary block space allocation | |
stack: reduce [face] | |
while [not empty? stack][ | |
face: first stack | |
case [ | |
not all [ | |
object? :face | |
in face 'pane | |
][ | |
remove stack | |
] | |
same? face pick parents 1 [ | |
; we've already handled the kids | |
remove parents | |
remove stack | |
invoke face parents | |
] | |
object? get in face 'pane [ | |
insert parents face | |
insert stack face/pane | |
] | |
block? get in face 'pane [ | |
insert parents face | |
insert stack reverse copy face/pane | |
] | |
face [ | |
remove stack | |
invoke face parents | |
] | |
] | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment