conditional-expressions

Incomplete FLWOR expression: expecting 'return'

天涯浪子 提交于 2019-12-10 22:16:02
问题 I am having some trouble with the if-then-else command of the XQuery. Currently I am using BaseX to edit XQuery (if that matters!) if ($item/pf3:Current/pf3:Name) then ( let $Name := "None" ) else ( let $Name := data($item/pf3:Current/pf3:Name) ) This piece throws an error saying: [XPST0003] Incomplete FLWOR expression: expecting 'return'. 回答1: There is a small problem with your xquery. Here is the corrected version - let $Name := if ($item/pf3:Current/pf3:Name) then "None" else data($item

What does 'Conditional expressions can be only boolean, not integral.' mean?

不羁的心 提交于 2019-12-10 17:57:57
问题 What does 'Conditional expressions can be only boolean, not integral.' mean? I do not know Java and I know C++ deffenetly not enought to understend what it means.. Please help (found in http://www.javacoffeebreak.com/articles/thinkinginjava/comparingc++andjava.html in Comparing C++ and Java item 7 sub item 1) 回答1: Conditional expressions are used by the conditional and loop control structures to determine the control flow of a program. // conditional control structure if

Unexpected output using Pythons' ternary operator in combination with lambda

这一生的挚爱 提交于 2019-12-08 16:13:50
问题 I have a specific situation in which I would like to do the following (actually it is more involved than this, but I reduced the problem to the essence): >>> (lambda e: 1)(0) if (lambda e: True)(0) else (lambda e: 2)(0) True which is a difficult way of writing: >>> 1 if True else 2 1 but in reality '1','True' and '2' are additional expressions that get evaluated and which require the variable 'e', which I set to '0' for this simplified code example. Note the difference in output from both

Are conditional expressions broken within packages?

余生长醉 提交于 2019-12-06 00:00:35
问题 Consider the following snippet: requires designide, rtl, vcl, {$IF RTLVersion < 19.0} // E2026 Constant expression expected //{$IF CompilerVersion = 22.0} // same as above vcljpg; {$ELSE} vclimg; {$IFEND} It seems to be absolutely syntactically correct. However, the compiler chokes on it and reports Constant expression expected . What really happens here? Technical: currently tested on XE (15.0.3953.35171) only. Of course, workaround suggestions are welcome too. 回答1: I found the same issue in

Numeric Type Promotion with Conditional Expression

删除回忆录丶 提交于 2019-12-01 08:49:44
I was toying around with java, and I noticed something. It can be best shown here: boolean boo = true; Object object1 = boo ? new Integer(1) : new Double(2.0); Object object2; if (boo) object2 = new Integer(1); else object2 = new Double(2.0); System.out.println(object1); System.out.println(object2); I would expect the two to be the same, but this is what gets printed: 1.0 1 Does anyone have a good explanation for this? A ternary must return the same type for both conditions, so your first result ( Integer ) is promoted to a double to match 2.0 . See also, Object object1 = boo ? new Integer(1)

Numeric Type Promotion with Conditional Expression

僤鯓⒐⒋嵵緔 提交于 2019-12-01 06:58:52
问题 I was toying around with java, and I noticed something. It can be best shown here: boolean boo = true; Object object1 = boo ? new Integer(1) : new Double(2.0); Object object2; if (boo) object2 = new Integer(1); else object2 = new Double(2.0); System.out.println(object1); System.out.println(object2); I would expect the two to be the same, but this is what gets printed: 1.0 1 Does anyone have a good explanation for this? 回答1: A ternary must return the same type for both conditions, so your

Why isn't this a syntax error in python?

醉酒当歌 提交于 2019-11-28 09:34:54
Noticed a line in our codebase today which I thought surely would have failed the build with syntax error, but tests were passing so apparently it was actually valid python (in both 2.x and 3). Whitespace is sometimes not required in the conditional expression: >>> 1if True else 0 1 It doesn't work if the LHS is a variable: >>> x = 1 >>> xif True else 0 File "<stdin>", line 1 xif True else 0 ^ SyntaxError: invalid syntax But it does seem to still work with other types of literals: >>> {'hello'}if False else 'potato' 'potato' What's going on here, is it intentionally part of the grammar for

C# if-null-then-null expression

淺唱寂寞╮ 提交于 2019-11-27 06:52:19
Just for curiosity/convenience: C# provides two cool conditional expression features I know of: string trimmed = (input == null) ? null : input.Trim(); and string trimmed = (input ?? "").Trim(); I miss another such expression for a situation I face very often: If the input reference is null, then the output should be null. Otherwise, the output should be the outcome of accessing a method or property of the input object. I have done exactly that in my first example, but (input == null) ? null : input.Trim() is quite verbose and unreadable. Is there another conditional expression for this case,

Why isn't this a syntax error in python?

强颜欢笑 提交于 2019-11-27 03:01:43
问题 Noticed a line in our codebase today which I thought surely would have failed the build with syntax error, but tests were passing so apparently it was actually valid python (in both 2.x and 3). Whitespace is sometimes not required in the conditional expression: >>> 1if True else 0 1 It doesn't work if the LHS is a variable: >>> x = 1 >>> xif True else 0 File "<stdin>", line 1 xif True else 0 ^ SyntaxError: invalid syntax But it does seem to still work with other types of literals: >>> {'hello

C# if-null-then-null expression

天涯浪子 提交于 2019-11-26 12:57:12
问题 Just for curiosity/convenience: C# provides two cool conditional expression features I know of: string trimmed = (input == null) ? null : input.Trim(); and string trimmed = (input ?? \"\").Trim(); I miss another such expression for a situation I face very often: If the input reference is null, then the output should be null. Otherwise, the output should be the outcome of accessing a method or property of the input object. I have done exactly that in my first example, but (input == null) ?