Exemplo n.º 1
0
        public static List <IRacketObject>?ParseAny(string str)
        {
            string[]             args      = str.Split(" ");
            List <IRacketObject> arguments = new List <IRacketObject>();

            string predicate = "";

            for (int i = 0; i < args.Length; i++)
            {
                string        currentToken    = predicate + args[i];
                IRacketObject?newRacketObject = RacketBoolean.Parse(currentToken)
                                                ?? RacketNumber.Parse(currentToken) ?? RacketString.Parse(currentToken) ?? (IRacketObject?)RacketExpression.Parse(currentToken);

                if (newRacketObject != null)
                {
                    arguments.Add(newRacketObject);
                    predicate = "";
                    continue;
                }
                predicate += $"{args[i]} ";
            }

            if (predicate != "")
            {
                return(null);
            }
            return(arguments);
        }
Exemplo n.º 2
0
        public override RacketNumber Evaluate()
        {
            RacketNumber largestNumber = (RacketNumber)arguments[0].Evaluate();

            for (int i = 1; i < arguments.Count; i++)
            {
                RacketNumber currentNumber = (RacketNumber)arguments[i].Evaluate();
                largestNumber = currentNumber.Value > largestNumber.Value ? currentNumber : largestNumber;
            }
            return(largestNumber);
        }
Exemplo n.º 3
0
        public override RacketBoolean Evaluate()
        {
            bool         retValue    = true;
            RacketNumber firstNumber = (RacketNumber)arguments[0].Evaluate();

            for (int i = 1; i < arguments.Count; i++)
            {
                RacketNumber currentNumber = (RacketNumber)arguments[i].Evaluate();
                retValue = retValue && firstNumber.Value > currentNumber.Value;
            }
            return(new RacketBoolean(retValue));
        }
Exemplo n.º 4
0
        public override RacketInteger Evaluate()
        {
            RacketNumber currentNumber = (RacketNumber)arguments[0].Evaluate();
            long         retValue      = (long)currentNumber.Value;
            bool         isExact       = currentNumber.IsExact;

            for (int i = 1; i < arguments.Count; i++)
            {
                currentNumber = (RacketNumber)arguments[i].Evaluate();
                isExact       = isExact && currentNumber.IsExact;
                retValue     /= (long)currentNumber.Value;
            }
            return(new RacketInteger(retValue, isExact));
        }
Exemplo n.º 5
0
        public override RacketNumber Evaluate()
        {
            RacketNumber currentNumber = (RacketNumber)arguments[0].Evaluate();
            float        retValue      = currentNumber.Value;
            bool         isExact       = currentNumber.IsExact;
            bool         isRational    = currentNumber.IsRational;

            for (int i = 1; i < arguments.Count; i++)
            {
                currentNumber = (RacketNumber)arguments[i].Evaluate();
                isRational    = isRational && currentNumber.IsRational;
                isExact       = isExact && currentNumber.IsExact;
                retValue      = MathF.Pow(retValue, currentNumber.Value);
            }
            return(RacketNumber.Parse(retValue, isExact, isRational));
        }
Exemplo n.º 6
0
        public override RacketNumber Evaluate()
        {
            RacketNumber currentNumber = (RacketNumber)arguments[0].Evaluate();

            return(RacketNumber.Parse(MathF.Atan(currentNumber.Value), false, currentNumber.IsRational));
        }
Exemplo n.º 7
0
        public override RacketInteger Evaluate()
        {
            RacketNumber currentNumber = (RacketNumber)arguments[0].Evaluate();

            return(new RacketInteger((long)MathF.Floor(currentNumber.Value), true));
        }
Exemplo n.º 8
0
        public override RacketBoolean Evaluate()
        {
            RacketNumber currentNumber = (RacketNumber)arguments[0].Evaluate();

            return(new RacketBoolean(currentNumber.Value == 0));
        }
Exemplo n.º 9
0
        public override RacketNumber Evaluate()
        {
            RacketNumber racketNumber = (RacketNumber)arguments[0].Evaluate();

            return(new RacketFloat(racketNumber.Value, false, racketNumber.IsRational));
        }
Exemplo n.º 10
0
        public override RacketNumber Evaluate()
        {
            RacketNumber currentNumber = (RacketNumber)arguments[0].Evaluate();

            return(new RacketInteger((long)MathF.Abs(currentNumber.Value), currentNumber.IsExact));
        }
Exemplo n.º 11
0
        public override RacketNumber Evaluate()
        {
            RacketNumber currentNumber = (RacketNumber)arguments[0].Evaluate();

            return(RacketNumber.Parse(currentNumber.Value - 1, currentNumber.IsExact, currentNumber.IsRational));
        }
Exemplo n.º 12
0
        public override RacketNumber Evaluate()
        {
            RacketNumber currentNumber = (RacketNumber)arguments[0].Evaluate();

            return(RacketNumber.Parse(MathF.Round(currentNumber.Value), currentNumber.IsExact, true));
        }
Exemplo n.º 13
0
        public override RacketString Evaluate()
        {
            RacketNumber racketNumber = (RacketNumber)arguments[0].Evaluate();

            return(new RacketString(racketNumber.Value.ToString()));
        }
        public override RacketFloat Evaluate()
        {
            RacketNumber currentNumber = (RacketNumber)arguments[0].Evaluate();

            return(new RacketFloat(MathF.Pow(MathF.E, currentNumber.Value), false, false));
        }