M
Modular4mo ago
MRiabov

How to iterate through an array/list?

Hello, I'm coming from Java to Mojo. It seems there is no support for iterating with "for" through a list - at least in the present version of Mojo. Here's the code:
def createFreeformExtrusion(lines:((Int,Int),(Int,Int),Optional[(Int,Int)])[], height)->String: # currently without curves.
code=""
for line in lines:
if line[2]:
def createFreeformExtrusion(lines:((Int,Int),(Int,Int),Optional[(Int,Int)])[], height)->String: # currently without curves.
code=""
for line in lines:
if line[2]:
Should work, doesn't it? It does work in Python. Thanks.
5 Replies
Serg Gini
Serg Gini4mo ago
lines looks like Tuple, not like List. Why not List((Int, Int),...) ?
MRiabov
MRiabov4mo ago
Throws an error.
No description
MRiabov
MRiabov4mo ago
it's strange to me as well
Ryulord
Ryulord4mo ago
Tuples are still a little rough around the edges last time I checked. You also can't use a list here unless you also use a variant since lists must be of a single type. I'd probably just make a simple struct since the type is quite large and unwieldy looking.
@value
struct Point:
var x: Int
var y: Int

@value
struct Lines:
var a: Point
var b: Point
var c: Optional[Point]
var d: Bool
var e: Bool

fn create_freeform_extrusion(lines: Lines, height: Float32) -> String:
@value
struct Point:
var x: Int
var y: Int

@value
struct Lines:
var a: Point
var b: Point
var c: Optional[Point]
var d: Bool
var e: Bool

fn create_freeform_extrusion(lines: Lines, height: Float32) -> String:
ModularBot
ModularBot4mo ago
Congrats @Ryulord, you just advanced to level 6!
Want results from more Discord servers?
Add your server