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

[improvement] Support for backward for loop like in python #70

Open
shazz opened this issue Oct 21, 2020 · 1 comment
Open

[improvement] Support for backward for loop like in python #70

shazz opened this issue Oct 21, 2020 · 1 comment

Comments

@shazz
Copy link
Contributor

shazz commented Oct 21, 2020

As a workaround, a js plugin works well but as you implemented the python style for loop style using range(), could be nice to also support backwards loop like

for i in range(10, 0, -1)

Here is my javascript plugin:

module.exports = {
    reverse: ({}, val) => {
        return val.reverse();
    }
}

ex:

!for i in syn.reverse(range(SPRITES_NB)) {
... 	
@nurpax
Copy link
Owner

nurpax commented Feb 7, 2021

BTW, the python range is IMO a bit funky:

>>> list(range(10, 0, -1))
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

This is not the same as just looping the list in reverse:

>>> list(reversed(range(0, 10)))
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

Looks like a great source of off-by-one errors.

Alternative would be to add a built-in reversed() function like in Python. This would be the same as your plugin, except built-in.

Do we want to pollute the symbol namespace with many functions like this? Or maybe something like:

!for i in range(10).reverse() {
}

This type of array prototype calling convention is not currently supportd in c64jasm.

PS:

module.exports = {
    reverse: ({}, val) => {
        return val.reverse();
    }
}

Whoops! JavaScript reverse() is in-place. You should not mutate the plugin input arguments. (I should document this!)

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