<commit_before>package com.jedrzejewski.slisp.interpreter.specialforms;

import com.jedrzejewski.slisp.TestUtils;
import com.jedrzejewski.slisp.interpreter.Interpreter;
import com.jedrzejewski.slisp.parser.lispobjects.Num;
import org.junit.Assert;
import org.junit.Test;

public class FnFormTest {

    @Test
    public void testBindAndCall() throws Exception {
        Interpreter interpreter = new Interpreter();
        TestUtils.evalString("(set! inc (fn [n] (+ n 1)))", interpreter);
        Assert.assertEquals(
                new Num(2),
                TestUtils.evalString("(inc 1)", interpreter)
        );
    }

    // TODO: add lexical binding test
}<commit_msg>Test calling just defined function<commit_after>package com.jedrzejewski.slisp.interpreter.specialforms;

import com.jedrzejewski.slisp.TestUtils;
import com.jedrzejewski.slisp.interpreter.Interpreter;
import com.jedrzejewski.slisp.parser.lispobjects.Num;
import org.junit.Assert;
import org.junit.Test;

public class FnFormTest {

    @Test
    public void testBindThenCall() throws Exception {
        Interpreter interpreter = new Interpreter();
        TestUtils.evalString("(set! inc (fn [n] (+ n 1)))", interpreter);
        Assert.assertEquals(
                new Num(2),
                TestUtils.evalString("(inc 1)", interpreter)
        );
    }

    @Test
    public void testDefineAndCall() throws Exception {
        Assert.assertEquals(
                new Num(6),
                TestUtils.evalString("((fn [a b] (* a b)) 3 2)")
        );
    }

    // TODO: add lexical binding test
}
{'fraction_non_alphanumeric': 0.11146295123495883, 'fraction_numerical': 0.005699810006333122, 'mean_word_length': 2.8916256157635467, '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': '4444440', 'n_tokens_mistral': 494, 'n_tokens_neox': 492, 'n_words': 106}