artemiogr97
MModular
•Created by artemiogr97 on 4/14/2024 in #questions
Optional string argument
Is there a simple way to create a function that takes an optional String argument with no default value (assigned to None) ? I tried the following:
this works for a
String
but calling the function with a StringLiteral
does not: my_func("my_string")
gives the following error invalid call to 'my_func': argument #0 cannot be converted from 'StringLiteral' to 'Optional[String]'
I guess one way to make it work for now is to use a default value as follows:
But this does not allow to distinguish between a bad input and an empty imput17 replies
MModular
•Created by artemiogr97 on 4/4/2024 in #questions
Lifecycle doc clarification
I was reading https://docs.modular.com/mojo/manual/lifecycle/life#move-constructor, the following struc is given as an example:
what does
Then the lifetime of "existing" ends here, but Mojo does NOT call its destructor
mean? I understand that existing.data must not be free but what about existing.size? is it freed even though the destructor is not called? in theory a copy was made by doing self.size = existing.size
5 replies