Open soraros opened 1 month ago
+1 to this, conveys the same meaning with a more succinct syntax, definitely more Pythonic.
I don't think that making it shorter is the only motivation, it is also about consistency: I'd suggest using initializer syntax, so that "creating a T" is always done with initializers.
If we did that, it would argue for something like Pointer(to=x)
or Pointer(at=x)
or Pointer(of=x)
or Pointer(address=x)
etc.
Yesss, this will even spare having to set the type that the pointer is for since it can be inferred :+1:
Pointer(at=x) [...] Pointer(address=x)
these ones in particular might be confusing if you pass an Int and you come from the C world though
Opened PR #3606 but I'm getting a segfault for _ListIter
even though I only added a constructor for Pointer
and didn't touch any more code :/
If we did that, it would argue for something like
Pointer(to=x)
orPointer(at=x)
orPointer(of=x)
orPointer(address=x)
etc.
More broadly speaking, the fact that Mojo supports function overloads opens the door to Swift-style, argument-label-rich API designs. I'm overall supportive to this approach, but we also need to aware of the trade-offs.
For object initialisation, static methods (technically classmethods
) are like a "poor man's" overloading in Python. They do have some advantages though:
range
to support 3 different arities).Pointer
, but it could be important for Python interoperability for some other types (especially when called from Python).
Review Mojo's priorities
What is your request?
As title. Maybe to
Pointer(to=thing)
.What is your motivation for this change?
UnsafePointer
andPointer
are consistent, I am happy"Any other details?
For the bike-shading crowd: I mostly just moved Chris's comments from Discord, please don't shoot the passenger.