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)); }
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])); }
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])); }
private MalType ReadAtom() { string token = _tokens[0]; _tokens.RemoveAt(0); if (MalIntegerRegex.IsMatch(token)) { return(MalLong.Of(Int64.Parse(token))); } return(new MalSymbol(token)); }
private static MalType Plus(MalList <MalType> arg) { return(arg.GetItems().Aggregate(MalLong.Of(0), (current, item) => (MalLong)current + (MalLong)item)); }