rdickert
Explore posts from serversMModular
•Created by rdickert on 1/1/2024 in #questions
Passing generics to DynamicVector
I'm trying to understand the traits system and am working with a toy
list
struct from this thread
The original declaration (which works) starts with:
In the above I can declare a list of strings with list[String]
I have tried to add the ability to print items in the list
, but CollectionElement
s aren't accepted by str
(errors with "no matching function in call to 'str'"), so I tried making a trait that inherits from both requirements:
This removes the compile error in my print method, but then I can no longer declare list[String]
. In this declaration
the compiler errors with "'list' parameter #0 has 'ListElement' type, but value has type 'String'". But it seems like String
should satisfy my new trait since it satisfied CollectionElement
and should certainly satisfy Stringable
. Am I doing something wrong, or is this a current bug/limitation of Mojo?1 replies
MModular
•Created by rdickert on 11/27/2023 in #questions
Errors for flow control?
Exceptions are used for flow control in Python (e.g. the
StopIteration
exception). Is this considered a good/normal practice in mojo as well (using Error
I guess)?3 replies