**Araq** : Start by not capturing elements in:
    
    
    (index.with_length length).sort do (a, b: int) -> int:
        elements[a].cmp elements[b]
    
    
    Run

Before **janAkali** 's kind help. .. I resorted to the **temporary copy hack** 
in the above code. I just thought there should be a better way if I just had 
enough _nim foo_ 🙂

**Araq** : And in general it helps to know the language.

I can't argue with you there 🙂

**Araq** : For example
    
    
    cast[ptr UncheckedArray[T]](cast[pointer](alloc(n * sizeof(T))))`
    
    
    Run

> should be
    
    
    cast[ptr UncheckedArray[T]](alloc(n * sizeof(T)))
    
    
    Run

Yes... much better... (_although I suspect a good optimizing C compiler would 
have generated very similar machine code... but just sloppy on my part_). 
Thanks.

**Araq** : Also, a compiler error message is the opposite of a "runtime error".

I don't understand. The reported error was generated at **runtime**
    
    
    dennismisener@Denniss-iMac nim % nim --hints:off check  test_sortOrder.nim
    
    dennismisener@Denniss-iMac nim % nim --hints:off r  test_sortOrder.nim
    /Users/dennismisener/work/Nim/test_sortOrder.nim(33, 5) Error: 'elements' 
is of type <var openArray[string]> which cannot be captured as it would violate 
memory safety, declared here: 
/Users/dennismisener/work/Nim/test_sortOrder.nim(43, 20); using 
'-d:nimNoLentIterators' helps in some cases. Consider using a <ref var 
openArray[string]> which can be captured.
    
    
    Run

And yes... I suspect this could have been detected at compile time.... but 
whether it is worth the effort to implement such checking is probably only know 
to you 🙂

Reply via email to