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
27
votes
2 answers

Format Negative numbers in parenthesis BUT NOT with $ symbol?

I have seen all over the internet to format a NEGATIVE double value with a parenthesis WITH a $ symbol ie. currency type. I am looking for a .NET format string, to format 12345.67 = 12,345.67 -12345.67 = (12,345.67)
user715993
  • 291
  • 1
  • 5
  • 8
26
votes
2 answers

Do parentheses make a difference when determining the size of an array?

The following program prints the same number twice on gcc 4.8.2: #include int main() { char a[13]; printf("sizeof a is %zu\n", sizeof a ); printf("sizeof(a) is %zu\n", sizeof(a)); } According to this reddit post, gcc is not…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
25
votes
3 answers

Scala methods with no arguments

In Scala there are two ways to define a method which takes no argument 1 def a=println("hello") 2 def a()=println("hello") These two methods are exactly same but (2) can be called with and without parentheses. Is there any special reason…
codecool
  • 5,886
  • 4
  • 29
  • 40
24
votes
2 answers

C macros and use of arguments in parentheses

Example #define Echo(a) a #define Echo(a) (a) I realize there probably isn’t a significant difference here, but why would you ever want to include the a within parenthesis inside the macro body? How does it alter it?
rubixibuc
  • 7,111
  • 18
  • 59
  • 98
23
votes
2 answers

Python generator expression parentheses oddity

I want to determine if a list contains a certain string, so I use a generator expression, like so: g = (s for s in myList if s == myString) any(g) Of course I want to inline this, so I do: any((s for s in myList if s == myString)) Then I think it…
Ari
  • 3,460
  • 3
  • 24
  • 31
23
votes
3 answers

What is the meaning of parentheses in Haskell type signatures?

Take the type signature of fmap (the Functor method) as an example: (a -> b) -> f a -> f b How is that different from the following type signature? a -> b -> f a -> f b Is there even a difference between those two type signatures?
Trident D'Gao
  • 18,973
  • 19
  • 95
  • 159
23
votes
5 answers

Indices of matching parentheses in Python

Is there a way to get indices of matching parentheses in a string? For example for this one: text = 'aaaa(bb()()ccc)dd' I'd like to get a dictionary with values: result = {4:14, 7:8, 9:10} which means that parentheses on index 4 and 14 are…
Peter Gubik
  • 347
  • 1
  • 3
  • 10
22
votes
4 answers

Idiomatic use of parentheses in Ruby

array.include? 'foo' or array.include? 'bar' is a syntax error (unexpected keyword_or). Parentheses solve the problem, but as I'm new to Ruby I've no idea which of the following is considered more idiomatic: Option 1 array.include?('foo') or…
davidchambers
  • 23,918
  • 16
  • 76
  • 105
21
votes
4 answers

What do parentheses () used on their own mean?

I read in learn you haskell that Enum members are sequentially ordered types ... Types in this class: (), Bool, Char ... Also it appears in some signatures: putChar :: Char -> IO () It is very difficult to find info about it in Google as…
cibercitizen1
  • 20,944
  • 16
  • 72
  • 95
20
votes
5 answers

C# Regex match anything inside Parentheses

I want to match anything inside parentheses but the result must exclude the parentheses as well. Examples: Initialize(P90W) Brake(45X) Result: 990W 45X note results without the Parentheses. I've been trying to make this work but to no avail I…
Michael D. Irizarry
  • 6,186
  • 5
  • 30
  • 35
20
votes
3 answers

SQL Parentheses use in an OR clause

Was wondering whether anyone would know why do we use the parentheses in this SQL: So, the format goes as follows: Name,location and department of the service of the employees whose name starts with A or B. (A rough translation from French). I…
angela
  • 303
  • 1
  • 2
  • 5
19
votes
4 answers

parsing nested parentheses in python, grab content by level

Apparently this problem comes up fairly often, after reading Regular expression to detect semi-colon terminated C++ for & while loops and thinking about the problem for a while, i wrote a function to return the content contained inside an arbitrary…
justin cress
  • 1,745
  • 5
  • 24
  • 35
19
votes
13 answers

How to remove nested parentheses in LISP

How can I remove nested parentheses recursively in Common LISP Such as (unnest '(a b c (d e) ((f) g))) => (a b c d e f g) (unnest '(a b)) => (a b) (unnest '(() ((((a)))) ())) => (a) Thanks
bubdada
  • 343
  • 1
  • 3
  • 10
18
votes
4 answers

What is the reason to use parenthesis-less subroutine calls in Perl?

As per perldoc perlsub: The & is optional in modern Perl, as are parentheses if the subroutine has been predeclared. I notice that a lot of times, people use the fact that you can omit parenthesis when calling Perl subroutines (e.g., randomly…
DVK
  • 126,886
  • 32
  • 213
  • 327
17
votes
5 answers

Why would the addition of parentheses in SQL query cause the results to change?

When I execute the following query, even though there are 11 records that match, none are returned as written. However, if I remove the parentheses on lines 6 and 9, all 11 records are returned as expected. 1 select obj_id, obj_title,…
Sam F.
  • 197
  • 1
  • 1
  • 6
1 2
3
68 69