FAQ Database Discussion Community


Why conditional operator not work in java switch case? [duplicate]

java,operators
This question already has an answer here: use relational operators in switch 6 answers I do the following code int cnt=1; switch(cnt){ case (cnt<=10): System.out.println("Less than 10"); break; case (cnt<=20): System.out.println("Less than 20"); break; case (cnt<=30): System.out.println("Less than 30"); break; } There are some questions available about this problem....

Operator delete associativity

c++,delete,operators
Whilst looking up operator associativity on wikipedia, I noticed that delete has an associativity of right to left. The source is cited as msdn, I checked it and it comes under group 3 precedence, right to left associativity. So I checked the C++ standard (n4296) 5.3 Unary expressions [expr.unary] 1)...

Difference between prefix and postfix ++ operators in Java [closed]

java,jvm,operators,bytecode
There are a few questions regarding this (like Java: Prefix/postfix of increment/decrement operators?) but I'm not asking about the general difference between postfix and prefix ++ operators (I know that part), but about the fundamental difference between them at the Java specification level. Specifically, is there any difference between prefix...

Xpath | operator inside the path

xpath,operators
I have an xpath as follows: .//*[text()='Name:']/../child::select | .//*[text()='Name:']/../child::span However for me it's not very compact nor elegant, I'd prefer something along the lines of: .//*[text()='Name:']/../child::(select|span) But the above solution does not work. The idea is that the text (e.g. 'Name:' is passed as an argument to a function, and...

Is it possible to use an arbitrary character as an operator?

c++,operators
As a prior note: This is not something I would 'desire' to achieve; more-so a question related to if it's actually possible. N.B. I understand (and have used) Operator Overloding in C++. For example: std::ostream& operator<<(std::ostream& os, const T& obj){ return os; } Is it possible to define a custom...

How to check for matching key value pairs

php,arrays,operators
I have sets of arrays with key value pairs: $array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); $array2 = array('green' => 5, 'blue' => 1, 'yellow' => 7, 'cyan' => 8); How do I check that both arrays contain a match key and value...

Operand order in Scala List.prepend (::)

list,scala,operators
Odersky has brilliantly optimized Java syntax, enabling object calls without dots and parenthesis. I.e. instead of list.prepend(item), you now simply write list :: item, which also turns language operators into simple object methods. Here, List defines :: (prepend) operator. However, you normally write it vice-verse in Scala, using item ::...

Python operators with other meanings (like the print chevron)

python,python-2.7,python-3.x,operators
There are a number of questions on SO about Python's print chevron, which uses the same token as one of the bit-shift operators to send print's output somewhere other than stdout: print >> sys.stderr, "foo" From one of the answers: The >> token is not actually an operator here; it's...

Haskell priority of operator

haskell,operators,priority,infix-notation
I have some questions about priority of operators with Haskell. Is infixl the correct way to set an infix operator priority ? Is it possible to modify the priority in its own programs ? What is the difference between infixl and infixr ? ...

Using backticks and operators in apply family functions

r,data.frame,operators,apply
I saw in a recent answer an apply family function with assignments built-in and can't generalize it. lst <- list(a=1, b=2:3) lst $a [1] 1 $b [1] 2 3 This can't yet be made into a data.frame because of the unequal lengths. But by coercing the max length to the...

Java value plus variable++

java,operators,increment
Consider the following code int val1 = 3; val1++; int val2 = val1++; System.out.println(val1); System.out.println(val2); Val1 value = 5; Val2 value = 4; Why is the value of Val1 "5"? As I understand it it should be 4, because: at line1 it is assigned value of 3, on line2 1...

Using the !== Operator to compare strings taken froma Dropdown list - Javascript

