Talk:Named parameter

Latest comment: 3 years ago by 212.68.230.219 in topic Objective-C does not have named parameters

MATLAB edit

I think it is misleading to claim that MATLAB has named arguments. If whoever included MATLAB is referring to the varargs convention like foo('par1', 5, 'par2', 34), that is hacking named arguments, and does not constitute language support (since to use it requires explicit parsing).

I've removed MATLAB from the list. If some one can justify it (and give a cite) then put it back. 70.179.23.194 (talk) 04:42, 18 August 2009 (UTC)Reply


Needs sources and/or external references; more expansion beyond C/Java/Smalltalk would be a plus. Grammar and presentation need work &emdash; the article needs to have a much more encyclopedic tone, and examples with similar syntax would be a welcome improvement (for example, a method call presented twice in the same language, once with named parameters and once with ordinary parameters). --bmills 01:50, 16 January 2006 (UTC)Reply

There has been discussion on "keyword parameters" on comp.lang.fortran.

It seems that to some people "keyword parameters" are what are here called "named parameters". Others believe that "keyword" has another meaning and shouldn't be used with this meaning.

I have known them called "keyword parameters" at least since JCL and OS/360 assembler macros since around 1974, and I believe other systems and languages also use "keyword" with this meaning.

I would rather not get into the parameter/argument discussion, though.

this article could use some work edit

I may get to it someday. dr.ef.tymac (talk) 04:01, 25 July 2008 (UTC)Reply

ADA has also Named Parameters edit

http://en.wikibooks.org/wiki/Ada_Programming/Subprograms#Named_parameters

Janburse (talk) 11:00, 30 March 2012 (UTC)Reply

Pass-by-name? edit

I don't think "pass-by-name", as listed in the first paragraph, is an appropriate alternate term. A quick Google search turns up that this is considered the same as call-by-name, which is not at all like named parameters. See Evaluation strategy. Call-by-name is when you pass an entire expression in as a parameter, and its evaluation is delayed until it is used, and re-evaluated each time it is used. We should remove "pass-by-name" from the list in the first paragraph, unless anyone can name a language that uses that term for named parameters. — Preceding unsigned comment added by Qseep (talkcontribs) 03:23, 5 January 2014 (UTC)Reply

Objective-C does not have named parameters edit

In many parts of the article Objective-C is mentioned as one of the languages supporting named parameters. Apple, however, denies this by stating that "Some programming languages allow function definitions with so-called named arguments; it’s important to note that this is not the case in Objective-C"[1] (I assume named parameters and named arguments are equivalent). The Objective-C syntax is however similar so maybe it should just be rephrased? Or, if Objective-C does have named parameters by the common definition, it should be mentioned in the article that Apple denies it. --LoPoBo (talk) 10:28, 7 February 2014 (UTC)Reply

I have modified the article now. --LoPoBo (talk) 08:32, 28 August 2017 (UTC)Reply
if Objective-C doesn't have named parameters then Smalltalk and Self don't either. And while technically they don't (they have compound method names instead), functionally the result is the same, they have all the advantages of named parameters. — Preceding unsigned comment added by 212.68.230.219 (talk) 12:22, 27 July 2020 (UTC)Reply
The same goes for Swift. Example valid Swift code which shows that it does not have named parameters:
func add(a x: Int, a y: Int) -> Int {
    return x + y
}
add(a: 1, a: 2) // Returns 3
(a and a are argument labels) --LoPoBo (talk) 08:41, 28 August 2017 (UTC)Reply

References edit

Named ~arguments~, not named parameters edit

