Questions tagged [parentheses]

The symbols "(" and ")", commonly used in programming languages. Please use this tag only if the specific usage of these symbols is a relevant part of the question.

The parentheses "(" and ")" are special cases of brackets, along with square brackets ("[" and "]") and curly brackets (or braces) ("{", "}").

Parentheses (singular parenthesis) have many uses in most programming languages, such as:

  • indicate the arguments of a function call;
  • specify the order of evaluation/execution of expressions;
  • create lists/arrays/vectors.
1024 questions
12
votes
4 answers

What do parentheses in binding paths mean?

Recently i've read 'Databinding overview' article at MSDN and there is such sample code: I know that {} means markup…
igorGIS
  • 1,888
  • 4
  • 27
  • 41
12
votes
5 answers

Two strings between brackets separated by a comma in C++

I came across unexpected (to me at least) C++ behavior today, shown by the following snippit: #include int main() { std::cout << ("1", "2") << std::endl; return 0; } Output: 2 This works with any number of strings between the…
Adversus
  • 2,166
  • 20
  • 23
11
votes
2 answers

Keeping parentheses balanced (Paredit for Vim?)

Emacs has Paredit which actively prevents you from typing unbalanced parentheses (short of C-Q ( to force-insert a literal one, or other craziness). Inserting an open paren also inserts a closing one. Backspacing over a paren either deletes both…
Brian Carper
  • 71,150
  • 28
  • 166
  • 168
11
votes
3 answers

Calling the parenthesis overload given a pointer

I can overload the parenthesis operator using the following signature: char& operator()(const int r, const int c); The intended usage of this would be: // myObj is an object of type MyClass myObj(2,3) = 'X' char Y = myObj(2,3); Which works as I…
chessofnerd
  • 1,219
  • 1
  • 20
  • 40
11
votes
3 answers

Why do some Python functions have an extra set of parenthesis around the argument list?

I've seen some Python functions written like this: def get_year((year,prefix,index,suffix)): return year How does that differ (if at all) from other functions without the extra parentheses like this: def do_format(yr,pfx,id,sfx): return "%s %s…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
11
votes
2 answers

Why are tokens wrapped by parentheses not r-value expressions?

Consider the following code: #include struct Foo { Foo() : bar( 0 ) {} int bar; }; int main() { Foo foo; ++(foo.bar); std::cout<< foo.bar << std::endl; system("pause"); return 0; }; Why does foo.bar evaluate to…
Martin85
  • 308
  • 4
  • 13
10
votes
3 answers

Changing Paredit Formatting

When using paredit in programming modes such as C, typing ( will insert a space before the paren when I'm trying to call a function, leaving me with: foo () Is there a way to disable the insertion of the space without changing paredit's source?
Nathaniel Flath
  • 15,477
  • 19
  • 69
  • 94
10
votes
3 answers

Parenthesizing a string so that expression takes a given value

The following problem is from the chapter on Dynamic Programming by Vazirani et. al. [6.6]Let us define a multiplication operation(×) on three symbols a; b; c according to the following table: Therefore, a × a = b , a × b = b etc. Find an…
10
votes
9 answers

Parentheses pairing ({}[]()<>) issue

I want to be able to pair up all parentheses in a string, if they aren't paired then then they get their index number and False. It seems like it is repeating some values over and over, i.e cl == pop[1]. I have tried to see where the problem is but…
thabubble
  • 640
  • 1
  • 8
  • 17
10
votes
2 answers

Why is the Object.keys() method not added to Object.prototype?

I am confused about why JavaScript works in a certain way. If I have an Object set to the variable of obj, and if I wanted to list all the keys in the object, I would say Object.keys(obj) Why wouldn't it be the following? obj.keys() If I was…
Greg
  • 111
  • 4
10
votes
1 answer

Ruby block and unparenthesized arguments

I extracted simple example: require 'pp' x = 1..3 pp x.map do |i| {:value => i, :double => (i*2)} end pp x.map { |i| {:value => i, :double => (i*2)} } pp(x.map do |i| {:value => i, :double => (i*2)} end) pp(x.map { |i| {:value => i, :double =>…
rkj
  • 8,787
  • 2
  • 29
  • 35
10
votes
1 answer

Time complexity for combination of parentheses

I tried to do the classical problem to implement an algorithm to print all valid combinations of n pairs of parentheses. I found this program (which works perfectly) : public static void addParen(ArrayList list, int leftRem, int rightRem,…
salamanka44
  • 904
  • 3
  • 17
  • 36
10
votes
2 answers

C++ warning: suggest parentheses around arithmetic in operand of |

I have a code like A = B|C|D|E; Throwing the warning "suggest parentheses around arithmetic in operand of |" Expecting that expression needs high priority paranthesis for operators, tried the following ways: A=(B|C)|(D|E); one more as…
Programmer
  • 111
  • 1
  • 1
  • 5
10
votes
2 answers

Automatically fix missing parenthesis in C

I converted some Fortran code to C. I was wondering if someone could help me solve the following problem: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses] I know this warning is caused by syntax like this: A || B && C Which…
user2470258
  • 121
  • 1
  • 4
9
votes
4 answers

short circuiting and parenthesis

Does it matter how I group subexpressions when dealing with a single short-circuiting operator? a && b && c && d a && (b && (c && d)) (a && b) && (c && d) ((a && b) && c) && d Are the above expressions equivalent?
foobar
  • 4,968
  • 3
  • 17
  • 11