Implementing functional languages: a tutorial [SPJ online book]
research.microsoft.com1 ポイント投稿者 ced0 コメント
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? [sin(x) for x in vec]
map(sin, vec)
sin.(vec)
which are roughly equivalent? Is that what you're referring to?