Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bikeshedding filtered generator syntax #16428

Closed
ararslan opened this issue May 18, 2016 · 3 comments
Closed

Bikeshedding filtered generator syntax #16428

ararslan opened this issue May 18, 2016 · 3 comments

Comments

@ararslan
Copy link
Member

ararslan commented May 18, 2016

This started coming up in #16389 but it's a little off topic, so perhaps we should branch this discussion out into a separate issue.

@StefanKarpinski mentioned the nice, familiar syntax

x^2 if x % 3 == 0 for x = 1:100

which follows more closely what other languages do.

I had also proposed using where, e.g.

x^2 for x = 1:100 where x % 3 == 0  # or,
x^2 where x % 3 == 0 for x = 1:100

This, at least in my mind, makes the filtering aspect a little clearer than if, since if looks like it should be modifying the computation rather than the iterator. (Which perhaps is a little narrow-minded of me.)

Thoughts?

@ararslan
Copy link
Member Author

I could also imagine where extending to other scenarios, e.g.

s = 0
for x = 1:100 where x % 3 == 0
    s += 1
end

This super contrived example would be equivalent to

s = 0
for x = 1:100
    if x % 3 == 0
        s += 1
    end
end

(or whatever single-line if comes about from #16389)

@JeffBezanson
Copy link
Member

This can be moved to #550. We are also likely to use where for #11310.

@ararslan
Copy link
Member Author

@JeffBezanson Okay, sounds good. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants