flofriday / Moose

🐐 A new fun programming language
MIT License
6 stars 1 forks source link

Implement Double-Quote-Operator #20

Closed flofriday closed 1 year ago

flofriday commented 1 year ago

Example

a: Int = nil
print(a ?? "nothing") // prints nothing

Notes

I think we should implement it as its own AST Node and not as a custom operator.

Jozott00 commented 1 year ago

Yes, I guess it's the only way we could do this...

flofriday commented 1 year ago

I think so too. Maybe there is a way we could do it as an operator but it is a generic operator infix && (a: T, b: T) > T which I am not sure we can implement in the typechecker that easily. But other than that there are no restrictions on T as any object has the isNil computed member.

Jozott00 commented 1 year ago

Yes, currently we only support generics for builtin classes...

The other problem is, that normally this operator has a different evaluation flow, similar to ||. So only if the left expression was evaluated to nil, we evaluate the right expression.

flofriday commented 1 year ago

Actually we will rewrite them in the parser to the the ternary operator and I will implement them now together with the ternary operator.

flofriday commented 1 year ago

Implemented