How to handle a seq as a return value in Nim

Viewed 1172

I am running into a problem with Nim sequences and returning them from a function.

json_p.nim(42, 33) template/generic instantiation from here
json_p.nim(28, 22) Error: no generic parameters allowed for seq

Line 28 is where I define my key_list

proc get_json_keys(json_data: JsonNode) : seq =
    var key_list: seq[string] = @[] # 28
    var key: string
    for record in json_data:
        for key, value in record:
            if (not key_list.contains(key)):
                key_list.add(key)
    return key_list

I just call it from a main.

proc main() : void =     
    var file = get_url()
    var json_data = file.parseFile()

    [...]

    var key_list = get_json_keys(json_data)
    for key in key_list:
        echo key

The code works fine inside the main function.

1 Answers
Related