package interpreter.scheme;

import interpreter.*;
import interpreter.type.*;

import java.lang.IllegalArgumentException;

public class Base extends Library {
    public class Plus extends Primitive {
        public SchemeObject apply(Interpreter interpreter, SchemePair args) {
            double total = 0.0;
            while(args != null) {
                SchemeObject element = args.head;
                if(element instanceof SchemeNumber) {
                    total += ((SchemeNumber)element).value;
                } else {
                    throw new IllegalArgumentException("argument is not a Number");
                }
                args = SchemePair.of(args.tail);
            }
            return new SchemeNumber(total);
        }
    }

    public class Minus extends Primitive {
        public SchemeObject apply(Interpreter interpreter, SchemePair args) {
            return null;
        }
    }


    public void importLib(Environment env) {
        env.define("+", new Plus());

        // Special forms
        env.define("if", new Syntax(Syntax.Special.IF));
        env.define("lambda", new Syntax(Syntax.Special.LAMBDA));
        env.define("begin", new Syntax(Syntax.Special.BEGIN));
        env.define("define", new Syntax(Syntax.Special.DEFINE));
        env.define("quote", new Syntax(Syntax.Special.QUOTE));
        env.define("set!", new Syntax(Syntax.Special.SET));
    }
}

@@ -890,116 +890,2710 @@
     
-return null;%0A        %7D%0A    %7D%0A%0A%0A    public void importLib(Environment env) %7B%0A        env.define(%22+%22, new Plus
+if(args == null) %7B%0A                throw new IllegalArgumentException(%22not enough arguments%22);%0A            %7D%0A            if(!(args.head instanceof SchemeNumber)) %7B%0A                throw new IllegalArgumentException(%22argument is not a Number%22);%0A            %7D%0A            double total = ((SchemeNumber)args.head).value;%0A            if(args.tail == null) %7B%0A                return new SchemeNumber(-total);%0A            %7D%0A            args = SchemePair.of(args.tail);%0A            while(args != null) %7B%0A                SchemeObject element = args.head;%0A                if(!(element instanceof SchemeNumber)) %7B%0A                    throw new IllegalArgumentException(%22argument is not a Number%22);%0A                %7D%0A                total -= ((SchemeNumber)element).value;%0A                args = SchemePair.of(args.tail);%0A            %7D%0A            return new SchemeNumber(total);%0A        %7D%0A    %7D%0A%0A    public class Times extends Primitive %7B%0A        public SchemeObject apply(Interpreter interpreter, SchemePair args) %7B%0A            double total = 1.0;%0A            while(args != null) %7B%0A                SchemeObject element = args.head;%0A                if(element instanceof SchemeNumber) %7B%0A                    total *= ((SchemeNumber)element).value;%0A                %7D else %7B%0A                    throw new IllegalArgumentException(%22argument is not a Number%22);%0A                %7D%0A                args = SchemePair.of(args.tail);%0A            %7D%0A            return new SchemeNumber(total);%0A        %7D%0A    %7D%0A%0A    public class Divide extends Primitive %7B%0A        public SchemeObject apply(Interpreter interpreter, SchemePair args) %7B%0A            if(args == null) %7B%0A                throw new IllegalArgumentException(%22not enough arguments%22);%0A            %7D%0A            if(!(args.head instanceof SchemeNumber)) %7B%0A                throw new IllegalArgumentException(%22argument is not a Number%22);%0A            %7D%0A            double total = ((SchemeNumber)args.head).value;%0A            if(args.tail == null) %7B%0A                return new SchemeNumber(1 / total);%0A            %7D%0A            args = SchemePair.of(args.tail);%0A            while(args != null) %7B%0A                SchemeObject element = args.head;%0A                if(!(element instanceof SchemeNumber)) %7B%0A                    throw new IllegalArgumentException(%22argument is not a Number%22);%0A                %7D%0A                total /= ((SchemeNumber)element).value;%0A                args = SchemePair.of(args.tail);%0A            %7D%0A            return new SchemeNumber(total);%0A        %7D%0A    %7D%0A%0A%0A    public void importLib(Environment env) %7B%0A        env.define(%22+%22, new Plus());%0A        env.define(%22-%22, new Minus());%0A        env.define(%22*%22, new Times());%0A        env.define(%22/%22, new Divide
 ());

Add - * / to scheme base