View Answer

First made popular in C, the binary operator shorthand, for example:

a += b      # and...
a ||= b

acts like:

a = a + b   # and ... note the short circuit difference ... 
a || a = b

The rearrangement for a more effective short circuit is a graceful way of dealing with a check for nil as it avoids the assignment altogether if it can. The assignment may have side effects. Just another example of seriously thoughtful design in Ruby.

See http://www.rubyinside.com/what-rubys-double-pipe-or-equals-really-does-5488.html for a more wordy explanation.

Score: 10
Comments: 3
Date posted: 4/17/2011

View Answer

Okay, so I did a bit of searching and there is a double colon operator in JScript, which was Microsoft's implementation of JavaScript:

a double colon is used as separator between the script ID and the event name

My guess is that's not part (or no longer part) of Internet explorer's ECMAScript implementation but it belongs (or used to belong) to Microsoft Office's implementation

What does ‘::’ (double colon) do in javascript for events?

Which was a really cool find, but I've never seen a double colon operator being used in TS or ECMAScript. You can use lambda expressions [].forEach((item: any) => console.log(item))

but I'm pretty sure JS or TS doesn't have a wrapper for a lambda expression like Java does.

EDIT: I also found this What does ‘::’ (double colon) do in JavaScript? after a little more searching and it is also a valid ES7 operator as syntactic sugar for bind: http://blog.jeremyfairbank.com/javascript/javascript-es7-function-bind-syntax/

Although it doesn't behave the same way as Java's :: operator.

Score: 2
Comments: 0
Date posted: 5/17/2019

View Answer

You can solve this by using the splat operator:

h.slice(*a)

This will produce

> {:a=>"test1"}

For an explanation what the asterisk does, please see this link.

Score: 2
Comments: 0
Date posted: 10/17/2013

View Answer

I'm assuming index is a numpy array - if so, the explanation for what the tilde operator is doing can be found here:

What does the unary operator ~ do in numpy?

As for what you're trying to accomplish, you could assemble a complementary index array:

notIndex = numpy.array([i for i in xrange(256) if i not in index])

And then use notIndex instead of index.

Score: 2
Comments: 0
Date posted: 1/7/2015

View Answer

Martin York has a good explanation of what is happening and James McNellis gives you a decent answer on what to do if you are using literals.

If you are using int/float/short/etc variables instead, then you can get around this by just casting them inline. e.g.

double Average(int *values, int count)
{
    int sum = 0;
    for(int i = 0; i < count; ++i) sum += values[i];
    return sum / (double) count; // Cast one of the values to double, that will force both to be calculated as doubles
    // note that "return (double)sum / count;" won't work because operator precendence
    // causes this to translate to "return (double)(sum / count);"

    // the "c++ way" to do this would be through the static_cast operator
    // i.e. "return static_cast<double>(sum)/count;"
    //  or  "return sum/static_cast<double>(count);"
    // both of which are very explicit in what you are casting
}
Score: 1
Comments: 1
Date posted: 7/22/2010


1


© 2021 Search Overflow
Contributions licensed under cc by-sa