<commit_before>package vm

import (
	"sync"
	"sync/atomic"
)

type thunkState uint32

const (
	illegal thunkState = iota
	normal
	locked
	app
)

type Thunk struct {
	Result    Object
	function  *Thunk
	args      []*Thunk
	state     thunkState
	blackHole sync.WaitGroup
}

func Normal(o Object) *Thunk {
	return &Thunk{Result: o, state: normal}
}

func App(f *Thunk, args ...*Thunk) *Thunk {
	t := &Thunk{function: f, args: args, state: app}
	t.blackHole.Add(1)
	return t
}

func (t *Thunk) Eval() Object { // into WHNF
	if t.compareAndSwapState(app, locked) {
		o := t.function.Eval()
		f, ok := o.(Callable)

		if ok {
			t.Result = f.Call(t.args...).Eval()
		} else {
			t.Result = NotCallableError(o).Eval()
		}

		t.function = nil
		t.args = nil

		t.storeState(normal)

		t.blackHole.Done()
	} else {
		t.blackHole.Wait()<commit_msg>Wrap func(...*Thunk) *Thunk with Function to make it Callable<commit_after>package vm

import (
	"sync"
	"sync/atomic"
)

type thunkState uint32

const (
	illegal thunkState = iota
	normal
	locked
	app
)

type Thunk struct {
	Result    Object
	function  *Thunk
	args      []*Thunk
	state     thunkState
	blackHole sync.WaitGroup
}

func Normal(o Object) *Thunk {
	if f, ok := o.(func(...*Thunk) *Thunk); ok {
		o = Function(f)
	}

	return &Thunk{Result: o, state: normal}
}

func App(f *Thunk, args ...*Thunk) *Thunk {
	t := &Thunk{function: f, args: args, state: app}
	t.blackHole.Add(1)
	return t
}

func (t *Thunk) Eval() Object { // into WHNF
	if t.compareAndSwapState(app, locked) {
		o := t.function.Eval()
		f, ok := o.(Callable)

		if ok {
			t.Result = f.Call(t.args...).Eval()
		} else {
			t.Result = NotCallableError(o).Eval()
		}

		t.function = nil
		t.args = nil

		t.storeState(normal)

		t.blackHole.Done()
	} else {
		t.blackHole.Wait()
{'fraction_non_alphanumeric': 0.14955357142857142, 'fraction_numerical': 0.0033482142857142855, 'mean_word_length': 3.0474040632054176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1027880', 'n_tokens_mistral': 771, 'n_tokens_neox': 730, 'n_words': 181}