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

Negative loop step to iterate backwards #324

Open
lydell opened this issue Aug 1, 2014 · 4 comments
Open

Negative loop step to iterate backwards #324

lydell opened this issue Aug 1, 2014 · 4 comments

Comments

@lydell
Copy link
Collaborator

lydell commented Aug 1, 2014

$ echo "for a in b by -1 then c" | bin/coffee --js --no-optimise
// Generated by CoffeeScript 2.0.0-beta9-dev
void function () {
  var a;
  for (var i$ = 0, length$ = b.length; i$ < length$; i$ += -1) {
    a = b[i$];
    c;
  }
}.call(this);
$ echo "for a in b by -1 then c" | coffee -sc
// Generated by CoffeeScript 1.7.1
(function() {
  var a, _i;

  for (_i = b.length - 1; _i >= 0; _i += -1) {
    a = b[_i];
    c;
  }

}).call(this);

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/3447901-negative-loop-step-to-iterate-backwards?utm_campaign=plugin&utm_content=tracker%2F33145&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F33145&utm_medium=issues&utm_source=github).
@michaelficarra
Copy link
Owner

Fixed by 5272d3c.

@lydell
Copy link
Collaborator Author

lydell commented Aug 20, 2014

Nope.

~/CoffeeScriptRedux [master|✔] 
17:44 $ git checkout  5272d3c -q
~/CoffeeScriptRedux [:5272d3c|✔] 
17:44 $ echo "for a in b by -1 then c" | bin/coffee --js --no-optimise
// Generated by CoffeeScript 2.0.0-beta9-dev
void function () {
  var a;
  for (var i$ = 0, length$ = b.length; i$ < length$; i$ += -1) {
    a = b[i$];
    c;
  }
}.call(this);

Which is exactly the same output as in my original post.

This example might be clearer:

~/CoffeeScriptRedux [master|✔] 
17:53 $ bin/coffee -e --cli "for i in [1,2,3] by -1 then console.log i.toString 2"
1

(cli):10
    console.log(i.toString(2));
                  ^
TypeError: Cannot call method 'toString' of undefined
  at Object.<anonymous> ((cli):1:43, <js>:10:19)
  at Object.<anonymous> ((cli) <js>:12:3)
  at Module._compile (module.js:456:26)
  at runModule (/home/lydell/CoffeeScriptRedux/lib/run.js:100:17)
  at runMain (/home/lydell/CoffeeScriptRedux/lib/run.js:93:10)
  at processInput (/home/lydell/CoffeeScriptRedux/lib/cli.js:276:7)
  at Object.<anonymous> (/home/lydell/CoffeeScriptRedux/lib/cli.js:297:5)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)

~/CoffeeScriptRedux [master|✔] 
17:53 $ coffee -e "for i in [1,2,3] by -1 then console.log i.toString 2"
11
10
1

@lydell lydell reopened this Aug 20, 2014
@vendethiel
Copy link
Contributor

@lydell and congrats on that collaborator badge :-).

@michaelficarra
Copy link
Owner

Ah I see, the test is not changed for negative step loops. Okay, I understand now.

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

3 participants