javascript,comparison,operators
I'm trying to get q1check to read a value from the dropdown form item 'qq1'.' It's reading it in fine. There seems to be an issue with the way I'm using the comparison operators. Could anyone help me? function q1ans_check(){ var q1check = document.getElementById("qq1").value; alert(q1check); if(q1check !== "1" || qlcheck...

Logical operators and their behavior in JavaScript

javascript,jquery,logic,operators,logical-operators
Why does this fail? The way I read this code is "if either a or b or c equals three, then the statement is true". But apparently JavaScript disagrees. Why? function test() { var a = 'one'; var b = 'two'; var c = 'three'; return ( ( a ||...

Ruby `**` method [closed]

ruby,operators
I was playing/learning with ruby and did something as in below mentioned code snippet and got: 1 ** 5 # => 1 43 ** 67 # => 27694053307656599023809257877241042019569010395053468294153499816223586030238186389799480520831161107426185107 What is ** operator in ruby? Why did i get too large number in result of second query?...

c# security: memory allocation inside logical operators

c#,security,memory,operators,logical
My goal is to make my software a bit more secure against crackers. First of all I have two easy code samples: 1°: var base64EncodedBytes = System.Convert.FromBase64String("a base 64 string here"); if (System.Text.Encoding.UTF8.GetString(base64EncodedBytes) == "something") { //do; } 2°: if (System.Text.Encoding.UTF8.GetString((System.Convert.FromBase64String("a base 64 string here"))) == "something") { //do; }...

Incrementation not showing in MessageBox and variable values being changed

c#,operators,increment
I have two questions about this code... Why is that at line 10 it starts keeping the current value. For example, int a = 7 (a += 4) Which is 11 is brought over to the next line of code (a -= 4) now making it 7. Instead of just...

How do I create a class with template that does operations on two numbers

java,templates,generics,types,operators
I would like to create a generic class called "BasicInterval" that contains two private objects start_ and stop_ that would be restricted to Number and Comparable: My goal is to add public functions that would return start > stop ?, start_ - stop_, ... public class BasicInterval<T extends Number2> {...

What's wrong with order for not() in python?

python,operators,boolean-expression
What's wrong with using not() in python?. I tried this In [1]: not(1) + 1 Out[1]: False And it worked fine. But after readjusting it, In [2]: 1 + not(1) Out[2]: SyntaxError: invalid syntax It gives an error. How does the order matters?...

Python: Why is binary AND operator allowed between sets, but not lists?

python,set,operators
Why can I do set('dog') & set('hotdog') to find the similar letters, but cannot do the same with a list? i.e ['dog'] & ['hotdog'] What is the reasoning for this from a computer science perspective?...

PHP Define var = one or other (aka: $var=($a||$b);)

php,variables,operators
Is there a way to define a php variable to be one or the other just like you would do var x = (y||z) in javascript? Get the size of the screen, current web page and browser window. var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var height = window.innerHeight...

Do relational operators like less than, greater than, gte, lte use type conversion in PHP?

php,operators,relational,comparison-operators
Do relational operators like less than, greater than, gte, lte use type conversion? If they do, why are there no strict comparison relational operators like !== or === ?

What does ,= mean in python?

python,operators
I wonder what ,= or , = means in python? Example from matplotlib: plot1, = ax01.plot(t,yp1,'b-') ...

PHP and logical operators?

php,operators,logical
I am currently writing my own permission class for my forum and i've run into a small problem that I really can understand. I have the following function: function editTopic($perm_edit_topic, $id, $user_id, $my_id, $permission){ if($perm_edit_topic == true && $user_id == $my_id OR $permission == 0 XOR $permission == 1){ echo...

Overloading bitwise operators in Java

java,operators
I learnt that Java does not give provision to programmer to overload an operator. I also learnt that + is the only operator overloaded in java, But, Operators & | ^ work on integral operands as bitwise operators. Operators & | ^ work on boolean operands as logical operators. My...

Please explain the default constructor (int = 10)

arrays,class,constructor,operators,overloading
class Array { public: Array(int = 10); // default constructor ~Array(); // destructor protected: int size; // number of elements in the Array int *ptr; // address of dynamically allocated memory }; Could someone explain what the default constructor (int = 10) is about, with an example? Also, how do...

What does -f mean in bash

bash,operators
I was looking at how to use runit to run gunicorn. I was looking at the bash file and I don't know what -f $PID does in #!/bin/sh GUNICORN=/usr/local/bin/gunicorn ROOT=/path/to/project PID=/var/run/gunicorn.pid APP=main:application if [ -f $PID ]; then rm $PID; fi cd $ROOT exec $GUNICORN -c $ROOT/gunicorn.conf.py --pid=$PID $APP Google...

Will Specific Operators give me different results?

c++,floating-point,int,operators
I'm working in my Sam's teach yourself work book, in lesson 5 the workshop asks to show the results of 32/7 and 32.0/7. Will the use of different operators such as float or int give me different results. I attempted in my code, but it resulted in an error. Could...

Javascript Logical OR and Objects

javascript,object,operators,logical
Can someone explain everything that's happening in a statement like this: POJO.someProperty = POJO.someProperty || {} Is this checking for undefined then simply assigning an empty object if undefined = true? ...

Example of expression where the precedence of AND (&&) over OR (||) matters?

javascript,operators,operator-precedence
In all of the JavaScript operator precedence charts I can find (like this one and this one), the logical AND (&&) has slightly higher precedence to the logical OR (||). I can't seem to figure out an expression where the result is different than it would be if they had...

Why these expressions are giving me output instead of compile error? [duplicate]

java,operators
This question already has an answer here: Java += operator 10 answers I was giving a exam when i got this question What is the Output of following question public class ClassicQuestion { public static void main(String[] args) { int i = 25; double j = 95.0; System.out.println(j+=i); System.out.println(i+=j);...

Get operator operands

list,prolog,operators
I have list: List = [a=3, b=2, c=0]. For example, first element a=3, how can I get value Left = a, Right = 3. Left side is atom and right side is number....

How does Dart's operator overloading translate to javascript?

javascript,dart,operator-overloading,operators,overloading
Very happy to see Dart support operator overloading (very cool :) ), but I am curious as to how this implementation translates to Javascript before I dive into developing something around this? Know this isn't something Javascript supports natively so wondered if there would be any complications around conversion to...

Different slicing behaviors on left/right hand side of assignment operator

python,python-3.x,operators,slice,deep-copy
As a Python newbie coming from the C++ background, the slicing operator in Python (3.4.x) looks ridiculous to me. I just don't get the design philosophy behind the "special rule". Let me explain why I say it's "special". On the one hand, according to the Stack Overflow answer here, the...

Arguments for Subset within a function in R colon v. greater or equal to

r,operators,subset
Suppose I have the following data. x<- c(1,2, 3,4,5,1,3,8,2) y<- c(4,2, 5,6,7,6,7,8,9) data<-cbind(x,y) x y 1 1 4 2 2 2 3 3 5 4 4 6 5 5 7 6 1 6 7 3 7 8 8 8 9 2 9 Now, if I subset this data to select...

How do I do exponentiation in python?

python,math,operators
def cube(number): return number^3 print cube(2) I would would expect cube(2) = 8, but instead I'm getting cube(2) = 1 What am I doing wrong?...

Showing two .substring in the same alert()

javascript,string,operators
I have an assessment for Java script basics that I have not been able to study for due to unforeseen circumstances so I am now having to catch up in the little time I have. My assessment states that I must find the substring of the start of each string,...

Understanding operators in C [duplicate]

c,operators
This question already has an answer here: OR and AND operation in C 2 answers I am struck on a basic problem with operators. Here is the problem int i=3, j=2, k=1, m; m = ++i || ++j && ++k; printf("%d %d %d %d", i, j, k, m); As...

Regex for splitting a string to get operators

java,arrays,regex,split,operators
I have a String = A+B+CC-D0. I want to use a regular expression to split it apart to get an array of of the ops {+,+,-} I have tried the regular expression: "[^+-]" But the output gave me a array of { ,+,+, ,+}, why? String s1 = "A+B+C-D"; String...

C++ overload << operator for class object acting as stream

c++,sockets,tcp,operators
So I've browsed a bunch of other threads, but none pertain to the questions I have on this exact topic. I am writing a C++ library to do socket communication. I have a TCP socket class which handles all operations on a TCP socket (setup, read/write, etc). I want to...

Why was the double colon operator chosen for Java 8? [duplicate]

java,syntax,operators,java-8
This question already has an answer here: Why did Java 8 introduce a new “::” operator for method references? 3 answers Prior to Java 8, my observation was that the de facto standard for referring to member methods was by using the # symbol (such as Object#toString()). Then along...

IS vs. AS vs. IsAssignableFrom - What are the differences when checking for objectTypes and Interfaces?

c#,performance,object,interface,operators
I'm sort of new to C# and i was wondering if you could help me out. The scenario: public bool ObjectImplementsSpecificInterface (object obj) { // 1. if (obj is IExampleInterface) { return true; } // 2. var tmp = obj as IExampleInterface; if (tmp != null) { return true; }...

Chain Increment Operators

c#,operators
Why can you not chain operators? int test = 5; test++++; OR int test = 5; ++test++; This code gives a compile time error. The operand of an increment or decrement operator must be a variable, property or indexer. I fully understand this, if allowed, would be a complete code...

What use does the new as! operator have?

swift,operators,downcasting
I don't quite understand what new functionality the as! operator is supposed to add. Apple's documentation says: The as! operator performs a forced cast of the expression to the specified type. The as! operator returns a value of the specified type, not an optional type. If the cast fails, a...

What does comma operator in C do when we return an integer with two values? [duplicate]

c,operators,comma-operator
This question already has an answer here: What does the comma operator `,` do in C? 8 answers I was actually returning a float value when I typed , instead of . but it did not give me any error. Then I tried running the below code. #include<stdio.h> #include<conio.h>...

using if statement to compare a combo box value with two text boxes value

c#,winforms,if-statement,combobox,operators
I'm using C# winforms I have a form with combobox called cmbExport and two textboxes txtDateSend and txtSendNum The combobox get its data from a stored procedure GET_ALL_EXPORT_WITHNULL cmbExport.DataSource = cmp.GET_ALL_EXPORT_WITHNULL(); cmbExport.DisplayMember = "side"; cmbExport.ValueMember = "ID_EXPORT"; cmbExport.SelectedValue = "6"; When the user NOT choose certain values from the combobox...

Shorthand expression for an if ( $a == $b || $a == $c ) statement

php,regex,if-statement,operators,expression
I know this code will work: echo ( $a == $b || $a == $c ) ? "Yes" : "No"; That can be read like: if $a is equal to $b or $a is equal to $c Is there a way to make it more shorter like: if $a is...

Understanding ~ Operator

operators,bit-manipulation
I am learning Bitwise Operators and for that I pulled out an article on tutsplus. Well, it is written quite nicely. I could understand the & and | operator but the ~ is messing things up. For example, as stated there in the article: In fact, just as ! flips...

JavaScript operator ++

javascript,operators
i'm having this js code and i can't understand why does the last number is 12 and why it starts counting from 8. Why doen't it strat from 10 and end at 14? <html> <body> <script type="text/javascript"> var k; for (k=010; k<015; k++) { document.write(" "+k); document.write("<br>"); } </script> </body>...

How is it possible to evaluate +5 in Python?

python,operators,addition
How does evaluating + 5 work (spoiler alert: result is 5)? Isn't the + working by calling the __add__ method on something? 5 would be "other" in: >>> other = 5 >>> x = 1 >>> x.__add__(other) 6 So what is the "void" that allows adding 5? void.__add__(5) Another clue...

What is the “>>” and “>>>” operator in java? [duplicate]

java,operators
This question already has an answer here: Double Greater Than Sign (>>) in Java? 7 answers Hi I was wondering if anyone could help me with something I can find literally nothing online about. I was looking through some code that had the following statement: int mainInt = 10>>>...

C++: About null characters

c++,operators,stdstring,double-quotes,null-character
There are two string variables, m and n: #include <string> string m = "0100700\0" cout << m.size() << endl; // it prints: 7 string n; n += "0100700" n += '\0'; cout << n.size() << endl; // it prints: 8 I supposed that both had 8 characters, but m had...

Non-scalar in Uniform output error in arrayfun. How to fix?

arrays,matlab,operators,output
I'm not sure what it means in this context. I tried adding " 'uniformoutput',false " to the end of arrayfun, but then it got upset with the "+" operator saying "Undefined operator '+' for input arguments of type 'cell'." I changed it to ".+" but got a parse error :(...

bad operand types for binary operator compiling error

java,arrays,multidimensional-array,compiler-errors,operators
for a game i'm making I need to place a tetris-like piece on a 10x10 game board. I want to return "offboard" if the player tries to put the piece on a cell that is outside the board For this, I've made an initial method that returns true if the...

“?:” operator is scala [duplicate]

java,scala,operators
This question already has an answer here: Ternary Operator Similar To ?: 3 answers In Java, I can write: Double x = (x1 > x2)? x1:x2 But this doesn't seem to work in Scala, the following has an error: var x = (x1 > x2)? x1:x2 I don't feel...

Java Increment / Decrement Operators - How they behave, what's the functionality?

java,oop,operators
It's been 3 days since I start to learn Java. I have this program and I don't understand code in main method with ++ and -- operators. I don't even know what to call them(name of these operators) Can anyone explain me what's all about. class Example { public static...

Execution order in Prolog: ; operator

prolog,operators
I am currently delving into Prolog but coming from a JavaScript background a lot seems strange. For instance, I have a definition such as this: np # Subject, pp # IObject ; np # IObject, However, in executing the result is not as expected. But when using parantheses it is....

JSCS: Operator should stick to following expression

javascript,operators,jscs
I keep receiving the following error, and I am unable to find documentation on what it means. I know it involves strict javascript formatting, and I was wanting to resolve it by abiding by the formating. JSCS: Operator / should stick to following expression. //Slow Scroll if ( window.addEventListener )...

Macro Operator List

c++,macros,operators,preprocessor,standard-library
I know about Macro's Stringizing operator (#) and I recently learned about the (##) Concatenation operator: Preprocessor Stringizing Operator with String Literal Prefixes Are there any other macro operators that are available to me? I know that Boost has a pretty extensive suite that they've put together, however for the...

Need some help - left shift bitwise operator

c++,bit-manipulation,operators
I am trying to clearly understand the behaviour of the shift operators (especially for the boundary cases), so I devised a little test written in C++. int a = odd_value; //321 in my case but it should not matter (the last bit to be 1) print(0, a); a = a...

Operations with some user-defined operators in my Matrix4 class are returning high values very high values

c++,matrix,operators
i am writing a Matrix4 class for an OpenGL game: static class Matrix4 { private: float matrix[16]; Matrix4 Identity() { matrix[1] = matrix[2] = matrix[3] = matrix[4] = matrix[6] = matrix[7] = matrix[8] = matrix[9] = matrix[11] = matrix[12] = matrix[13] = matrix[14] = 0.f; matrix[0] = matrix[5] = matrix[10]...

PostScript == operator

operators,postscript
The value of == is not an operator, but rather a built-in procedure. PLRM page 526 (pdf page 540). a built-in procedure, does this mean that this is a PostScript procedure: { something here } or an actual function e.g. in Java that you have to define yourself?...

What does '<<' do in a C# integer declaration? [duplicate]

c#,variables,int,operators
This question already has an answer here: C# Left Shift Operator 4 answers In C#, what does the << operator do when used to declare a variable? int layer = 1 << 8; I've tried looking up the operator, but only confirmed what I already understood. I'm not to...

Errors 2676 and 2784 (…could not deduce template argument for…) when inserting vector of structs into set

c++,vector,struct,operators
I am getting the following build errors when I try to run my program (in VS): Error 10 error C2676: binary '<' : 'const move' does not define this operator or a conversion to a type acceptable to the predefined operator Error 4 error C2784: 'bool std::operator <(const _Elem *,const...

implement __rmul__ from both sides, python

python,class,operators
I there a way to implement rmul so that it works in both directions? I'm using mul to multiply two vectors a and b of class R3 element by element. Later I want to be able to multiply each element by a number with an operator like 2*a and a*2....

vector/array bounds check only when a define is declared

c++,class,operator-overloading,operators,element
I've create my own container that is inherited from a vector. I would like to reimplement operator[] in a way that makes checking for bounds decided by a #define. So putting an example, and ignoring template parmameters as they're complicated and irrelevant class MyArray : vector<double> { //... virtual double&...

What is -> operator in Java/JavaFX?

java,javafx,operators
Looking into an open source project in JavaFX I found this lines: @FXML private TreeTableColumn<Person, String> firstNameColumn; @FXML private TreeTableColumn<Person, String> lastNameColumn; @FXML private void initialize() { // Initialize the person table with the two columns. firstNameColumn.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty()); lastNameColumn.setCellValueFactory(cellData -> cellData.getValue().lastNameProperty()); } I never saw the "->" operator before....

subsetting with not operator `!`

r,operators,subsetting
I just ran into an interesting nuance with the not ! operator in subsetting while answering this question link. Check out: y <- 1:10 y[!y] integer(0) y[4] <- NA y[!y] [1] NA y[6] <- 0 y[!y] [1] NA 0 From R documentation: ! indicates logical negation (NOT) How is 0...

Why the variation in operators?

scala,operators
Long time lurker, first time poster. In Scala, I'm looking for advantages as to why it was preferred to vary operators depending on type. For example, why was this: Vector(1, 2, 3) :+ 4 determined to be an advantage over: Vector(1, 2, 3) + 4 Or: 4 +: Vector(1,2,3) over:...

How do you test the identity of Strings in Swift?

swift,operators,identity-operator
Swift, like a few other languages, has an identity operator ===. But it seems like you can't use it against strings: var x = "hello" var y = "hello" if x === y { //ERROR: 'String' does not conform to protocol 'AnyObject' println("SAME!") }else { println("DIFFERENT!") } Is there no...

Provide a proper operator<< with variadic template specialization

c++,templates,operators,friend
When providing the operator<< for a specialization of a template class, clang likes the inline friend form: #include <iostream> template <typename A, typename... Bs> struct Hello; template <typename A> struct Hello<A> { template <typename A2> friend std::ostream & operator<<(std::ostream & s, const Hello<A2> & h) { return s << "specialized\n";...

adding an operator to std::vector

c++,operators
I am trying to add an operator to std::vector to identify when 2 vectors are approximately the same. How do I do it? template<typename T> //only numeric types class ImperciseVector: public std::vector<T> { public: ImperciseVector() {} //is this constructor needed? bool operator~ (const ImperciseVector& v) { T l1sq=0.0, l2sq=0.0, l3sq=0.0;...

What difference does variable order/side make with relational operators?

php,syntax,operators
Compare: if (donald_duck != null) if (roast_potatoes > 9000) if (love === 'explosions') and if (null != donald_duck) if (9000 <= roast_potatoes) if ('explosions' === love) In the languages I've written in, I've always used the first order since it makes sense human-wise. e.g. "Is the parrot dead?" vs "Is...

bash while loop comparison not evaluating

bash,comparison,operators
I am trying to understand the difference between coding for if and while statements in bash. In the script below, if I use IF I get the expected result using == OR -eq etc. However with the while loop each while seems to evaluate as true for all tests. While...

XQuery - Doing math on elements within a sequence and aggregating results

function,operators,xquery,sequence,aggregation
I'm trying to execute a XQuery sum function in a multiplication of two XML elements, but it has been difficult to avoid the iteration in a sequence of elements. For example, consider this case: sample data: <Orders> <Order> <OrderKey>1</OrderKey> <LineItem> <LineNumber>1</LineNumber> <Quantity>41</Quantity> <ExtendedPrice>70848.0000</ExtendedPrice> <Discount>0.0913</Discount> <Tax>0.0663</Tax> <ReturnFlag>A</ReturnFlag>...

best way to create an operator+ inside a class without declaring so many unnecessary variables

c++,c++11,operator-overloading,operators
So we were given a question where we have a class called Cocktail with name and volume attributes. Now they want us to "write an overloading operator addition to make the mix of two cocktails i.e. add two cocktails together which gives : volume of cocktail 1 + volume of...

C++ Copy constructor and Operator

c++,class,pointers,operators,copy-constructor
I was trying to understand Copy constructor and Operator. I read some code but I just didn't get it. Here is main function int main() { Cwin win1('A',"window") Cwin win2; win1 = win2; win1.set_data('B',"hello"); win1.show(); win2.show(); } I extract the most important code from Class Cwin Class Cwin { private:...

Why does comparing Integers by reference (==) work?

java,comparison,operators,equality
In Herbert Schildt's "Java: The Complete Reference, 9th Edition", there's an example that kinda baffles me. Its key point that i can't comprehend could be summed up to the following code: class Test { public static void main (String args[]) { Integer i1 = 6; Integer i2 = 6; Integer...

Calculate the bit depth from the colour count of a gif

c#,image-processing,operators
I've been reading though the gif specification trying to understand how the size of a colour table palette is calculated. From the example on Wikipedia here byte# hexadecimal text or (hex) value Meaning 0: 47 49 46 38 39 61 GIF89a Header Logical Screen Descriptor 6: 03 00 3 -...

User specified function with operators in R

r,function,functional-programming,operators,eval
I want to use a user-specified function and apply the function to a list of values. I envision that the user will give a 'formula' as a character string containing the names of variable and operators, e.g. "a * b %% c - d / e ^ f + g...

Ruby ||= operator acting funny

ruby,operators
From what I understand, a ||= 7 means the following: if a has a value, continue using that value, but if it does NOT have one, then set it to 7. Here is what happens though. If i have a and b as: a = true b = false then...

What is '<=>' 'Spaceship' Operator in PHP7?

php,operators,php-7,spaceship-operator
PHP7, which will come out in November this year will introduce a new type of operator, called SpaceShip (<=>) operator. My questions are: What is <=> (SpaceShip) operator in PHP /? How <=> it works? ...

Changing scope variable on ng-click without calling a function

javascript,angularjs,operators,angularjs-ng-click,angular-ng-if
How can I change a Scope Variable without calling a function from controller. I'm trying to show a div content when the editState variable equals to 1 but it's not working. HTML <body data-ng-controller="profileCtrl as pctrl"> <div data-ng-click="pctrl.editState === 1">Edit</div> <div data-ng-if="pctrl.editState === 1"> ..... </div> </body> JS(in profileCtrl controller)...

Operator '+=' behaves wierd

php,operators
My problem is that i with this code gets 3, but as it looks to me i should get 1, but just don't have any idea how to fix it. Example Code: $counter = 0; if (($counter = test2() !== false)) { $counter += 2; print $counter; } function test2()...

Objective C custom operator functions

objective-c,function,operators
Is it possible to have operator like functions in Obj C? Some thing like: int a = b times c; -(int)times:(int)v1 :(int)v2{ return v1*v2; } ...

Why can't I use `&&a` in C?

c,pointers,operators,address-operator
int main(int argc, char * argv[]) { int a = 10; int * sp = &a; int * * dp1 = &sp; int * * dp2 = &&a; // NG int * * dp3 = &(&a); // NG int * * dp4 = &((int *) &a); // NG } $...

Using Comparison Operators correctly

javascript,html,comparison,operators
I am new to HTML and have used Eclipse for Java before. Below I am trying to have the user input a number (0-5) and have the computer try and guess it. I have looked this over and it seems sound, the only thing that I have never done is...

Understanding an overloaded operator[] example

c++,operator-overloading,operators,overloading,binary-operators
I am confused with a question that I saw in a c++ test. The code is here: #include <iostream> using namespace std; class Int { public: int v; Int(int a) { v = a; } Int &operator[](int x) { v+=x; return *this; } }; ostream &operator<< (ostream &o, Int...

What does the + method in Ruby do, exactly?

ruby,math,operators,addition
Imagine I want to write my own math operators like "+" The simple version would be: def plus(a,b) return a+b end But this is not what the real "+" does. I want 3.add(4) # =>7 But how do I tell ruby to take the object that I used my method...

prefix and postfix operators c++

c++,operators,postfix-operator,prefix-operator
class compl{ float re,im; public: compl(float r, float i) {re=r; im=i;} compl& operator++() {++re; return*this;} //(1) compl operator++(int k){ compl z=*this; re++; im+=k; return z;} //(2) friend compl& operator--(compl& z) {--z.re; return z;} friend compl operator--(compl& z,int k) {compl x=z; z.re--; z.im-=k; return x;} }; (1) Why do we have...

How do I initialize a custom class like this?

c#,arrays,operators,overloading
C#: How do I initialize a custom class as shown below? Point3 Last = { 0, 0, 0 }; I realize that I can overload the assignment operator '=,' but I want to be able to assign things like this: Point3 p1 = { 3, 4, 5 }; Point3 p2...

Java equals plus operator [duplicate]

java,operators,equals-operator
This question already has an answer here: What is the difference between a += b and a =+ b , also a++ and ++a? 8 answers I need to explain this strange operator =+ (equal plus) Example #1: Double a = new Double(5); Double b = new Double(10); a...

String Concatenation Operator + Ambiguity

string,operator-overloading,operators,concatenation,language-design
I am currently working on a JVM-based programming language that supports operator overloading and custom operators. I wanted to stick to Java and use the + operator for String concatenation, and this is implemented and works flawlessly in my language. However, the operator is also used in various other places,...

Operators suddenly not working

time,vbscript,operators
A week ago I wrote this script which starts up when you log in and then greets you according to the time of the day. This morning it suddenly suddenly said: "Invalid time" (it would do that if all other elseif options wouldn't match the time). This used to work...

overloading arithmetic operators c++

c++,operators,overloading
I just started learning classes on C++ and I'm having quite some issues dealing with overloading arithmetic operators. First of all, in my header file I have: #ifndef MONEY_H #define MONEY_H #include <iostream> using namespace std; class Money{ public: Money(int dollars, int cents); Money(int dollars); Money(); int getDollars() const {return...

Are these two python statements the same?

python,operators
I have these two statements return self.getData() if self.getData() else '' and return self.getData() or '' I want to know are they same or there is any difference...

PHP `or` operator within an `if` statement [closed]

php,if-statement,operators
When doing an if statement can you use the or operator? e.g. //Bad syntax here is noted.It is an example ONLY and not working code. It won't work. if ($1 == 1 or $2 == 2 ) { ... } Or is this completely wrong? Note I started of using...

Reversing logical operators causes R function to fail?

r,operators
I have a vector that is essentially a series of data points recorded over time, for example- data_vector <- c(5,21,25,26,67,24,15,11,15,19,27,28,22,14,11) I want a function that identifies the indexes when the data crosses a user defined threshold, both as the data are decreasing and increasing. To identify and output the values...

Can you use equals assignment when removing delegate members in a disposing method?

c#,delegates,operators,variable-assignment,dispose
I have the following code in my class public class Receiver : IReceiver { public event EventHandler Received; public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (disposing) { if (Received != null) { foreach (EventHandler delegateMember in Received.GetInvocationList()) { Received -= delegateMember; } }...

Python- How to convert stringed operator back to its special meaning?

python,string,operators
I am writing a program in python3.3 which requires me to evaluate a stringed expression like : "2+3" I converted the '2' and '3' to numbers using int("2") int("3") But how do i change "+" to get its special meaning?...

Swift, two issues. 1) weak var 2) bang operator for @IBOutlet

swift,operators,automatic-ref-counting,iboutlet
Per: @IBOutlet weak var nameLabel: UILabel! Whenever I declare my IBOutlets, i just use var instead of weak var. But I've recently come across a few code templates that use weak var. Why do they do it? What's the added benefit? Why is there a bang operator at the end...