Hacker News new | ask | show | jobs
by ced 1464 days ago
As an aside, Julia's MacroTools.jl defines pre- and post- code walking in four lines:

    walk(x, inner, outer) = outer(x)
    walk(x::Expr, inner, outer) = outer(Expr(x.head, map(inner, x.args)...))

    postwalk(f, x) = walk(x, x -> postwalk(f, x), f)
    prewalk(f, x)  = walk(f(x), x -> prewalk(f, x), identity)
It's dead simple and obvious in retrospect, but I don't think I would have ever thought of that! I've always wondered if there's a lineage to this set of definitions. Does anyone know?