예제 #1
0
        private IodineObject sum(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length < 1)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(null);
            }

            IodineObject initial    = args.Length > 1 ? args [1] : new IodineInteger(0);
            IodineObject collection = args [0];

            collection.IterReset(vm);
            while (collection.IterMoveNext(vm))
            {
                IodineObject o = collection.IterGetCurrent(vm);
                initial = initial.Add(vm, o);
            }
            return(initial);
        }
예제 #2
0
        IodineObject Sum(VirtualMachine vm, IodineObject self, IodineObject [] args)
        {
            if (args.Length < 1)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(IodineNull.Instance);
            }

            IodineObject initial    = args.Length > 1 ? args [1] : new IodineInteger(0);
            var          collection = args [0].GetIterator(vm);

            collection.IterReset(vm);
            while (collection.IterMoveNext(vm))
            {
                var o = collection.IterGetCurrent(vm);
                initial = initial.Add(vm, o);
            }
            return(initial);
        }