Using map on ArrayList and then join gives segmentation fault

38 views
Skip to first unread message

jonath...@gmail.com

unread,
Jul 30, 2015, 5:02:37 AM7/30/15
to ooc-lang
Hello

This is the code:
import structs/[ArrayList, List]

a := [1, 2, 3] as ArrayList<Int>
b := a map(func (value: Int) -> String { value toString()})
b join(", ") println()

When I run the above code with rock I get this:
(SIGSEGV) segmentation fault
[lang/Backtrace] Falling back on execinfo.. (build extension if you want fancy backtraces)
./GenericFuncInClassTest(lang_Backtrace__BacktraceHandler_backtrace_impl+0xf0) [0x44275e]
./GenericFuncInClassTest(lang_Backtrace__BacktraceHandler_backtrace+0x20) [0x443398]
./GenericFuncInClassTest(lang_Exception__Exception_getCurrentBacktrace+0x22) [0x42fa2b]
./GenericFuncInClassTest(lang_Exception___signalHandler+0x1a7) [0x43098b]
/lib/x86_64-linux-gnu/libc.so.6(+0x36d40) [0x7f3b701a8d40]
./GenericFuncInClassTest(structs_List__List_itemsSizeInBytes_impl+0x72) [0x43a056]
./GenericFuncInClassTest(structs_List__List_itemsSizeInBytes+0x23) [0x43a97c]
./GenericFuncInClassTest(structs_List__List_join_string_impl+0x20) [0x43a11f]
./GenericFuncInClassTest(structs_List__List_join_string+0x2e) [0x43a9d1]
./GenericFuncInClassTest(GenericFuncInClassTest_load+0x1b9) [0x42b596]
./GenericFuncInClassTest(main+0x1e) [0x42b5d5]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f3b70193ec5]
./GenericFuncInClassTest() [0x42b319]


Am I doing anything wrong or is this an issue with rock?

/Jonathan

Amos Wenger

unread,
Jul 30, 2015, 5:54:17 AM7/30/15
to jonath...@gmail.com, ooc-lang
Your code should definitely work, but (*sigh*) rock probably generates invalid code without even erroring.

This equivalent code works:

import structs/ArrayList
([1, 2, 3] as ArrayList<Int>) map(|x| x toString()) join(", ") println()

(The important difference is in the call to map).

Cheers,
- Amos

--
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 ooc-lang+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jonath...@gmail.com

unread,
Jul 30, 2015, 7:43:01 AM7/30/15
to ooc-lang, amosw...@gmail.com

Thank you it works now

/Jonathan

jonath...@gmail.com

unread,
Jul 30, 2015, 8:28:22 AM7/30/15
to ooc-lang, amosw...@gmail.com
On Thursday, July 30, 2015 at 11:54:17 AM UTC+2, fasterthanlime wrote:

I ran into a new problem when trying to implement fold.

This is the fold code:
fold: func <T,S> (function: Func(T, S) -> S, initial: S) -> S {
for(i in 0..this count)
initial = function(this[i], initial)
initial
}

This is how I'm trying to use it:
import structs/[ArrayList, List]

a := [1, 2, 3] as ArrayList<Int>

b := a fold(|x, y| x toString() + y, "START")

And this is the error:
rock/./GenericFuncInClassTest.ooc:5:8 error Not enough info to resolve return type S of function call


b := a fold(|x, y| x toString() + y toString(), "START")


Is there a way to write the code to make it understand the return type?

/Jonathan

Amos Wenger

unread,
Jul 30, 2015, 10:02:07 AM7/30/15
to jonath...@gmail.com, ooc-lang
I'm afraid not. It was probably broken in rock 0.9.10, when it became stricter on generics..

We're reaching the limits of what rock can do with generics due to its design. You could report an issue to https://github.com/fasterthanlime/rock/issues, see if shamanas or someone else is willing to fix it, but I'm now focusing my efforts on cork — you can see the discussion here: https://github.com/fasterthanlime/cork/issues/1

In the meantime, I'd suggest settling for more imperative code :(

Cheers,
- Amos

jon...@gmail.com

unread,
Jul 30, 2015, 10:58:16 AM7/30/15
to ooc-lang
Thank you for fast answers :)
I'ts nice to know the reson to the problem even if it dosen't solve it.

/Jonathan

Reply all
Reply to author
Forward
0 new messages