<commit_before>use data::{Value, RuntimeError};
use scope::GlobalScope;

pub fn load(env: &mut GlobalScope)
{
    env.set_builtin("quote", false, |args, _| {
        match *args {
            Some(ref cons) => Ok(cons.car.clone()), //FIXME: should fail with extra args
            None => Err(RuntimeError::InvalidArgNum(1)),
        }
    });

    env.set_builtin("+", true, |mut args, _| {
        let mut acc = 0.0;
        while let Some(ref cons) = *args
        {
            match cons.car {
                Value::Number(n) => acc += n,
                ref other => return Err(RuntimeError::InvalidArgType("Number", other.type_name())),
            };
            args = &cons.cdr;
        }
        Ok(Value::Number(acc))
    });
}<commit_msg>implemented builtin "set"<commit_after>use data::{Value, RuntimeError};
use scope::GlobalScope;

pub fn load(env: &mut GlobalScope)
{
    env.set_builtin("quote", false, |args, _| {
        match *args {
            Some(ref cons) => Ok(cons.car.clone()), //FIXME: should fail with extra args
            None => Err(RuntimeError::InvalidArgNum(1)),
        }
    });

    env.set_builtin("set", true, |args, env| {
        match *args {
            Some(ref c1) => match c1.cdr {
                Some (ref c2) => match c1.car {
                    Value::Symbol(ref name) => {
                        env.set(name, c2.car.clone());
                        Ok(c2.car.clone())
                    }
                    ref other => Err(RuntimeError::InvalidArgType("Symbol", other.type_name())),
                },
                None => Err(RuntimeError::InvalidArgNum(2)),
            },
            None => Err(RuntimeError::InvalidArgNum(2)),
        }
    });

    env.set_builtin("+", true, |mut args, _| {
        let mut acc = 0.0;
        while let Some(ref cons) = *args
        {
            match cons.car {
                Value::Number(n) => acc += n,
                ref other => return Err(RuntimeError::InvalidArgType("Number", other.type_name())),
            };
            args = &cons.cdr;
        }
        Ok(Value::Number(acc))
    });
}
{'fraction_non_alphanumeric': 0.1542830099384761, 'fraction_numerical': 0.006625650733554188, 'mean_word_length': 1.74189364461738, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3167528', 'n_tokens_mistral': 638, 'n_tokens_neox': 626, 'n_words': 134}