expression

How does variable assignment in an expression work?

巧了我就是萌 提交于 2019-12-20 02:44:11
问题 This is a practice I've seen before, but not very often: A variable is assigned to a value at the same time the value itself is evaluated (or is it the expression itself that is evaluated?). Example: // Outputs "The value is 1" $value = 1; if ($var = $value) { echo "The value is $var"; } Seems to be the same as: $value = 1; $var = $value; if ($var) { echo "The value is $var"; } Another example: // Outputs "The value is 1" $value = 1; echo "The value is ".$var = $value; I've been using this a

python regex match only last occurrence

守給你的承諾、 提交于 2019-12-20 01:41:08
问题 I'm experiencing some problems implementing a regular expression for a repeating string pattern. >>> re.findall('(\(\w+,\d+\)(?:,)?)+', '(a,b),(c,d),(e,f)') ['(e,f)'] I would like ro get the other items as well Help would be really appriciated 回答1: Remove the + ; your pattern matches all occurrences, but the group can only capture one occurrence, you cannot repeat a capturing group that way: >>> import re >>> re.findall('(\(\w+,\w+\),?)+', '(a,b),(c,d),(e,f)') ['(e,f)'] >>> re.findall('\(\w+,

C++ primary expressions - Is it primary expression or not?

自古美人都是妖i 提交于 2019-12-19 21:53:45
问题 Why are they called "primary"? In the order of evaluence they are the first? C++03 standard defines the expression in chapter 5 (Note 1): An expression is a sequence of operators and operands that specifies a computation. Then the 5.1 "Primary expressions" defines the list of primary expressions: (1) primary-expression: literal this ( expression ) id-expression My main question is in connection the third point: ( expression ) So, according to the standard, every expression with brackets are

Use a rectangle shape as a clip in XAML

痴心易碎 提交于 2019-12-19 19:49:20
问题 Is there a way that I can use a normal Rectangle (shape) as part of a clip for another object in XAML. It seems like I should be able to, but the solution is eluding me.. <Canvas> <Rectangle Name="ClipRect" RadiusY="10" RadiusX="10" Stroke="Black" StrokeThickness="0" Width="32.4" Height="164"/> <!-- This is the part that I cant quite figure out.... --> <Rectangle Width="100" Height="100" Clip={Binding ElementName=ClipRect, Path="??"/> </Canvas> I know that I can use a 'RectangleGeometry' type

How to set more than 2 Expression in Expression.Or

二次信任 提交于 2019-12-19 16:52:24
问题 I want to create a query which has more than 3-4 Expression.Or ? But Expression.Or just let me to add two Expressions inside it. if (!string.IsNullOrEmpty(keyword)) query .Add(Expression.Or( Expression.Like("Name", keyword, MatchMode.Anywhere), Expression.Like("LastName", keyword, MatchMode.Anywhere))) .Add(Expression.Or( Expression.Like("Email1", keyword, MatchMode.Anywhere), Expression.Like("Email2", keyword, MatchMode.Anywhere))); The code above generates "Name like %this% or LastName like

Expression templates: improving performance in evaluating expressions?

☆樱花仙子☆ 提交于 2019-12-19 08:17:08
问题 By the expression templates technique, a matrix expression like D = A*B+sin(C)+3.; is pretty much equivalent, in terms of computing performance, to a hand-written for loop. Now, suppose that I have the following two expressions D = A*B+sin(C)+3.; F = D*E; cout << F << "\n"; In a "classical" implementation by expression templates, the computing performance will be pretty much the same as that of two for loops in sequence. This is because the expressions are evaluated immediately after the =

Why is AngularJS complaining about an unexpected token in an expression when I try to use a string?

半城伤御伤魂 提交于 2019-12-19 06:03:03
问题 I have the folowing attribute on a div: ng-show="state.name === 'index'" . I've also tried ng-show='state.name === "index" , but I keep getting the following error: Syntax Error: Token ' "index" ' is an unexpected token at column 16 of the expression [state.name === "index"] starting at ["index"] . Why? 回答1: ng-show takes an "AngularJS statement." This type of statement only has an == operator, but this operator behaves like === . It's a bit confusing, but handy in that you cannot shoot

How to use CriteriaQuery SUM of custom operation on some cells?

泄露秘密 提交于 2019-12-19 04:04:26
问题 Consider you have table T, with fields A and B. With regular SQL, I could do this: SELECT SUM(A * (100.0 - B) / 100.0) AS D FROM T; And I would get exactly what I expect. However, I'm not sure how to do it with CriteriaQuery. I know how to do sum over 1 field, but not how to do sum over some math expression over multiple fields in a row. 回答1: The CriteriaBuilder interface provides the following arithmetic functions: addition: sum(a, b) substraction: diff(a, b) multiplication: prod(a, b)

The parameter '***' was not bound in the specified LINQ to Entities query expression

拜拜、爱过 提交于 2019-12-19 02:47:24
问题 I am doing a common query in my project. I use Expression to build my query tree, the code list below: public IList<Book> GetBooksFields(string fieldName, string fieldValue) { ParameterExpression paramLeft = Expression.Parameter(typeof(string), "m." + fieldName); ParameterExpression paramRight = Expression.Parameter(typeof(string), "\"" + fieldValue + "\""); ParameterExpression binaryLeft = Expression.Parameter(typeof(Book),"m"); BinaryExpression binaryExpr = Expression.Equal(paramLeft,

How would I express a chained assignment in Scala?

 ̄綄美尐妖づ 提交于 2019-12-19 02:07:24
问题 How would I express the following java code in scala? a = b = c; By the way, I'm re-assigning variables (not declaring). 回答1: The closest shortcut syntax in Scala can only be used when you declare a var or val . scala> val c = 1 c: Int = 1 scala> val a, b = c a: Int = 1 b: Int = 1 From the Scala Reference, Section 4.1 A value declaration val x 1 , ... , x n : T is a shorthand for the sequence of value declarations val x 1 : T ; ...; val x n : T. A value definition val p 1 , ..., p n = e is a