Named arguments is a more suitable term for the act of mapping an argument to a parameter name, and is used by companies working on modern languages (such as Microsoft with C# and Jetbrains with Kotlin).

Named parameters implies giving a name to a parameter, which does not properly describe the topic at hand. It may even be infered as aliasing a parameter, as the term "parameter" is used in the context of implementation rather than usage.

Using Google Trends, named arguments seems to fluctuate alongside named parameters, and within the past 30 days, there shows less than a 10 query difference between the two. Older languages, such as Ada and Fortran, have made the term "named parameters" a popular topic, yet doesn't fully describe the behavior being perform.

The current subcategory for optional parameters links to the page Default Arguments - a synonym for optional arguments. Renaming Named Parameters to Named Arguments would help maintain consistency and better describe the behavior. — Preceding unsigned comment added by Ipwxy (talkcontribs) 04:14, 25 August 2017 (UTC)Reply

I believe that they are, fully, "named-parameter arguments". Clhodapp (talk) 03:59, 21 August 2018 (UTC)Reply
I agree, a function definition has parameters while a function call has arguments. However I used "named parameters" below because it is the article name. elias

Functions are binary relations, either tuple or record sets may be domains edit

A mathematical function is a binary relation with the restriction that the first entry in the tuple can not appear in two different tuples in the relation.

---Hold it!, hold it! What about binary and ternary functions, they have two or three arguments---

That is just a colloquial name. Have you seen this kind of definitions in your maths book:

 

the first entry in a function   is taken from a domain set and the second entry is taken from a codomain set. In the above example  

  is the domain, and   is the codomain.

The members of   are tuples. What is colloquially called a binary function is a function with tuples as a domain.

The majority of programming languages lack tuples as data types, they are only used in function call and definition, but not freely available in other places.

Some languages have records or structures as data types, in many of such languages it is possible to define functions which have as a domain a set of records.

   struct pair { double x, y; };

   double f(pair p)
   { double x, y;
     double result;

     x = p.x;
     y = p.y;

/* here the same code as if f were defined as:
   double f(double x, double y)
*/
      return result;
   }

   int main()
   {  struct pair p;

      p.x = E1 ; /* E1 and E2 are expresions */
      p.y = E2 ; 
      /* may also be assigned p.y=E2; followed by p.x=E1; */
      
      /* f function is called: */ 
      E3 = f(p); 
      /* instead of tuples E3 = f(E1,E2); */

      /* do something */
      return 0;
   }

As shown in the example tuples are ordered, while records, being labelled are unordered.

Named parameters are syntactic sugar for functions with record sets instead of tuple sets as domains.

Pre-processing or macros may be used. The following example use macros:

   double f(struct pair p);
   #define fc(d,u,w) {struct pair p; p.u; p.w; d=f(p);}
   /* may be used as */ 
   double z;
   fc(z,x=1,y=2); /* or fc(z,y=2,x=1) */
   /* is translated to {struct pair p; p.x=1; p.y=2; z=f(p);} */
   /* ... */

it is not the safest way, but possible to implement in plain C.

Another syntactic sugar present in languages with named parameters is default values for arguments and optional parameters.

Is it a key feature in programming languages? Not really. Records and tuples are equivalent.

However the other features often present in languages with named parameters, like code with optional parameters are risky if it is possible to omit a default value, although the usual way to declare them as optional is to assign them a default value otherwise they could be a source for not initialized variables.

Default values for optional parameters could be implemented via macros as in the following example:

   #define f0(x) f(x,0)
   int f(int x, int y){ /* some code */ }

   /* use */
   int main()
   { int m, n; 
     /* ... */
     m = f(E1, 1); /* E1 and E2 are expressions   */
     n = f0(E2);   /* translated to n = f(E2, 0); */
     /* ... */
     return 0;
   }

Optional parameters should not be confused with curried functions, that is a feature of higher order languages. A higher order function has a function as codomain, for example:  

if called as   which is equivalent to   because function application is left associative. The evaluation of   returns a   function which in turn is applied to the "second" argument   returning a value in  .

That is all the explanation needed for this article.

Yes I know it is not in the Wikipedia style, and some more concrete examples of languages with named parameters should be added. I leave it to another volunteer to rewrite it.

In my opinion named parameters are a nice feature in macro languages like LaTeX and in C programs called from the shell (analysing the command line with int main(int argc, char *argv) with programner's code or some library functions like getopt in <unilib.h> or getsubopt in <stdlib.h>).

In programming languages I don't see a really useful reason to use named parameters (arguments).

I am not going to discus my reasons here, because that is too long, and an article should not have personal opinions, although I can argue it formally but very lengthily, maybe some other volunteer has some concise argument with a credited citation. elias