1 package org.simantics.scl.runtime.lazy;
3 import org.simantics.scl.runtime.function.Function;
4 import org.simantics.scl.runtime.function.FunctionImpl1;
5 import org.simantics.scl.runtime.tuple.Tuple0;
8 private static final Function CYCLIC_EVALUATION_TRAP = new FunctionImpl1() {
10 public Object apply(Object p0) {
11 throw new RuntimeException("Cyclic dependency on lazy value.");
15 volatile Function thunk;
16 volatile Object value;
18 public Lazy(Function thunk) {
22 public Object force() {
27 Function curThunk = thunk;
28 if(curThunk != null) {
29 thunk = CYCLIC_EVALUATION_TRAP;
30 value = curThunk.apply(Tuple0.INSTANCE);