Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ternary operation support? #100

Open
cdarrigo opened this issue Aug 19, 2022 · 3 comments
Open

ternary operation support? #100

cdarrigo opened this issue Aug 19, 2022 · 3 comments

Comments

@cdarrigo
Copy link

The conditional operator ?:, also known as the ternary conditional operator, evaluates a Boolean expression and returns the result of one of the two expressions, depending on whether the Boolean expression evaluates to true or false.

Is this type of operation supported in Flee?

@shawndewet
Copy link

Have you actually tried such an operation and see what you get?

@shawndewet
Copy link

Seems it's not supported:

 [Fact]
        public void Expression_Ternary_Operator()
        {
            ExpressionContext expressionContext = new();
            expressionContext.Imports.AddType(typeof(Math));

            expressionContext.Variables["operation"] = true; //or subtract

            IGenericExpression<int> eGeneric = expressionContext.CompileGeneric<int>("operation ? 1+3 : 1-3");
            var actual = eGeneric.Evaluate();

            actual.ShouldBe(4);
        }

The above fails with the following error: Flee.Parsing.ParserLogException : unexpected character '?', on line: 1 column: 11

@viklele
Copy link

viklele commented Jul 6, 2023

When I needed a ternary function, I wrote a simple custom method named IIf (boolExpression, trueValue, falseValue) that returned trueValue when boolExpression evaluated to true, and falseValue when it evaluated to false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants