开发者

Are there any languages in which the ternary operator can be used to modify code structure?

I am curious to know if there are any languages in which the ternary operator can be used to modify code structure at run time. Such as:


boolean bool = true;
// Addition method - can add 2 or 3 integers.
add(5,10 bool ? ) : ,15);

I would assume that if this exists anywhere, both the if 开发者_运维技巧and else statements of the ternary must be acceptable at compile-time.


No, because

  1. such a language would be a syntactical nightmare

  2. the intended effect can easily be produced by using

    result = bool ? add( 5, 10 ) : add( 5, 10, 15 ) # both expressions evaluated?

    result = add( 5, 10, bool ? 0 : 15 ) # maybe nil, empty, or nix instead of 0

    the standard if of the language

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