Fork me on GitHub
#graalvm
<
2021-10-18
>
Benjamin15:10:49

hi I'm calling random-sample but Random/SplittableRandom class is not allowed. Do you know an alternative? The randomnes is for ui purposes

borkdude15:10:58

@benjamin.schwerdtner The common solution to this is to move your reference in a delay so it won't be initialized at build time

borkdude15:10:45

Showing that it does work in a native image:

$ bb -e '(random-sample 0.5 [1 2 3])'
(2 3)

👀 1
Benjamin15:10:57

what is a delayed reference?

borkdude15:10:52

So instead of doing:

(def foo (random-sample 0.5 [1 2 3]))
you write:
(def foo (delay (random-sample 0.5 [1 2 3])))
And then you write @foo instead of foo when you want to reference the value. But don't dereference it from any other top level values or they must also be delayed.

Benjamin15:10:46

ah sick. Thanks