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

Added support for SWAP and WITH_EXCEPT_START #485

Closed
wants to merge 9 commits into from

Conversation

ddouworld
Copy link
Contributor

@ddouworld ddouworld commented May 27, 2024

WITH_EXCEPT_START is simply put together with SETUP_WITH_A, but it works fine.
The test code for SWAP is as follows

def SWAP():
    my_array = [
        1,
        2,
        3,
        4,
        5,
        6,
        8]
    i = 1
    j = 3
    my_array[i], my_array[j], my_array[2] = my_array[j], my_array[i], my_array[4]

The generated code looks like this

def SWAP():
    my_array = [
        1,
        2,
        3,
        4,
        5,
        6,
        8]
    i = 1
    j = 3
    (my_array[i], my_array[j], my_array[2]) = (my_array[j], my_array[i], my_array[4])

It's not quite the same, but I don't think it should affect function much

@ddouworld ddouworld changed the title Added support for SWAP_A and WITH_EXCEPT_START Added support for SWAP and WITH_EXCEPT_START May 27, 2024
@TiZCrocodile
Copy link
Contributor

the problem with this:

my_array[i] = my_array[j]
my_array[j] = my_array[i]
my_array[2] = my_array[4]

is that the logic changes, for example

x=1
y=2
x,y = y,x

would replace them, but this

x=1
y=2
x = y
y = x

would result in both variables equals to y, because after x = y, now y = x, means y = y

@ddouworld
Copy link
Contributor Author

Yes, you're right. I think I need to change it

@ddouworld ddouworld closed this Jun 1, 2024
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

Successfully merging this pull request may close these issues.

2 participants