Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Added some macro iterators #33

Merged
merged 1 commit into from
Jul 8, 2014
Merged

Added some macro iterators #33

merged 1 commit into from
Jul 8, 2014

Conversation

carlobaldassi
Copy link
Contributor

As per the discussion in 1bbeeee.

This adds macro versions of

  • zip
  • enumerate
  • take/takestrict
  • drop
  • chain

which work on for loops. They all follow the same general syntax: whenever one would write

for VARS in ITERATOR(ARGUMENTS)
  BODY
end

the corresponding macro version is:

@ITERATOR for VARS in ARGUMENTS
  BODY
end

@timholy
Copy link
Member

timholy commented Jul 8, 2014

Really beautiful. I made a trivial variable-naming comment simply to prove I had looked at it 😄. I say merge at will.

@kmsquire
Copy link
Member

kmsquire commented Jul 8, 2014

I really like the idea here. I'd like to offer a thought on the interface.

Having the iterator name out front is necessary (because it's a macro, after all), but somewhat harder to read, in my opinion. What about something like

@zip for (x,y) in zip(a,b)
   @show x,y
end

Or, just using one macro for all iterators

@iterate for (x,y) in zip(a,b)
   @show x,y
end

In the first, the zip is obviously extraneous, but it's easier to see what's happening (and easier to switch back to the non-macro version).

The second would be harder to implement, and may not be worth it, but the syntax is easy (and also makes it easier to switch back to the non-macro version).

Thoughts?

@kmsquire
Copy link
Member

kmsquire commented Jul 8, 2014

Okay, @iterate doesn't work as a prefix, because there's already an iterator by that name. (Although I would prefer that one be named something like applyiter.)

@StefanKarpinski
Copy link
Contributor

How about @itr? It's sort of an annotation that the thing that's coming is a for loop over an iterator that should be transformed.

@kmsquire
Copy link
Member

kmsquire commented Jul 8, 2014

I like @itr.

@carlobaldassi
Copy link
Contributor Author

Using @itr to dispatch to the correct macro seems a good idea, I'll try that.

@carlobaldassi
Copy link
Contributor Author

@itr macro implemented.

@kmsquire
Copy link
Member

kmsquire commented Jul 8, 2014

LGTM

@carlobaldassi
Copy link
Contributor Author

Ok I'll squash, clean up a bit and merge.

Thie adds macro versions of
  * zip
  * enumerate
  * take/takestrict
  * drop
  * chain
The itr macro dispatches on those
carlobaldassi added a commit that referenced this pull request Jul 8, 2014
@carlobaldassi carlobaldassi merged commit 67487a4 into JuliaCollections:master Jul 8, 2014
@timholy
Copy link
Member

timholy commented Jul 8, 2014

Yay! Really nice to have this in Iterators. Will presumably get much more attention that way.

simonster added a commit to JuliaStats/DataArrays.jl that referenced this pull request Jul 8, 2014
simonster added a commit to JuliaStats/DataArrays.jl that referenced this pull request Jul 8, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants