(mac trav (x . fs)
(w/uniq g
`((rfn go (,g)
(when ,g
,@(map [list _ g] fs)))
,x)))
(def bst-elts (b)
(accum a (trav b [go _!l] [a _!d] [go _!r])))
"self" doesn't strike me as being properly descriptive of how trav uses it - so I suggest using "go" instead of "self". It would be nice to re-use "trav" instead too - although you'd have to dive in the user's code and replace 'trav with a (uniq)'ed symbol.
(def bst-elts (b)
(accum a (trav b [trav _!l] [a _!d] [trav _!r])))
Since captured symbols are kind of freaky I want to be conservative with names: it for objs in general, and self for fns. I wouldn't want to use trav in case someone actually wants to call trav in one of the arguments.
Well, "self" has attached itself (in my mind, anyway) to afn. Seeing "trav" use "self" is disturbing - its like "self" is an unfaithful wife or something.
"self" for "afn" is OK, because "afn" is defined as "a function which calls itself". It's not so OK for "trav", because "trav" doesn't call "itself" (yes, internally it does, but for the user of the macro, it isn't - it's traversing a structure). That's why I'd rather suggest using go. Or alternatively have an optional "go" argument:
Of course this has the problem where the user might have an existing named function that he or she just wants to call to handle some part of the structure:
(trav b existing-fun [self _!next])
A possible alternative would be to force the user to add a ' to the gofn symbol. Since symbols cannot be applied (yet), it would unambiguously specify a special symbol to replace the default 'self: