Exemplo n.º 1
0
        /// <summary>
        /// Classify element to the corresponding group.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="arguments">Instead of class variables.</param>
        /// <returns></returns>
        private AType Classify(AType element, CalculationArguments arguments)
        {
            int index;

            if (arguments.Interval.IsArray)
            {
                AType intervalArray = arguments.Interval;

                for (index = 0; index < intervalArray.Length; index++)
                {
                    if (element.CompareTo(intervalArray[index]) <= 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                index = (element.CompareTo(arguments.Interval) <= 0) ? 0 : arguments.Interval.Length;
            }

            return(AInteger.Create(index));
        }
Exemplo n.º 2
0
        /// <summary>
        /// CASE 3: Slotfiller right argument and simple symbol left argument.
        /// </summary>
        /// <param name="symbol">Symbol to use for selecting from a slotfiller</param>
        /// <param name="items">Slotfiller</param>
        /// <returns></returns>
        private AType SimpleSymbolConstant2SlotFiller(AType symbol, AType items, Aplus environment)
        {
            if (!items.IsSlotFiller(true))
            {
                throw new Error.Domain(DomainErrorText);
            }

            AType result;
            AType keys   = MonadicFunctionInstance.Disclose.Execute(items[0], environment);
            AType values = MonadicFunctionInstance.Disclose.Execute(items[1], environment);

            if (keys.IsArray)
            {
                if (keys.Rank > 1)
                {
                    keys = MonadicFunctionInstance.Ravel.Execute(keys);
                }

                if (values.Rank > 1)
                {
                    values = MonadicFunctionInstance.Ravel.Execute(values);
                }

                int index = -1;

                // TODO: refactor, remove 'i' use the 'index' variable
                for (int i = 0; i < keys.Length; i++)
                {
                    if (keys[i].IsBox)
                    {
                        throw new Error.Domain(DomainErrorText);
                    }

                    if (keys[i].CompareTo(symbol) == 0)
                    {
                        index = i;
                        break;
                    }
                }

                if (index == -1)
                {
                    //y is a symbol and is not a member of the vector of symbol s in x.
                    throw new Error.Index(IndexErrorText);
                }

                if (values[index].IsPrimitiveFunction() || !values[index].IsBox)
                {
                    throw new Error.Domain(DomainErrorText);
                }

                result = MonadicFunctionInstance.Disclose.Execute(values[index], environment);
            }
            else
            {
                // We have only one item in the keys list
                if (symbol.CompareTo(keys) != 0)
                {
                    throw new Error.Index(IndexErrorText);
                }

                if (values.IsPrimitiveFunction() || !values.IsBox)
                {
                    throw new Error.Domain(DomainErrorText);
                }

                result = MonadicFunctionInstance.Disclose.Execute(values, environment);
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// CASE 3: Slotfiller right argument and simple symbol left argument.
        /// </summary>
        /// <param name="symbol">Symbol to use for selecting from a slotfiller</param>
        /// <param name="items">Slotfiller</param>
        /// <returns></returns>
        private AType SimpleSymbolConstant2SlotFiller(AType symbol, AType items, Aplus environment)
        {
            if (!items.IsSlotFiller(true))
            {
                throw new Error.Domain(DomainErrorText);
            }

            AType result;
            AType keys = MonadicFunctionInstance.Disclose.Execute(items[0], environment);
            AType values = MonadicFunctionInstance.Disclose.Execute(items[1], environment);

            if (keys.IsArray)
            {
                if (keys.Rank > 1)
                {
                    keys = MonadicFunctionInstance.Ravel.Execute(keys);
                }

                if (values.Rank > 1)
                {
                    values = MonadicFunctionInstance.Ravel.Execute(values);
                }

                int index = -1;

                // TODO: refactor, remove 'i' use the 'index' variable
                for (int i = 0; i < keys.Length; i++)
                {
                    if (keys[i].IsBox)
                    {
                        throw new Error.Domain(DomainErrorText);
                    }

                    if (keys[i].CompareTo(symbol) == 0)
                    {
                        index = i;
                        break;
                    }
                }

                if (index == -1)
                {
                    //y is a symbol and is not a member of the vector of symbol s in x.
                    throw new Error.Index(IndexErrorText);
                }

                if (values[index].IsPrimitiveFunction() || !values[index].IsBox)
                {
                    throw new Error.Domain(DomainErrorText);
                }

                result = MonadicFunctionInstance.Disclose.Execute(values[index], environment);
            }
            else
            {
                // We have only one item in the keys list
                if (symbol.CompareTo(keys) != 0)
                {
                    throw new Error.Index(IndexErrorText);
                }

                if (values.IsPrimitiveFunction() || !values.IsBox)
                {
                    throw new Error.Domain(DomainErrorText);
                }
    
                result = MonadicFunctionInstance.Disclose.Execute(values, environment);
            }

            return result;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Classify element to the corresponding group.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="arguments">Instead of class variables.</param>
        /// <returns></returns>
        private AType Classify(AType element, CalculationArguments arguments)
        {
            int index;

            if (arguments.Interval.IsArray)
            {
                AType intervalArray = arguments.Interval;

                for (index = 0; index < intervalArray.Length; index++)
                {
                    if (element.CompareTo(intervalArray[index]) <= 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                index = (element.CompareTo(arguments.Interval) <= 0) ? 0 : arguments.Interval.Length;
            }

            return AInteger.Create(index);
        }