<commit_before>package cas

import "bytes"

type Function struct {
	Name string
	Arguments []Ex
}

func (this *Function) Eval(es *EvalState) Ex {
	if this.Name == "Power" && len(this.Arguments) == 2 {
		t := &Power{
			Base: this.Arguments[0],
			Power: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "Equal" && len(this.Arguments) == 2 {
		t := &Equal{
			Lhs: this.Arguments[0],
			Rhs: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "SameQ" && len(this.Arguments) == 2 {
		t := &Equal{
			Lhs: this.Arguments[0],
			Rhs: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "Plus" {
		t := &Plus{Addends: this.Arguments}
		return t.Eval(es)
	}
	if this.Name == "Times" {
		t := &Times{Multiplicands: this.Arguments}
		return t.Eval(es)
	}
	if this.Name == "Set" && len(this.Arguments) == 2 {
		t := &Set{
			Lhs: this.Arguments[0],
			Rhs: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "SetDelayed" && len(this.Arguments) == 2 {
		t := &SetDelayed{
			Lhs: this.Arguments[0],
			Rhs: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "If" && len(this.Arguments) == 3 {
		t := &If{
			Condition: this.Arguments[0],
			T: this.Arguments[1],
			F: this.Arguments[2],
		}
		return t.Eval(es)
	}
	if this.Name == "While" && len(this.Arguments) == 1 {
		t := &While{
			Test: this.Arguments[0],
			Body: &Symbol{"Null"},
		}
		return t.Eval(es)
	}
	if this.Name == "While" && len(this.Arguments) == 2 {
		t := &While{
			Test: this.Arguments[0],
			Body: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "MatchQ" && len(this.Arguments) == 2 {
		t := &MatchQ{
			Expr: this.Arguments[0],
			Form: this.Arguments[1],
		}
		return t.Eval(es)
	}
	return this
}

func (this *Function) Replace(r *Rule, es *EvalState) Ex {
	if this.IsMatchQ(r.Lhs, es) {
		return r.Rhs
	}
	return this
}

func (this *Function) ToString() string {
	var buffer bytes.Buffer
	buffer.WriteString(this.Name)
	buffer.WriteString("[")
	for i, e := range this.Arguments {
		buffer.WriteString(e.ToString())
		if i != len(this.Arguments)-1 {
			buffer.WriteString(", ")
		}
	}
	buffer.WriteString("]")
	return buffer.String()
}

func (this *Function) IsEqual(otherEx Ex, es *EvalState) string {
	return "EQUAL_UNK"
}

func (this *Function) IsSameQ(otherEx Ex, es *EvalState) bool {<commit_msg>Provide function interface for Replace.<commit_after>package cas

import "bytes"

type Function struct {
	Name string
	Arguments []Ex
}

func (this *Function) Eval(es *EvalState) Ex {
	if this.Name == "Power" && len(this.Arguments) == 2 {
		t := &Power{
			Base: this.Arguments[0],
			Power: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "Equal" && len(this.Arguments) == 2 {
		t := &Equal{
			Lhs: this.Arguments[0],
			Rhs: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "SameQ" && len(this.Arguments) == 2 {
		t := &Equal{
			Lhs: this.Arguments[0],
			Rhs: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "Plus" {
		t := &Plus{Addends: this.Arguments}
		return t.Eval(es)
	}
	if this.Name == "Times" {
		t := &Times{Multiplicands: this.Arguments}
		return t.Eval(es)
	}
	if this.Name == "Set" && len(this.Arguments) == 2 {
		t := &Set{
			Lhs: this.Arguments[0],
			Rhs: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "SetDelayed" && len(this.Arguments) == 2 {
		t := &SetDelayed{
			Lhs: this.Arguments[0],
			Rhs: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "If" && len(this.Arguments) == 3 {
		t := &If{
			Condition: this.Arguments[0],
			T: this.Arguments[1],
			F: this.Arguments[2],
		}
		return t.Eval(es)
	}
	if this.Name == "While" && len(this.Arguments) == 1 {
		t := &While{
			Test: this.Arguments[0],
			Body: &Symbol{"Null"},
		}
		return t.Eval(es)
	}
	if this.Name == "While" && len(this.Arguments) == 2 {
		t := &While{
			Test: this.Arguments[0],
			Body: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "MatchQ" && len(this.Arguments) == 2 {
		t := &MatchQ{
			Expr: this.Arguments[0],
			Form: this.Arguments[1],
		}
		return t.Eval(es)
	}
	if this.Name == "Replace" && len(this.Arguments) == 2 {
		t := &Replace{
			Expr: this.Arguments[0],
			Rules: this.Arguments[1],
		}
		return t.Eval(es)
	}
	return this
}

func (this *Function) Replace(r *Rule, es *EvalState) Ex {
	if this.IsMatchQ(r.Lhs, es) {
		return r.Rhs
	}
	return this
}

func (this *Function) ToString() string {
	var buffer bytes.Buffer
	buffer.WriteString(this.Name)
	buffer.WriteString("[")
	for i, e := range this.Arguments {
		buffer.WriteString(e.ToString())
		if i != len(this.Arguments)-1 {
			buffer.WriteString(", ")
		}
	}
	buffer.WriteString("]")
	return buffer.String()
}

func (this *Function) IsEqual(otherEx Ex, es *EvalState) string {
	return "EQUAL_UNK"
}

func (this *Function) IsSameQ(otherEx Ex, es *EvalState) bool {
{'fraction_non_alphanumeric': 0.1857553366174056, 'fraction_numerical': 0.012110016420361249, 'mean_word_length': 3.3392698130008904, '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': '703251', 'n_tokens_mistral': 2105, 'n_tokens_neox': 1931, 'n_words': 437}