Skip to first unread message


Mar 15, 2015, 12:28:45 PM3/15/15
Hi, me again :-)

the following code fails:
  assert([1] == [1])

how should I fix that?
do I need to extend == for arrays? if so, where is that code.
Thanks alot

Amos Wenger

Mar 15, 2015, 12:36:33 PM3/15/15
to kobi2187,
Unfortunately, arrays are kind of a sore spot in ooc right now.

You've got C pointers, e.g.

a: Int* = gc_malloc(10 * Int size)
a[0] = 42 // etc.

If you compare those, it does a pointer comparison

You've also got ArrayLists, e.g.:

a := ArrayList<Int> new()
a add(42)

But `==` is not overloaded on those in a generic way because nothing tells you that the content of the ArrayList is going to be comparable.

And then there's ooc arrays, which are kind of a weird beast, implemented in C with a struct (pointer + length), and they're an endless source of bugs and confusion for new users - and you can't really do anything useful with operator overloads there as well.

ooc arrays implementation (which you use in your code sample) is contained mostly in this file: and the rest is internal compiler logic.

It's a bit weird when coming from languages like Python/Ruby that you're not able to just compare arrays by value, and that they're not that much of a strong built-in in ooc, and that's a shame, but that's the current state of things.

In practice, I mostly use ArrayList<T> whenever I'm not too worried about size/performance, and otherwise I go with either C pointers or ooc arrays, while remaining well aware of their limitations (ie. probably better wrapped in a class or a cover, with some utility methods for comparison and all the things you'd need to do with them).

- A

You received this message because you are subscribed to the Google Groups "ooc-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Reply all
Reply to author
0 new messages