parentheses

How to get an expression between balanced parentheses

耗尽温柔 提交于 2019-11-27 04:48:37
问题 Suppose I am given the following kind of string: "(this is (haha) a string(()and it's sneaky)) ipsom (lorem) bla" and I want to extract substrings contained within a topmost layer of parentheses. I.e. I want to obtain the strings: "this is (haha) a string(()and it's sneaky)" and "lorem" . Is there a nice pythonic method to do this? Regular expressions are not obviously up to this task, but maybe there is a way to get an xml parser to do the job? For my application I can assume the parentheses

Matlab Calling Functions without parentheses

大憨熊 提交于 2019-11-27 03:38:21
问题 What is the correct name for the situation where a Matlab-script calls a function, but provides arguments without parentheses? Example: clear xx Alternatively, I could use parentheses and transfer a string with the variable name: clear('xx') How can I distinguish between both alternatives when googling for a solution? Bonus Question: How can I put the content of a variable into a call that is NOT using parentheses? Specifically, a build-script using mcc with a dynamic -o filename option;

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

≡放荡痞女 提交于 2019-11-27 02:49:53
问题 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 nested parentheses. An example of the string would be This is a (string). I would like all of the (parentheses to be removed). This (is) a string. Nested ((parentheses) should) also be removed. (Thanks) for your help. The desired output should be as

Scala methods with no arguments

眉间皱痕 提交于 2019-11-27 01:56:20
问题 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 for which this feature is allowed in Scala.It confuses me which to use and when? 回答1: The general rule is that you should add an empty parameter list at both declaration site and call site whenever the method (not function) has side effects. Otherwise, Scala

What is the meaning of curly braces? [closed]

不羁的心 提交于 2019-11-27 01:13:37
问题 Just starting to figure Python out. I've read this question and its responses: Is it true that I can't use curly braces in Python? and I still can't fathom how curly braces work, especially since pages like Simple Programs: http://wiki.python.org/moin/SimplePrograms use curly braces all over the place. I understand square brackets and regular curved parentheses, but I don't know what's meant by "defining dictionaries" or what they're supposed to represent. 回答1: "Curly Braces" are used in

Can we remove parentheses around arguments in C macros definitions?

北城以北 提交于 2019-11-26 23:38:11
问题 From http://c-faq.com/style/strcmp.html, I learned the following convenience macro: #define Streq(s1, s2) (strcmp((s1), (s2)) == 0) I want to know why there are so many parentheses being used in this macro. Is each parenthesis serving a purpose or is this macro using redundant parentheses that serve no purpose? Can we remove the parentheses around s1 and s2 and make a macro like this? #define MyStreq(s1, s2) (strcmp(s1, s2) == 0) The MyStreq macro seems to work for me as nicely as Streq .

What do the parentheses around a function name mean?

好久不见. 提交于 2019-11-26 23:34:02
In one of my project source files, I found this C function definition: int (foo) (int *bar) { return foo (bar); } Note: there is no asterisk next to foo , so it's not a function pointer. Or is it? What is going on here with the recursive call? NPE In the absence of any preprocessor stuff going on, foo 's signature is equivalent to int foo (int *bar) The only context in which I've seen people putting seemingly unnecessary parentheses around function names is when there are both a function and a function-like macro with the same name, and the programmer wants to prevent macro expansion. This

When to use parenthesis in Scala infix notation

陌路散爱 提交于 2019-11-26 22:45:13
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 { case c if c isLower => ('a'+((c-'a'+k)%26)).toChar case c if c isUpper => ('A'+((c-'A'+k)%26)).toChar case _ => c } def encrypt(file:String,k:Int) = (fromFile(file) mkString) map caesar(k)_ The (fromFile(file) mkString) needs parenthesis in order to compile. When removed I get the following error: Caesar.scala:24: error: not found: value map def encrypt

When can the parentheses around arguments in macros be omitted?

孤街浪徒 提交于 2019-11-26 22:08:12
问题 Often and often I felt some of the parentheses around arguments in macro definitions were redundant. It’s too inconvenient to parenthesize everything. If I can guarantee the argument needs not be parenthesized, can I omit the parentheses? Or is parenthesizing them all highly recommended? I came up with this question when I wrote: #define SWAP_REAL(a, b, temp) do{double temp = a; a = b; b= temp;}while(0) I think that if an argument appears as an l-value in the macro, the parentheses can be

When do extra parentheses have an effect, other than on operator precedence?

孤街醉人 提交于 2019-11-26 19:26:28
Parentheses in C++ are used in many places: e.g. in function calls and grouping expressions to override operator precedence. Apart from illegal extra parentheses (such as around function call argument lists), a general -but not absolute- rule of C++ is that extra parentheses never hurt : 5.1 Primary expressions [expr.prim] 5.1.1 General [expr.prim.general] 6 A parenthesized expression is a primary expression whose type and value are identical to those of the enclosed expression. The presence of parentheses does not affect whether the expression is an lvalue. The parenthesized expression can be