Skip to content

Iterator with openArray parameter make the argument evaluated many times #13417

Closed
@slangmgh

Description

@slangmgh

When using openArray type in iterator, if the argument is function call, it will be evaluated many times.

Example

proc p1(): seq[int] =
   echo "next"
   @[1,2]

iterator ip1(v: openArray[int]): auto =
   for x in v:
      yield x

for x in ip1(p1()):
   echo x

Current Output

next
next
1   
next
next
2   
next

Expected Output

next
1
2
$ nim -v
Nim Compiler Version 1.1.1 [Windows: i386]
Compiled at 2020-01-27
Copyright (c) 2006-2019 by Andreas Rumpf

active boot switches: -d:release

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions