koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.26k stars 162 forks source link

List additions #321

Open Matthew-Mosior opened 1 year ago

Matthew-Mosior commented 1 year ago

This adds the permutations function which is a port of the OCaml permutations function found in this Rosetta Code page:

https://rosettacode.org/wiki/Permutations#OCaml

Matthew-Mosior commented 1 year ago

@daanx @anfelor @timjs

When using the list\<int> permutation function, there seems to be an issue when using a list > 8 in length (i.e. [1,2,3,4,5,6,7,8,9]), I'm seeing:

core dumped. on my ubuntu linux workstation (x86_64)

and

rosetta error: unexpectedly need to EmulateForward on a synchronous expection ... on my M1 mac running in rosetta (emulating x86_64 environment).

It similarly crashes on my M1 mac when run without rosetta mode.

I've tried using both gcc/clang as the backend compiler, see the error either way.

But testing by inputting a list of length <= 8 works fine.

Could this be an issue in the perceus reference-counting implementation?

I tested using the following Koka script (after compiling that function into a library using koka -l):

module permutationstestint

import std/core
import std/os/file
import std/os/path
import permutationsint

pub fun main()
  permutations(list(1,10))
  println("done.")