Skip to content

Instantly share code, notes, and snippets.

@rgchris
Created August 18, 2019 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgchris/b84ecc4e3929ff0a683a3e2131adcfc3 to your computer and use it in GitHub Desktop.
Save rgchris/b84ecc4e3929ff0a683a3e2131adcfc3 to your computer and use it in GitHub Desktop.
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