JSAbrahams / mamba

🐍 The Mamba programming language, because we care about safety
MIT License
85 stars 3 forks source link

Wrap literals so that we may do method calls directly #278

Closed JSAbrahams closed 2 years ago

JSAbrahams commented 2 years ago

The desugar stage should wrap literals in function calls. This is so that they are treated as objects (which is also why all literal types are capitalized in Mamba, for consistency).

For instance, in Mamba:

def a: Int := 10
print(a.to_bytes(10, "little"))

which desugars to

a = 10
print(a.to_bytes(10, "little"))

Which works fine

However, we also want to be able to one-line this:

print(10.to_bytes(10, "little"))

Which desugars to

print(10.to_bytes(10, "little"))

Which Python does not like.

So we need:

JSAbrahams commented 2 years ago

Actually, the only literals which are troublesome are int and float. And these I think are best left as-is.