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

List or Map elements cannot be modified in-place(?) #307

Open
SolarLune opened this issue Jan 7, 2025 · 0 comments
Open

List or Map elements cannot be modified in-place(?) #307

SolarLune opened this issue Jan 7, 2025 · 0 comments

Comments

@SolarLune
Copy link

SolarLune commented Jan 7, 2025

The following doesn't seem to work:

package main

import (
	"context"
	"fmt"

	"github.com/risor-io/risor"
)

func main() {

	src := `
	test := [0, 3, 17]
	for i := 0; i < 3; i++ {
		test[i] *= 0.1
	}
	print(test)
	`

	_, err := risor.Eval(context.Background(), src)
	if err != nil {
		fmt.Println(err)
	}

}

Got:

[0.1, 0.1, 0.1]

Expected output:

[0, 0.3, 1.7]

To work around this, you need to do test[i] = test[i] * 0.1.

EDIT: This also happens for maps.

@SolarLune SolarLune changed the title List elements cannot be modified in-place(?) List or Map elements cannot be modified in-place(?) Jan 7, 2025
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

1 participant