Replies: 1 comment 5 replies
-
Hello, as a relatively new person learning the mojo language, contributions for the last questions:mojo do have an object type (see the matmul example and Object): def main():
var a = object([0,1])
var b = a
b[0] = 1
print(a) #[1, 1]
print(b) #[1, 1] It also have a PythonObject type: def main():
var a = PythonObject([0,1])
var b = a
b.__setitem__(0,1)
print(a) #[1, 1]
print(b) #[1, 1] Implementing a generic struct with pointers is also a possibility ( non memory only types or register_passable for T). Pretty sure with lifetimes it is gonna be ergonomical and obviously safer by design. For the fact that a
|
Beta Was this translation helpful? Give feedback.
-
The difference between name spaces and object space is very important in Python (for which names are just references to objects) and it has to be understood quite soon by Python beginners.
I understood that Mojo works completely differently (for example an assignment
a = b
leads to a copy, arguments passing much more advanced than in Python). I think there could be a section quite early somewhere in the documentation to explicitly discuss this important difference. It could be very useful for Python developers who can simply assume that an assignmenta = b
just create a new reference.For example in https://docs.modular.com/mojo/programming-manual.html#the-__copyinit__-__moveinit__-and-__takeinit__-special-methods, there is
I guess that for most Python dev without experience in another static language, this feels strange (at least too much information: (i) assignment means copy and (ii) object not copyable without
__copyinit__
).Moreover, I somehow see how I could implement Mojo objects that mimic the behavior of Python types. But I don't get how one could implement a
list
in mojo to get something as simple asIs it already possible? Will it be possible? How could it be done?
Beta Was this translation helpful? Give feedback.
All reactions