Error with method append with string
When im try use List for string a get error
Error:
11 Replies
Hey, the error message is a bit unclear, but it means that you can only use simple
@register_passable
structs in lists (which String
is not)
You can use a StringLiteral
which is immutable but may be enough for what you're trying to achieve.
I made StringLiteral, and already another error.
append
is a mutating method that must modify the underlying storage, but you declared the variable as let
(immutable)
You have to declare the list as a var
Thanks It works)
If you still want a list that you can't modify later you can initialize it upfront
Is there a way to create a list for a String type on the heap?
As far as I know you can't have pointers in a list yet either so I doubt it
Not sure why considering it has no destructor but
Pointer
is not @register_passable
how to get rid of this warning
I don’t think this is related so this should be a different question
You’re not using the potential return values, discard them by assigning these to an underscore with _ =
_= is it the only way
here the return values are just useless
You’re interacting with Python, an untyped, dynamic language, so there’s no way to be sure it won’t actually return anything
This is not a problem unique to Mojo when it comes to this kind of interoperability
You seem to already be discarding return values in your screenshot so I’m not sure what the issue is