Parameters After Opening Bracket

Parameters after opening bracket

This is called trailing closure syntax.

I give a nice rundown of the various syntactic sugars of closures in this answer.

The expanded version of this code would be:

app.get("welcome", { (request: Request) throws -> ResponseRepresentable in 
return "Hello"
})

JavaScript: comma after opening bracket of parameter in syntax example

The brackets themselves mean "optional", and the = 0 gives the default value should you decide to omit that parameter. The reason why the comma is inside the brackets is because it forms part of the optional bit - if the second parameter is omitted, so is the comma.

In other words, you can use indexOf with only searchElement, in which case fromIndex is assumed to be zero. Or you can specify your own value for fromIndex if you don't want to start searching at element number zero.

So the first two below are equivalent while the third will start searching at a different point in the array:

x = haystack.indexOf (needle);
x = haystack.indexOf (needle, 0);
x = haystack.indexOf (needle, 42);

The Mozilla Developer Network has this to say on the matter (my emphasis):

fromIndex: The index to start the search at.

If the index is greater than or equal to the array's length, -1 is returned, which means the array will not be searched. If the provided index value is a negative number, it is taken as the offset from the end of the array.

Note: if the provided index is negative, the array is still searched from front to back. If the calculated index is less than 0, then the whole array will be searched.

Default: 0 (entire array is searched).

What do the brackets around the arguments mean when reading documentation for a method?

required [optional] <required> [<optional>, <but both needed>].

This is almost always the case.

Why the use of open bracket and close bracket to declare a variable in Java

Those are 'Generics'. Specifically, the things inside the brackets are called 'Type Parameters'. It allows different types to be chosen when you create the object or 'variable' as you call it.

So you could have a list of numbers with: new ArrayList<Integer>()

or a list of strings with: new ArrayList<String>()

https://www.tutorialspoint.com/java/java_generics.htm

In your example, it's creating a column to keep track of ids for books. The ids will be ints and the object they are identifying is books. But, you may want another TableColumn (which behaves the same as the Book Id column) but for tracking the titles of the books: TableColumn<Books, String> colTitle

What does it mean in documentation when arguments are in square brackets?

It means optional arguments.

It is not python specific syntax, it is more general grammar notation syntax, for example, from https://en.wikipedia.org/wiki/Extended_Backus–Naur_form:

Many BNF specifications found online today are intended to be human-readable and are non-formal. These often include many of the following syntax rules and extensions:

Optional items enclosed in square brackets: [].

Better explanation in https://en.wikipedia.org/wiki/Extended_Backus–Naur_form, Basics chapter.

Parameters in bracket after a javascript function

It's a IIFE (Immediately Invoked Function Expression), the second parenthesis invokes the function and allows you to pass arguments to the function

(function () {
//statements
})();

Check docs here

What does the brackets with comma around input arguments mean in python documentations?

It's a common convention in documentation to denote optional arguments with square brackets. That documentation is telling you that the second argument to boxPoints is optional. It has no syntactic meaning in Python; you can call the function with one or two arguments like normal.

PHP truncates parameter name after squared brackets?

This is intended behaviour. As you saw in your example, PHP builds arrays from GET parameters if it can, that is, if it finds square brackets in the variable name. There's a FAQ entry showing how that can sometimes be useful.

In your case, PHP sees xxx[1]yyy=42 as xxx[1]=42 which becomes an array.

As far as I know, PHP's query string parsing can not be changed, but you could use $_SERVER['QUERY_STRING'] and parse that yourself.

Passing arguments to function after parenthesis

Flatten() is the class instantiation (which is probably clear to you) and the second calls the instance with that parameter. For this to work the class must have a __call__ function defined.

Example:

class Sum:
def __call__(self, a, b, c):
return a + b + c

s = Sum()
print(s(3, 4, 5))
print(Sum()(3,4,5))

Also same behavior can be obtained with a function that returns another function with arguments:

def Sum2():
def Sum3(a, b, c):
return a + b + c
return Sum3

s2 = Sum2()
print(s2(3, 4, 5))
print(Sum2()(3, 4, 5))


Related Topics



Leave a reply



Submit