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
16
votes
5 answers

Vim plugin for 'auto-closed' parenthesis?

I've searched near and far, and not found a plugin that can simply auto-close a set of parenthesis like Textmate. For example: Vim : (*manually close parens* → ) Textmate: (*Auto closes parens*) If you can describe a plugin for this, I will be…
beakr
  • 5,709
  • 11
  • 42
  • 66
16
votes
4 answers

When to use parenthesis in Scala infix notation

When programming in Scala, I do more and more functional stuff. However, when using infix notation it is hard to tell when you need parenthesis and when you don't. For example the following piece of code: def caesar(k:Int)(c:Char) = c match { …
Felix
  • 8,385
  • 10
  • 40
  • 59
16
votes
1 answer

Why and how do extra parentheses change the type of an expression in C++ (C++11)?

Under what circumstances do extra grouping parentheses break things in C++ (C++11 specifically)? For reasons that are not relevant here, I ended up at one point with an expression that had an extra, unnecessary set of parens around it, and I…
blahedo
  • 834
  • 8
  • 19
16
votes
4 answers

How do you make parentheses match height when they're split between lines in LaTeX math?

Consider the following example \begin{equation} \begin{split} f = & \left( \frac{a}{b} + \right. \\ & \left. c \right) + d \end{split} \end{equation} In the result, the left parenthesis on the first line is very…
cheshirekow
  • 4,797
  • 6
  • 43
  • 47
15
votes
2 answers

Confused about Scala method calling conventions, specifically the sum function on Seq

I was playing around with the new Scala IDE (Eclipse 3.6.2 + Scala IDE 2.0.0 [Scala 2.9.0]) and I tried to do something simple like this: (1 to 10).sum That works fine, but I've been doing a lot of Groovy also recently and I automatically wrote: (1…
Phuong LeCong
  • 1,834
  • 16
  • 19
15
votes
3 answers

java escape parenthesis

i have this little class to make a multiple replace on a string: import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang.StringUtils; public class MultipleReplace…
Laphroaig
  • 619
  • 4
  • 12
  • 26
15
votes
3 answers

Pretty Printing AST with Minimal Parentheses

I'm implementing a pretty-printer for a JavaScript AST and I wanted to ask if someone is aware of a "proper" algorithm to automatically parenthesize expressions with minimal parentheses based on operator precedence and associativity. I haven't …
14
votes
3 answers

Different meanings of parentheses in C++?

I am a bit confused withnthe interpretation of parentheses by the compiler. Can some one please explain what actually happens in such contexts? Casting: (int)a or int(a) Parameter passing: template int size(t (&)[n]){return…
Kiran
  • 5,478
  • 13
  • 56
  • 84
14
votes
5 answers

Parenthesis in variables inside IF blocks

In one of my scripts, I need to use variables that contain parenthesis inside IF statements, but either the string is missing a closing parenthesis or the script exits prematurely with * was unexpected at this time (not actually an asterisk),…
mythofechelon
  • 3,692
  • 11
  • 37
  • 48
13
votes
2 answers

How to find all possible regex matches in python?

I am trying to find all possible word/tag pairs or other nested combinations with python and its regular expressions. sent = '(NP (NNP Hoi) (NN Hallo) (NN Hey) (NNP (NN Ciao) (NN Adios)))' def checkBinary(sentence): n =…
Wolf Vos
  • 177
  • 1
  • 8
13
votes
3 answers

PHP is confused when adding and concatenating

I have the following code: When I execute my code I get: 2 sum: 3 Why does it fail to print the string "sum:" in the first echo? It seems to be fine…
aizquier
  • 557
  • 5
  • 12
12
votes
4 answers

Why are there two parentheses after `let` in emacs lisp?

I'm doing a tutorial on emacs lisp, and it's talking about the let function. ;; You can bind a value to a local variable with `let': (let ((local-name "you")) (switch-to-buffer-other-window "*test*") (erase-buffer) (hello local-name) …
Hatshepsut
  • 5,962
  • 8
  • 44
  • 80
12
votes
2 answers

Jump over end parenthesis/bracket/quotation in atom editor with TAB

In atom editor, when I type console.log( for example, it becomes console.log() and the cursor stays between the two parenthesis. So I have to use End button or Right arrow key to jump out of there. Is there any way to use Tab instead (to jump out of…
Alireza Omidi
  • 163
  • 1
  • 2
  • 12
12
votes
2 answers

laravel - why function call with no parentheses?

I see this in a laravel tutorial : Auth::user()->item; where item is a function, inside models\User.php : function item() { return $this->hasMany('Item', 'owner_id'); } where Item is for models\Item.php So why the parentheses is not needed when…
trogne
  • 3,402
  • 3
  • 33
  • 50
12
votes
4 answers

C# Regex - How to remove multiple paired parentheses from string

I am trying to figure out how to use C# regular expressions to remove all instances paired parentheses from a string. The parentheses and all text between them should be removed. The parentheses aren't always on the same line. Also, their might be…
Matt Brandon
  • 321
  • 5
  • 13