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

Named Parameters solution in PHP 7+

How can I implement the named argument feature in PHP 7+? The ideal syntax is: find($wildcard, relative = true, listIfEmpty = false) { ... } But there is no such solution. In the answer, I implemented the shortest possible solution that…
Behnam
  • 2,212
  • 2
  • 22
  • 32
7
votes
1 answer

Does VBScript allow named arguments in function calls?

I am trying to run the following code in VBScript but it is not compiling the last statement. Is it because VBScript doesn't allow named arguments? Filename_Argument = WScript.Arguments(0) Set objExcel =…
CJ7
  • 22,579
  • 65
  • 193
  • 321
7
votes
1 answer

require named parameters in python function

I have created a class and I would like to give the user (probably me) two different ways to initialize it. For this example the class is called Box and I would like to initialize it with either: two sets of Cartesian coordinates, representing the…
VectorVictor
  • 820
  • 8
  • 17
7
votes
3 answers

How to used named parameters with a curried function in scala

I have a method with 4 parameters that gets used in blocks. Within each block, the first parameter is always the same: // Block 1 - first parameter always "A" foo(a="A", b="x", c="y", d="z") foo(a="A", b=".", c=",", d="-") foo(a="A", b="1", c="2",…
rmin
  • 1,018
  • 1
  • 9
  • 18
7
votes
4 answers

JavaScript function with optional parameters

I'm new to JavaScript coming from Python background. In Python parameters can be passed as key and value as such: def printinfo( name, age = 35 ): print "Name: ", name print "Age ", age return; Then the function could be called as…
codeBarer
  • 2,238
  • 7
  • 44
  • 75
7
votes
1 answer

Can't use a negative number in named parameters in Scala

I'm using Scala 2.11.2. If I have this Fraction class: case class Fraction(numerator: Int, denominator: Int) {} Then this gives an error: val f = new Fraction(numerator=-1, denominator=2) But this is not: val f = new Fraction(-1,…
gaijinco
  • 2,146
  • 4
  • 17
  • 16
7
votes
4 answers

Idiomatic Scala for applying functions in a chain if Option(s) are defined

Is there a pre-existing / Scala-idiomatic / better way of accomplishing this? def sum(x: Int, y: Int) = x + y var x = 10 x = applyOrBypass(target=x, optValueToApply=Some(22), sum) x = applyOrBypass(target=x, optValueToApply=None, sum) println(x) //…
7
votes
2 answers

define default named arguments in terms of other arguments in scala

I have a case class that stores three tied parameters. I'd like to define companion object that may build the class from any two parameters, something that looks like the sample below, that is obviously incorrect: def test(start : Float = end -…
ayvango
  • 5,867
  • 3
  • 34
  • 73
7
votes
4 answers

Dynamically adding key-arguments to method

I would like to set the default key-arguments of an instance method dynamically. For example, with class Module(object): def __init__(self, **kargs): set-default-key-args-of-method(self.run, kargs) # change run arguments def…
Juh_
  • 14,628
  • 8
  • 59
  • 92
7
votes
1 answer

Named Parameters rather than positional for Spring MessageSource.getMessage()

we are using Spring MessageSource to build error messages in our app. We populate our error messages like this dobInvalid = The DOB supplied {0} is invalid We want to use named parameters so we can do dobInvalid = The DOB supplied {dob} is…
Mark Hanlon
  • 121
  • 1
  • 3
7
votes
3 answers

Evaluation order of named parameters

Possible Duplicate: Are parameters evaluated in order when passed into a method? Say I have void foo (int x, int y) and call it by: foo(y: genNum(), x: genNum()) Does C# guarantee the evaluation order of x and y in this case?
Thomas Eding
  • 35,312
  • 13
  • 75
  • 106
6
votes
2 answers

Mixing Out and Named Parameters in C#: Why Does Out Parameter Need to be Named As Well?

Short Version: A named argument following an out argument gives a compiler error, but I cannot find any support for this behaviour in the language specification. Long Version: I'm using the Enum.TryParse three parameter overload, but I would…
Richard
  • 106,783
  • 21
  • 203
  • 265
6
votes
1 answer

C# Named parameters, Inheritance and overloading surprise

I was going through some presentation regarding C# 4.0 and in the end the presenter posted a quiz with the following code. using System; class Base {     public virtual void Foo(int x = 4, int y = 5) {         Console.WriteLine("B x:{0}, y:{1}", x,…
ferosekhanj
  • 1,086
  • 6
  • 11
6
votes
2 answers

How did they implement this syntax in the Massive Micro-ORM, multiple args parameters?

Here on this page, Scott Hanselman shows two examples from Micro-ORMs Dapper and Massive, and the Massive-example caught my interested, because I don't see how they could implement that syntax. The example is as follows, where I'm going to break it…
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
6
votes
1 answer

How to use Named Arguments in F#

Calling a Dictionary's Add() method using named arguments works in F#. let d = Dictionary() d.Add(key = "five", value = 5) let d2= Dictionary() d2.Add(key = "five", value = 5) d2.Add(key = 5, value = 5) In Polly's Context…
Brett Rowberry
  • 1,030
  • 8
  • 21