The copy doesn’t worry me if the behavior is consistent. But, there is 
something I don’t understand.

In this program
    
    
    proc p() =
      let x = "abc"
    
    
    Run

there is a string copy (and an allocation) for "x".

But in this one 
    
    
    proc p() =
      var a = "abc"
      let x = a
    
    
    Run

there is no string copy for "x", which may cause problems if "a" is modified 
later. "x" is indeed an alias for "x" (with all the problems of aliases which 
Nim normally avoids).

There is no risk to directly assign the pointer in the first case. So why is 
there a questionable optimization in the second case and not in the first case 
where it would be safe?

Reply via email to