<commit_before>package cat.udl.eps.butterp.data;

import cat.udl.eps.butterp.environment.Environment;

import java.util.Iterator;

public class Lambda extends Function {

    private SExpression params;
    private SExpression body;
    private Environment definitionEnv;

    /**
     * Creates a new lambda function.
     * @param params The list of symbols that represent the parameters of the function.
     * @param body The body of the function that this lambda will evaluate.
     * @param definitionEnv The environment where this lambda was created.
     */
    public Lambda(SExpression params, SExpression body, Environment definitionEnv) {
        assert ListOps.isListOf(params, Symbol.class);  // disabled by default (debug only)
        this.params = params;
        this.body = body;
        this.definitionEnv = definitionEnv;
    }

    @Override
    public SExpression apply(SExpression evargs, Environment callingEnv) {
        Environment localEnvironment = definitionEnv.extend();

        Iterator<SExpression> argsIt = ListOps.createIterator(evargs);
        Iterator<SExpression> paramsIt = ListOps.createIterator(params);
        while (argsIt.hasNext() && paramsIt.hasNext()) {
            localEnvironment.bind((Symbol)paramsIt.next(), argsIt.next());
        }

        return body.eval(localEnvironment);
    }

    @Override
    public String toString() {
        return String.format("<lambda-function-%x | parameters: %s>", hashCode(), params.toString());
    }
}<commit_msg>Added number of arguments check into lambda functions<commit_after>package cat.udl.eps.butterp.data;

import cat.udl.eps.butterp.environment.Environment;

import java.util.Iterator;

public class Lambda extends Function {

    private SExpression params;
    private SExpression body;
    private Environment definitionEnv;

    /**
     * Creates a new lambda function.
     * @param params The list of symbols that represent the parameters of the function.
     * @param body The body of the function that this lambda will evaluate.
     * @param definitionEnv The environment where this lambda was created.
     */
    public Lambda(SExpression params, SExpression body, Environment definitionEnv) {
        assert ListOps.isListOf(params, Symbol.class);  // disabled by default (debug only)
        this.params = params;
        this.body = body;
        this.definitionEnv = definitionEnv;
    }

    @Override
    public SExpression apply(SExpression evargs, Environment callingEnv) {
        Environment localEnvironment = definitionEnv.extend();

        Iterator<SExpression> argsIt = ListOps.createIterator(evargs);
        Iterator<SExpression> paramsIt = ListOps.createIterator(params);
        while (argsIt.hasNext() && paramsIt.hasNext()) {
            localEnvironment.bind((Symbol)paramsIt.next(), argsIt.next());
        }

        if (argsIt.hasNext() || paramsIt.hasNext())
            throw new EvaluationError(String.format("%s: not enought arguments provided", toString()));

        return body.eval(localEnvironment);
    }

    @Override
    public String toString() {
        return String.format("<lambda-function-%x | parameters: %s>", hashCode(), params.toString());
    }
}
{'fraction_non_alphanumeric': 0.09623170351915292, 'fraction_numerical': 0.0, 'mean_word_length': 3.237467018469657, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4734187', 'n_tokens_mistral': 824, 'n_tokens_neox': 807, 'n_words': 244}