vtereshkov / umka-lang

Umka: a statically typed embeddable scripting language
BSD 2-Clause "Simplified" License
1.08k stars 53 forks source link

Clear distinction between storing a value and storing a pointer in an interface #441

Open vtereshkov opened 3 months ago

vtereshkov commented 3 months ago

Umka could do it the same way as Go does. This would be more consistent than Umka's interfaces.

image

However, it would require two extra features:

skejeton commented 3 months ago

Why would it needs methods on non pointer receivers?

vtereshkov commented 3 months ago

@skejeton For consistency. For example, you can treat methods on non-pointer receivers as const methods in C++, i.e., the only methods applicable to a const object. When I put a non-pointer value into an interface, this value may be a const. What would a method acting on a pointer receiver mean here? That the constant should be addressable? That the method could modify it?

skejeton commented 3 months ago

@vtereshkov But the value type interface isn't immutable/const. On a normal value type you can call methods with pointer receivers, which implicitly takes reference of itself.

vtereshkov commented 3 months ago

@skejeton On a value-typed var you can, on a value-typed const you cannot.

skejeton commented 3 months ago

@vtereshkov Makes sense, but this is about const/var, not imterfaces. Isn't it?

vtereshkov commented 3 months ago

@skejeton Interface methods should act exactly as the corresponding concrete type methods. They shouldn't expect a pointer to a const, for example.

skejeton commented 3 months ago

@vtereshkov i don't get it, why are we talking about consts?

skejeton commented 3 months ago

I think I understand what you meant now. Now that we don't have structured constants, do we need value typed methods?