Re: Nested list comprehension

2020-04-02 Thread cdunn2001
I don't see "collect" used in that comprehension module at all. Also, **comprehension** is slightly broken with nim-1.0.0. I haven't tried nim-devel yet. (I can only use official releases at work.)

Re: Nested list comprehension

2020-03-10 Thread Araq
You can always follow our github instructions to produce a Nim devel version. First get Nim from github: git clone [https://github.com/nim-lang/Nim.git](https://github.com/nim-lang/Nim.git) cd Nim build_all.bat

Re: Nested list comprehension

2020-03-10 Thread andrewgohlk
I'm using MSYS2/MINGW64, so can't use choosenim. :(

Re: Nested list comprehension

2020-03-08 Thread dawkot
As I said, you must use the devel version. You can install it with a tool called choosenim.

Re: Nested list comprehension

2020-03-08 Thread andrewgohlk
Hi, I encountered "Error: undeclared identifier: 'collect'"

Re: Nested list comprehension

2020-03-07 Thread dawkot
I generally only put brackets where neccessary. You can write this using devel version of nim (you can use choosenim) import tables, sugar, sets, sequtils proc cross(xs, ys: string): seq[string] = for x in xs: (for y in ys: result.add x & y) let rows =

Re: Nested list comprehension

2020-03-07 Thread didlybom
It would be nice if when something is deprecated in the standard library there was a link to the associated discussion/decision summary (if any). I found the deprecated list comprehension type a while ago and was curious about why it was deprecated.

Re: Nested list comprehension

2020-03-06 Thread whospal
Expected results... # Python output: unitlist = [['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1'], ['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2'], ['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3'], ['A4', 'B4', 'C4', 'D4', 'E4', 'F4', '

Re: Nested list comprehension

2020-03-06 Thread whospal
Expected results... # Python output: unitlist = [['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1'], ['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2'], ['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3'], ['A4', 'B4', 'C4', 'D4', 'E4', 'F4', '

Re: Nested list comprehension

2020-03-06 Thread whospal
Thanks for the info. Yes, I'd tried the sugar package but failed. Will checkout the comprehension package.

Re: Nested list comprehension

2020-03-06 Thread whospal
Thanks! Just a clarification, why your codes have the brackets around the y loop, and not around the result.add? cross(xs, ys: string): seq[string] = for x in xs: (for y in ys: result.add x & y) Run While @trtt has it around the result.add? cross(a, b

Re: Nested list comprehension

2020-03-06 Thread kaushalmodi
> how about you first get familiar with the correct Nim syntax for them? link Wait, you are linking against the deprecated lc syntax. I believe the closest non-deprecated solution is [https://github.com/alehander92/comprehension](https://github.com/alehander92/comprehension) ?

Re: Nested list comprehension

2020-03-06 Thread miran
> The documentation of Seq & Tables are very poor in Nim. Not many examples to > learn from. If something has a solid documentation and lots of examples, then it is `tables` module. :rolleyes:

Re: Nested list comprehension

2020-03-06 Thread miran
> I tried with... > > [invalid syntax] If you really want to force list comprehensions, how about you first get familiar with the correct Nim syntax for them? [link](https://nim-lang.org/docs/sugar.html#\[\].m%2CListComprehension%2Cuntyped%2Cuntyped) But my advice would be: don't use list comp

Re: Nested list comprehension

2020-03-06 Thread dawkot
This should work: import tables, strutils proc cross(xs, ys: string): seq[string] = for x in xs: (for y in ys: result.add x & y) let rows = "ABCDEFGHI" cols = "123456789" squares = cross(rows, cols) var unitSeq: seq[string] for c

Re: Nested list comprehension

2020-03-06 Thread whospal
Some more codes... # Python codes: unitlist = ([cross(rows, c) for c in cols] + [cross(r, cols) for r in rows] + [cross(rs, cs) for rs in ('ABC','DEF','GHI') for cs in ('123','456','789')]) units = dict((s, [u for u in unitlist if s in u]) for s i

Re: Nested list comprehension

2020-03-03 Thread whospal
@trtt & @miran, Thanks very much. Yes, i notice I made the mistake of the return type in the proc.

Re: Nested list comprehension

2020-03-03 Thread miran
There are few problems with your Nim version, e.g. returning `string` instead of `seq[string]` (cause this is what the Python version does - it returns a list). Here is a correct Nim version: proc cross(xs, ys: string): seq[string] = ## Cross product of elements in A and ele

Re: Nested list comprehension

2020-03-03 Thread trtt
That's not list comprehension in nim, you just iterated over two strings and then joined the elements without using them. proc cross(a, b: string): seq[string] = for ac in a: for bc in b: result.add(ac & bc) let digits = "123456789" let letters =

Nested list comprehension

2020-03-03 Thread whospal
quares = cross(rows, cols) Run I hit " Error: expression 'a & b' is of type 'string' and has to be discarded" Please help to explain how to convert the nested list comprehension. Thanks in advance.