<commit_before>package hu

func (interpreter *Interpreter) quote(object Object, environment *Environment) Object {
	return cons(quote_symbol, object)
}

func (interpreter *Interpreter) unquote(object Object, environment *Environment) Object {
	// TODO check that car is quote
	return cdr(object)
}

func (interpreter *Interpreter) evalList(list Object, environment *Environment) Object {
	eval := func(object Object) Object { return interpreter.evaluate(object, environment) }
	return list_from(list, eval)
}

func (interpreter *Interpreter) define(object Object, environment *Environment) Object {
	var variable, value Object

	if is_symbol(car(object)) {
		variable = car(object)
		value = car(cdr(object))
	} else {
		variable = car(car(object))
		parameters := cdr(car(object))
		body := cdr(object)
		value = interpreter.lambda(cons(parameters, body), environment)
	}

	environment.Define(variable, value)
	return nil
}

func (interpreter *Interpreter) set(object Object, environment *Environment) Object {
	variable := car(object)
	value := car(cdr(object))
	value = interpreter.evaluate(value, environment)
	environment.Set(variable, value)
	return nil
}

func (interpreter *Interpreter) lambda(object Object, outer *Environment) Object {
	parameters := car(object)
	function := cdr(object)
	f := func(interpreter *Interpreter, object Object, environment *Environment) Object {
		operands := interpreter.evalList(object, environment)
		environment = outer.Extend(parameters, operands)
		function := interpreter.evalList(function, environment)
		return interpreter.begin(function, environment)
	}
	return &PrimitiveFunctionObject{f}
}<commit_msg>Evaluate value expression before binding it. <commit_after>package hu

func (interpreter *Interpreter) quote(object Object, environment *Environment) Object {
	return cons(quote_symbol, object)
}

func (interpreter *Interpreter) unquote(object Object, environment *Environment) Object {
	// TODO check that car is quote
	return cdr(object)
}

func (interpreter *Interpreter) evalList(list Object, environment *Environment) Object {
	eval := func(object Object) Object { return interpreter.evaluate(object, environment) }
	return list_from(list, eval)
}

func (interpreter *Interpreter) define(object Object, environment *Environment) Object {
	var variable, value Object

	if is_symbol(car(object)) {
		variable = car(object)
		value = interpreter.evaluate(car(cdr(object)), environment)
	} else {
		variable = car(car(object))
		parameters := cdr(car(object))
		body := cdr(object)
		value = interpreter.lambda(cons(parameters, body), environment)
	}

	environment.Define(variable, value)
	return nil
}

func (interpreter *Interpreter) set(object Object, environment *Environment) Object {
	variable := car(object)
	value := car(cdr(object))
	value = interpreter.evaluate(value, environment)
	environment.Set(variable, value)
	return nil
}

func (interpreter *Interpreter) lambda(object Object, outer *Environment) Object {
	parameters := car(object)
	function := cdr(object)
	f := func(interpreter *Interpreter, object Object, environment *Environment) Object {
		operands := interpreter.evalList(object, environment)
		environment = outer.Extend(parameters, operands)
		function := interpreter.evalList(function, environment)
		return interpreter.begin(function, environment)
	}
	return &PrimitiveFunctionObject{f}
}
{'fraction_non_alphanumeric': 0.10946306733906852, 'fraction_numerical': 0.0, 'mean_word_length': 6.205128205128205, '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': '2693623', 'n_tokens_mistral': 988, 'n_tokens_neox': 969, 'n_words': 273}