Why do we need openArray? Rather what is the difference between openArray and 
seq?
    
    
    var
      fruits:   seq[string]       # reference to a sequence of strings that is 
initialized with '@[]'
      capitals: array[3, string]  # array of strings with a fixed size
    
    capitals = ["New York", "London", "Berlin"]   # array 'capitals' allows 
assignment of only three elements
    fruits.add("Banana")          # sequence 'fruits' is dynamically expandable 
during runtime
    fruits.add("Mango")
    
    proc openArraySize(oa: openArray[string]): int =
      oa.len
    
    assert openArraySize(fruits) == 2     # procedure accepts a sequence as 
parameter
    assert openArraySize(capitals) == 3   # but also an array type
    
    
    Run

However the same can be achieved using seq as well. Like
    
    
    var
      fruits:   seq[string]       # reference to a sequence of strings that is 
initialized with '@[]'
      capitals: array[3, string]  # array of strings with a fixed size
    
    capitals = ["New York", "London", "Berlin"]   # array 'capitals' allows 
assignment of only three elements
    fruits.add("Banana")          # sequence 'fruits' is dynamically expandable 
during runtime
    fruits.add("Mango")
    
    proc openArraySize(oa: seq[string]): int =
      oa.len
    
    assert openArraySize(fruits) == 2     # procedure accepts a sequence as 
parameter
    assert openArraySize(@capitals) == 3   # but also an array type
    
    
    
    Run

Isn't openArray redundant?

Reply via email to