JuliaCollections/Iterators.jl

iterate/lazy macro

Closed this issue · 4 comments

hayd commented

I don't know if this is out of scope here, but thought I should post.

Sometimes you have nested functions over arrays which can could be done more efficiently using lazy evaluation.

See for example: jesusfv/Comparison-Programming-Languages-Economics#2

maximum(abs(mValueFunctionNew - mValueFunction))

It'd be great if there were an @iterate macro in the style of @devec. (Maybe this actually is in the scope of devec? I'm not sure.)

I think some functor/monad type thing would have to be assumed, so if it was an f: m A -> m B we could use f: A -> B, otherwise (if a reduction) use reduce (?).

Sorry if this post is a little confused/asked before/terrible idea, but thought I should cross post the thought here for discussion.

Have you seen the Devectorize package?

Looking at this again, you mention @devec. What would @iterate do differently than @devec?

hayd commented

For some reason I didn't think that devec could handle nested functions or reductions! Looking at it again, it looks like it actually does! - though for selected/"pre-defined" functions.

I guess what using iterators may give you is a more generic way to do devec (on simple classes of) functions including, of course, user-defined functions.

However, I think you're right, this could/should be in the scope of devec: to inspect any function and detect if/how to rewrite code blocks in order to devec. This will be faster than keeping track of state (with iterators)... I guess that iterators just feels like the solution to me (coming from python)!

hayd commented

(I guess you can register it's traits manually)