dddxxx
dddxxx

Reputation: 359

Nim-lang: list comprehension with two variables

Confused on how to perform a list comprehension using two variables.

Here's what i'm trying to do so far:

let profile_row = lc[profile[r][c] | ( r <- 0..<4, c <- 0..<k ), int]

Here's the error:

greedy_motif_ba2d.nim(22, 40) Error: type mismatch: got <seq[int], float>

How is this correctly done?

Upvotes: 2

Views: 613

Answers (2)

shirleyquirk
shirleyquirk

Reputation: 1598

Since Nim 1.2 lc has been removed so here's how to do this for anyone searching today:

let profile_row = collect(newSeq):
  for r in 0..<4:
    for c in 0..<4:
      profile[r][c]

note collect removes the need to specify the type of of profile[r][c] but requires you to supply an initialization proc for the container profile_row

Upvotes: 2

dddxxx
dddxxx

Reputation: 359

Turns out that the way I did it does actually work, just needed to change the type.

let profile_row = lc[profile[r][c] | ( r <- 0..<4, c <- 0..<k ), float]

Upvotes: 2

Related Questions