Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7505333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:52:40+00:00 2026-05-29T21:52:40+00:00

I am implementing a language interpreter in C# using the DLR, and I’m having

  • 0

I am implementing a language interpreter in C# using the DLR, and I’m having some troubles with the ternary operator. At this point, I have basic function declarations/calls implemented, like so:

F := (x) -> x + 1
F(1)   # returns 2

I’ve not had a problem with a function body being a sequence of expressions — the value of the last expression is always returned, and I’ve made sure all cases in the interpreter return at least something as a side effect. I’m now trying to implement the ternary operator (? :). The Expression tree I’m rendering looks like this:

work = Expression.IfThenElse(                                   
    Expression.IsTrue(Expression.Convert(work, typeof(Boolean))), 
    trueExp, 
    falseExp);

where trueExp and falseExp are both valid expressions.

The problem seems to be that the IfThenElse expression does not return a value, so basically even though trueExp and falseExp are building expression trees, the end result of the IfThenElse expression is always null. Short of making a Runtime function and explicitly calling it, is there a way to implement the ternary operator using the DLR? (ie: an Expression. that does the IfThenElse and returns the actual values in the true and false clauses?)

What I hope to parse is something like:

F := (x) -> (x = 1) ? 4 : 5
F(1)   #4
F(2)   #5

But right now this always returns null when compiled into a program, because of the problem outlined above.

I’d appreciate any help, this is quite vexing!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:52:43+00:00Added an answer on May 29, 2026 at 9:52 pm

    Expression.IfThenElse is an if (...) ... else ...; construct, not the ternary operator.

    The ternary operator is Expression.Condition

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some serious troubles implementing a draw in the scala language. my
What all language components will have to be used for implementing an email service
implementing publishActivity in PHP using the REST API using this code: $activity = array(
I'm implementing an interpreter for a toy language in C#, and in order to
I've looked high and low for examples of implementing a language using the RPython
I really can't find good examples for implementing own scripting language using javax.script ...
I have written a simple brainfuck interpreter in MATLAB script language. It is fed
I'm implementing a linux shell for my weekend assignment and I am having some
Let's say you are implementing an interpreter for a GCed language in a language
I am implementing language files for my PHP application. I am using constants to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.