M
Modular15mo ago
shBLOCK

Compile time properties?

Is it possible to make compile-time properties for structs? Mojo doesn't seems to support @property right now. So the only way to implement custom properties in mojo right now is to use the __getattr__() function, which isn't a performant solution. I want to make some vector classes that support "swizzling" like in GLSL (e.g. Vec3(1,2,3).xz gives Vec3(1,3)). I achieved this in Cython by generating every possible combinations (about 50k lines). But I think with advanced parameterization in mojo, this can potentially be much simpler while keeping maximum performance. I'm not sure if this is already possible in mojo somehow. I will open an issue on github if this interests many people.
5 Replies
gabrieldemarmiesse
I already made an issue on github for this, feel free to give it a thumbs up! But if you're asking specifically about something fully at compile time, structs accept the var keyword for attributes but they also accept "alias" for compile time attributes
shBLOCK
shBLOCKOP15mo ago
Did you read the part about "swizzling"? I want something more advanced than just @property. (More closed to the customizability of __getattr__(), but compile-time) This probably won't work well with auto-completion out-of-the-box though. (By the way, the Cython library I was talking about is here: https://github.com/shBLOCK/GdMath)
ModularBot
ModularBot15mo ago
Congrats @shBLOCK, you just advanced to level 1!
gabrieldemarmiesse
My bad, this is more in the realm of compile-time metaprogramming. I know it's a language feature that they want to add later on, but there is no timeline
shBLOCK
shBLOCKOP15mo ago
Yeah, I've read the doc and they said they would let you take basically full control of the compilation process, that would probably be one way to achieve what I wanted, but I think there could be easier ways to do this (considering the cool meta-programming features already implemented by parameterization). I will make an github issue about this. (btw, I'm sorry if my language seems a bit harsh, I'm not a native English speaker.) Also, vector swizzling is already doable in mojo with parameterization, but the syntax won't be convenient. (for example like this: Vec3(1,2,3).swiz["zxy"]())
Want results from more Discord servers?
Add your server