Questions tagged [named-parameters]

Named parameters enable you to specify an argument for a particular parameter by associating the argument with the parameter's name rather than with the parameter's position in the parameter list.

371 questions
15
votes
5 answers

Value classes introduce unwanted public methods

Looking at some scala-docs of my libraries, it appeared to me that there is some unwanted noise from value classes. For example: implicit class RichInt(val i: Int) extends AnyVal { def squared = i * i } This introduces an unwanted symbol i: 4.i …
0__
  • 66,707
  • 21
  • 171
  • 266
15
votes
5 answers

Does PHP have "named parameters" so that early arguments can be omitted and later arguments can be written?

In PHP you can call a function with no arguments passed in so long as the arguments have default values like this: function test($t1 ='test1',$t2 ='test2',$t3 ='test3') { echo "$t1, $t2, $t3"; } test(); However, let's just say I want the last…
matthy
  • 8,144
  • 10
  • 38
  • 47
15
votes
3 answers

Optional named arguments in Mathematica

What's the best/canonical way to define a function with optional named arguments? To make it concrete, let's create a function foo with named arguments a, b, and c, which default to 1, 2, and 3, respectively. For comparison, here's a version of…
dreeves
  • 26,430
  • 45
  • 154
  • 229
14
votes
5 answers

How to perform batch update in Spring with a list of maps?

New to Spring, I am trying to insert a List> into a table. Until now I have been using the SqlParameterSource for batch update, which works fine when a java bean is supplied to them. Something like this: @Autowired …
Mono Jamoon
  • 4,437
  • 17
  • 42
  • 64
13
votes
3 answers

Use Curiously Recurring Template Pattern (CRTP) with additional type parameters

I try to use the Curiously Recurring Template Pattern (CRTP) and provide additional type parameters: template class Base { Int *i; Float *f; }; ... class A : public Base
hrr
  • 1,807
  • 2
  • 21
  • 35
13
votes
7 answers

Does Perl support named parameters in function calls?

In my experience of languages that support the feature, programs that call functions with named parameters rather than positional parameters are easier to read and maintain. I think Perl has this feature, but it's not working for me. Is it a quirk…
Iain Samuel McLean Elder
  • 19,791
  • 12
  • 64
  • 80
12
votes
3 answers

Scala named and default arguments in conjunction with implicit parameters

Consider the following: def f(implicit a: String, y: Int = 0) = a + ": " + y implicit val s = "size" println(f(y = 2)) The last expression causes the following error: not enough arguments for method f: (implicit a: String, implicit…
Martin Studer
  • 2,213
  • 1
  • 18
  • 23
12
votes
3 answers

Named/optional parameters in Delphi?

In one of the Delphi demo applications, I've stumbled upon some syntax that I didn't know the Delphi compiler accepted: // ......\Demos\DelphiWin32\VCLWin32\ActiveX\OleAuto\SrvComp\Word\ // Main.pas, line 109 Docs.Add(NewTemplate := True); //…
Wouter van Nifterick
  • 23,603
  • 7
  • 78
  • 122
12
votes
1 answer

Hibernate: Can't use a named parameter for OFFSET and LIMIT?

I'm trying to get the following NamedQuery to work: @NamedQuery(name="MyEntity.findByUser", query="SELECT m FROM MyEntity m WHERE m.owner = :user OFFSET :offset LIMIT :limit") The problem is that this causes Hibernate to explode with the following…
aroth
  • 54,026
  • 20
  • 135
  • 176
12
votes
1 answer

How to provide a non-slurpy array or named array from the command line?

First of all: raku (perl6) is amazing. And so is Cro. It only took a week-end to fall in love. However now I stumble over something that must be extremely simple. If I use a slurpy parameter in a multiple dispatch MAIN this is recognized and works…
12
votes
2 answers

How to set named argument for string.Format?

I have C# error when calling: string.Format(format:"abbccc", 1,22); The error is "Named argument specifications must appear after all fixed arguments have been specified" How can I fix this? [Edit] I prefer to use named parameters.
Nam G VU
  • 33,193
  • 69
  • 233
  • 372
11
votes
3 answers

Scala Properties Question

I'm still learning Scala, but one thing I thought was interesting is that Scala blurs the line between methods and fields. For instance, I can build a class like this... class MutableNumber(var value: Int) The key here is that the var in the…
shj
  • 1,558
  • 17
  • 23
11
votes
6 answers

Can I pass arbitrary number of named parameters to function in C#?

Is there some kind of equivalent of Python's **kwargs in C#? I would like to be able to pass variable number of named arguments into functon, then get them as something Dictionary-like inside function and cycle over them.
src091
  • 2,807
  • 7
  • 44
  • 74
10
votes
3 answers

Is there a nicer way to do c named arguments?

I'm trying to implement a flexible debug macro/function lib and named/optional arguments seem like the best way to implement the functions. Is there a nicer way to do named arguments in c then the following? enum named_args…
Roman A. Taycher
  • 18,619
  • 19
  • 86
  • 141
10
votes
1 answer

Kotlin: What are named lambda arguments used for?

In Kotlin, it is possible to give lambda arguments names in their definition. fun example(lambda: (a: Int, b: Int) -> Int) As you can see, a and b are named in the lambda. I thought this might be really useful information for an IDE, to generate…
Jire
  • 9,680
  • 14
  • 52
  • 87