Hi, I'm new to Nim-lang.

I wanted to convert a Python script to Nim to improve my understanding of Nim.

I have the following Python code: 
    
    
    # Python codes:
    def cross(A, B):
        """Cross product of elements in A and elements in B."""
        return [a+b for a in A for b in B]
    
    digits   = '123456789'
    rows     = 'ABCDEFGHI'
    cols     = digits
    squares  = cross(rows, cols)
    
    
    Run

I tried to convert to Nim code but failed: 
    
    
    # Nim codes:
    proc cross(A: string, B: string): string =
        ## Cross product of elements in A and elements in B.
        result = string:
            for a in A:
                for b in B:
                    a&b
    
    let digits   = "123456789"
    let rows     = "ABCDEFGHI"
    let cols     = digits
    
    var squares  = 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.

Reply via email to