Esempio n. 1
0
        private static MalType Times(MalList <MalType> arg)
        {
            var  items  = arg.GetItems().Select(x => (long)(MalLong)x);
            long result = items.Aggregate <long, long>(1, (current, item) => current * item);

            return(MalLong.Of(result));
        }
Esempio n. 2
0
        private static MalType Minus(MalList <MalType> arg)
        {
            var items = arg.GetItems().Select(x => (long)(MalLong)x).ToList();

            if (items.Count() != 2)
            {
                throw new WrongNumberOfArgumentsException("wrong number of arguments for minus", null);
            }
            return(MalLong.Of(items[0] - items[1]));
        }
Esempio n. 3
0
        private static MalType IntegerDivide(MalList <MalType> arg)
        {
            var items = arg.GetItems().Select(x => (long)(MalLong)x).ToImmutableList();

            if (items.Count() != 2)
            {
                throw new WrongNumberOfArgumentsException("wrong number of arguments for divide", null);
            }
            return(MalLong.Of(items[0] / items[1]));
        }
Esempio n. 4
0
        private MalType ReadAtom()
        {
            string token = _tokens[0];

            _tokens.RemoveAt(0);
            if (MalIntegerRegex.IsMatch(token))
            {
                return(MalLong.Of(Int64.Parse(token)));
            }
            return(new MalSymbol(token));
        }
Esempio n. 5
0
 private static MalType Plus(MalList <MalType> arg)
 {
     return(arg.GetItems().Aggregate(MalLong.Of(0), (current, item) => (MalLong)current + (MalLong)item));
 }