risor-io / risor

Fast and flexible scripting for Go developers and DevOps.
https://risor.io
Apache License 2.0
576 stars 24 forks source link

Potential expression issue #243

Open saracen opened 1 month ago

saracen commented 1 month ago

Hey @myzie

I've recently been evaluating risor for a project and was surprised by this being allowed:

a := 123

a a a a // returns 123

and

fn := func() {}
a := 123
fn{}a{}fn{}true

I understand that this is because each of these are individual expressions, and they're not invalid, but it can account for some weird errors if you're not too familiar with the language. For example, I mistakening thought that to create a map, I needed to use the syntax map{a: 123}. But map is a built-in.

m := map{a: 123}
m["a"]

Rather than a parser or compile error, you get a runtime error of type error: object is not a container (got builtin) which is a little confusing.

Do you suspect this could be improved? Should this be a parser/compile error? Thank you!

myzie commented 1 month ago

Hi @saracen, I agree about the multiple expressions on a line being odd that it’s allowed. I’ll make a change to disallow it. I’ve been aware of it but no one has brought it up as an issue yet.

The map built in example is a bit tricky. I see that it could be a common source of confusion. Maybe renaming or removing that built in by default would be fine. IIRC that was built to be like the “dict” constructor in python.

Thanks for evaluating Risor and feel free to reach out with more suggestions. You could join the risor channel on the gophers slack too if you want.