ct
ct
MModular
Created by ct on 9/28/2023 in #questions
How can I create a Python list to add and remove structs?
Thanks for the reply
9 replies
MModular
Created by ct on 9/28/2023 in #questions
How can I create a Python list to add and remove structs?
I did read "https://docs.modular.com/mojo/programming-manual.html" a while ago and did not find how to use Python like list. There is an example of implementation of array but it is not dynamic.
9 replies
MModular
Created by Larsis on 9/14/2023 in #questions
Stackoverflow?
mojolang
3 replies
MModular
Created by ct on 9/13/2023 in #questions
newbie needs help with error messages
20 replies
MModular
Created by ct on 9/13/2023 in #questions
newbie needs help with error messages
I think the parens are necessary and should call the __init__ with "self" being provided
20 replies
MModular
Created by ct on 9/13/2023 in #questions
newbie needs help with error messages
This is what I got now:
@register_passable("trivial")
struct Item:
var name: StringLiteral
var qty: Int

fn __init__(inout self) -> Self:
return Self {name: "Unnamed", qty: 0}


fn main():
var item = Item()
var ls = DynamicVector[Item]()
ls.push_back(item)
print(ls[0].name)
print(ls[0].qty)
@register_passable("trivial")
struct Item:
var name: StringLiteral
var qty: Int

fn __init__(inout self) -> Self:
return Self {name: "Unnamed", qty: 0}


fn main():
var item = Item()
var ls = DynamicVector[Item]()
ls.push_back(item)
print(ls[0].name)
print(ls[0].qty)
error:
error: invalid call to '__init__': callee expects 1 argument, but 0 were specified
var item = Item()
error: invalid call to '__init__': callee expects 1 argument, but 0 were specified
var item = Item()
20 replies
MModular
Created by ct on 9/13/2023 in #questions
newbie needs help with error messages
does it download the 350MB or so or is it smart about it?
20 replies
MModular
Created by ct on 9/13/2023 in #questions
newbie needs help with error messages
do you have a newer version?
20 replies
MModular
Created by ct on 9/13/2023 in #questions
newbie needs help with error messages
mojo --version mojo 0.2.1 (64d14e85)
20 replies
MModular
Created by ct on 9/13/2023 in #questions
newbie needs help with error messages
this is what I get
@register_passable("trivial")
struct Item:
var name: StringLiteral
var qty: Int

fn __init__(inout self) -> Self:
self.name = "Unnamed"
self.qty = 0


fn main():
var item: Item = Item()
var ls = DynamicVector[Item]()
ls.push_back(item)
print(ls[0].name)
c@c:~/w/mojo-playground$ mojo hello.mojo
hello.mojo:15:26: error: invalid call to '__init__': callee expects 1 argument, but 0 were specified
var item: Item = Item()
~~~~^~
hello.mojo:9:5: note: function declared here
fn __init__(inout self) -> Self:
^
mojo: error: failed to parse the provided Mojo
@register_passable("trivial")
struct Item:
var name: StringLiteral
var qty: Int

fn __init__(inout self) -> Self:
self.name = "Unnamed"
self.qty = 0


fn main():
var item: Item = Item()
var ls = DynamicVector[Item]()
ls.push_back(item)
print(ls[0].name)
c@c:~/w/mojo-playground$ mojo hello.mojo
hello.mojo:15:26: error: invalid call to '__init__': callee expects 1 argument, but 0 were specified
var item: Item = Item()
~~~~^~
hello.mojo:9:5: note: function declared here
fn __init__(inout self) -> Self:
^
mojo: error: failed to parse the provided Mojo
20 replies
MModular
Created by ct on 9/13/2023 in #questions
What kind of list should I use to add struct instances
Thanks for the reply.
4 replies