boolean-expression

Boolean logic in RESTful filtering and queries

本小妞迷上赌 提交于 2019-11-29 04:09:27
This is sort of a follow-up to someone else's question about filtering/querying a list of cars. There the recommendation for a RESTful filtering request was to put filter expressions in the query of the URI, like this: /cars?color=blue&type=sedan&doors=4 That's fine. But what if my filtering query becomes more complicated and I need to use Boolean operators, such as: ((color=blue OR type=sedan) AND doors=4) OR color=red That is, I want to find a four-door blue car or a four-door sedan, but if the car is red I'll take it without caring about any of the other properties. Is there any sort of

boolean variable values in PHP to javascript implementation [duplicate]

£可爱£侵袭症+ 提交于 2019-11-29 01:44:52
问题 This question already has answers here : How do I pass variables and data from PHP to JavaScript? (19 answers) Closed 5 years ago . I've run into an odd issue in a PHP script that I'm writing-- I'm sure there's an easy answer but I'm not seeing it. I'm pulling some vars from a DB using PHP, then passing those values into a Javascript that is getting built dynamically in PHP. Something like this: $myvar = (bool) $db_return->myvar; $js = "<script type=text/javascript> var myvar = " . $myvar . "

if (boolean == false) vs. if (!boolean) [duplicate]

空扰寡人 提交于 2019-11-28 22:51:18
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Is it bad to explicitly compare against boolean constants e.g. if (b == false) in Java? In this NotePadProvider sample code, I noticed that the author chose the form: if (values.containsKey(NoteColumns.CREATED_DATE) == false) { values.put(NoteColumns.CREATED_DATE, now); } Over: if (!values.containsKey(NoteColumns.CREATED_DATE)) { values.put(NoteColumns.CREATED_DATE, now); } Is there any advantage in the first

Cleanest way to convert to boolean [duplicate]

扶醉桌前 提交于 2019-11-28 19:59:57
This question already has an answer here: How can I convert a string to boolean in JavaScript? 74 answers I have a variable. Let's call it toto . This toto can be set to undefined , null , a string, or an object. I would like the cleanest way to check if toto is set to a data, which means set to a string or an object, and neither undefined nor null , and set corresponding boolean value in another variable. I thought to the syntax !! , that would look like this: var tata = !!toto; // tata would be set to true or false, whatever toto is. The first ! would be set to false if toto is undefined or

Why does `if None.__eq__(“a”)` seem to evaluate to True (but not quite)?

為{幸葍}努か 提交于 2019-11-28 14:57:00
问题 If you execute the following statement in Python 3.7, it will (from my testing) print b : if None.__eq__("a"): print("b") However, None.__eq__("a") evaluates to NotImplemented . Naturally, "a".__eq__("a") evaluates to True , and "b".__eq__("a") evaluates to False . I initially discovered this when testing the return value of a function, but didn't return anything in the second case -- so, the function returned None . What's going on here? 回答1: This is a great example of why the __dunder__

Is there a difference between “== False” and “is not” when checking for an empty string?

Deadly 提交于 2019-11-28 14:10:43
I have read elsewhere on stackoverflow that the most elegant way to check for an empty string in Python (e.g. let's say it's a string called response ) is to do: if not response: # do some stuff The reason being that strings can evaluate to boolean objects. So my question is, does the below code say the same thing? if response == False: # do some stuff As already mentioned there is a difference. The not response checks if bool(response) == False or failing that if len(response) == 0 so it is the best choice to check if something is empty, None , 0 or False . See the python documentation on

What does the exclamation mark mean in an Objective-C if statement?

做~自己de王妃 提交于 2019-11-28 12:55:25
I am wondering what the exclamation mark in if(!anObject) means. It is the boolean NOT operator also called negation. !true == false; !false == true; That is the Logical NOT operator, i.e., if( thisThisIsNotTrue ) { doStuff } . It's a C operator, simply meaning "not". So !YES == NO and !NO == YES are both true statements. if (![txtOperator.text isEqualToString: @"+"]) , for example, checks to see if txtOperator.text is NOT equal to @"+". If it always adds, then your string is never "+". The logic as you have it will always add a+b unless the txtOperator.txt is exactly equal to @"+".

Python boolean expression and or

半世苍凉 提交于 2019-11-28 10:49:20
In python if you write something like foo==bar and spam or eggs python appears to return spam if the boolean statement is true and eggs otherwise. Could someone explain this behaviour? Why is the expression not being evaluated like one long boolean? Edit: Specifically, I'm trying to figure out the mechanism why 'spam' or 'eggs' is being returned as the result of the expression. The operators and and or are short-circuiting which means that if the result of the expression can be deduced from evaluating only the first operand, the second is not evaluated. For example if you have the expression a

Javascript && operator as if statement? [duplicate]

徘徊边缘 提交于 2019-11-28 08:27:10
问题 This question already has answers here : Is <boolean expression> && statement() the same as if(<boolean expression>) statement()? (5 answers) Closed 4 years ago . This should be quite a simple question I just couldn't find the answer anywhere so thought I'd save myself some time and ask here. I was looking at some javascript code and noticed an expression of the form: a < b && (other maths statements); The other maths statements are just assigning of variables and simple stuff. My question is

Boolean expression order of evaluation in Java?

有些话、适合烂在心里 提交于 2019-11-28 08:06:43
Suppose I have the following expression String myString = getStringFromSomeExternalSource(); if (myString != null && myString.trim().length() != 0) { ... } Eclipse warns me that myString might be null in the second phrase of the boolean expression. However, I know some that some compilers will exit the boolean expression entirely if the first condition fails. Is this true with Java? Or is the order of evaluation not guaranteed? However, I know some that some compilers will exit the boolean expression entirely if the first condition fails. Is this true with Java? Yes, that is known as Short