ooc-lang / rock

:ocean: self-hosted ooc compiler that generates c99
http://ooc-lang.org/
MIT License
403 stars 40 forks source link

ArrayList sort #923

Closed davidhesselbom closed 8 years ago

davidhesselbom commented 9 years ago
import structs/ArrayList

a := ArrayList<Int> new()

a add(5).add(3).add(4)

for (i in 0..a size)
    a[i] toString() println()

a sort(func(left, right: Int) -> Bool { left > right })

for (i in 0..a size)
    a[i] toString() println()

prints

5
3
4

and then seems to get caught in an infinite loop.

davidhesselbom commented 9 years ago

Replacing

a sort(func(left, right: Int) -> Bool { left > right })

with

a sort(|left, right| left > right )

seems to work, though.

fasterthanlime commented 9 years ago

The first version is comparing pointers on 32-bit, and comparing garbage on 64-bit.

rock doesn't handle well passing non-ACS generic `functions...

(not handling well is an understatement).

alexnask commented 8 years ago

Closing this, see #934