If something like this were to change, it would be good to do it sooner rather than later -> less code that depends on the syntax that would go would have been written. So maybe the right way forward for this is to open an issue suggesting to drop the = variant, discuss it, make a decision and then live with it, all for the 0.5 cycle.
I don’t feel strongly about this, but for what it’s worth, I’m also a fan of having only one way to do something like this. Cheers, David From: julia-users@googlegroups.com [mailto:julia-users@googlegroups.com] On Behalf Of FANG Colin Sent: Tuesday, October 27, 2015 11:20 AM To: julia-users@googlegroups.com Subject: Re: [julia-users] Re: For loop = or in? Julia tries to attract people from Python & R, which use `in`. As for matlab, it is not a direct competitor. Anyway, I think we only need 1 of the 2. "There should be one-- and preferably only one --obvious way to do it." Maybe enhance the documentation for the time being. On 27 October 2015 at 16:38, Glen O <gjo1...@gmail.com <mailto:gjo1...@gmail.com> > wrote: "When calculating a Fibonacci number, we have to apply F_n=F_(n-1)+F_(n-2) repeatedly. So to find F_6, we apply the equation for n equals 3 through 6". Writing it as "for n in 3 through 6" or "for n in the range 3 through 6" wouldn't make nearly as much sense. As I said, for general iterables, like vectors, the "in" keyword makes more sense. But when you're talking about a counter variable, equals makes a much more natural expression - you're not really constructing the range object, you're just telling the program you want the counter to start at the first value, and increment until it reaches the second value. On Wednesday, 28 October 2015 02:23:54 UTC+10, Tom Breloff wrote: It definitely makes sense for a range. Sorry... gotta disagree... mathematical set notation is more appropriate, especially for scientific computing. This is coming from a former matlab user, btw, so it's not like I was confused by the syntax. The "for i = 1:5" syntax is actually more reminiscent of C: "for (int i=1; i<=5; i++)", and I'm guessing that the syntax originated more from that rather than scientific concepts. On Tue, Oct 27, 2015 at 11:58 AM, feza <moham...@gmail.com <mailto:moham...@gmail.com> > wrote: +1 @Tom Breloff . I was confused about this when starting out. Comparing `for i in 1:3` vs `for i = 1:3`, even though I regularly use matlab if you think about it for `i = 1:10` doesn't really make a lot of sense. It would be nice if it was just one way as opposed to the confusion about whether = or in should be used. On Tuesday, October 27, 2015 at 10:26:44 AM UTC-4, Tom Breloff wrote: It's harmless, sure, but I would prefer that everyone uses "in" exclusively so that there's one less thing to waste brainpower on. You don't say "for each x equals the range 1 to n", you say "for each x in the range 1 to n". I don't think "=" has a place here at all except to allow copy/pasting of Matlab code (which creates other performance problems anyways). On Tue, Oct 27, 2015 at 10:04 AM, Stefan Karpinski <ste...@karpinski.org <mailto:ste...@karpinski.org> > wrote: My general approach is to only use = when the RHS is an explicit range, as in `for i = 1:n`. For everything else I use `for i in v`. I would be ok with dropping the = syntax at some point, but it seems pretty harmless to have it. On Tue, Oct 27, 2015 at 8:56 AM, FANG Colin <coli...@gmail.com <mailto:coli...@gmail.com> > wrote: Thank you. In that case I will happily stick with `in`. On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote: There is no difference, as far as I know. '=' seems to be used more for explicit ranges (i = 1:5) and 'in' seems to be used more for variables (i in mylist). But using 'in' for everything is ok too. The '=' is there for familiarity with matlab. Remember that julia's syntax was in part designed to be familiar to matlab users. On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote: Hi All I have got a stupid question: Are there any difference in "for i in 1:5" and "for i = 1:5"? Does the julia community prefer one to the other? I see use of both in the documentations and source code. Personally I haven't seen much use of "for i = 1:5" in other languages. Thanks.