Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Named parameter
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Use in programming languages == Named parameters are supported explicitly in many languages. A non-exhaustive selection of examples includes [[Ada (programming language)|Ada]],<ref>{{cite book|author=|year=1983|title=Reference Manual for the Ada Programming Language|publisher=United States Department of Defense|isbn=}}</ref> [[C Sharp 4.0|C# 4.0+]],<ref>{{Cite web|last=BillWagner|title=Named and Optional Arguments - C# Programming Guide|url=https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/named-and-optional-arguments|access-date=2021-06-16|website=Microsoft Learn|language=en-us}}</ref> [[Ceylon (programming language)|Ceylon]]{{Citation needed|date=July 2021}}, [[ColdFusion Markup Language]] (CFML){{Citation needed|date=July 2021}}, [[Common Lisp]],<ref>{{Cite web|title=Functions|url=https://lispcookbook.github.io/cl-cookbook/functions.html|access-date=2021-10-28|website=The Common Lisp Cookbook }}</ref> [[Fortran]]{{Citation needed|date=July 2021}}, [[IDL (programming language)|IDL]]{{Citation needed|date=July 2021}}, [[Kotlin (programming language)|Kotlin]],<ref>{{Cite web|title=Functions {{!}} Kotlin|url=https://www.jetbrains.com/idea/functions.html|access-date=2021-06-16|website=Kotlin Help|language=en-US}}{{dead link|date=December 2023}}</ref> [[Mathematica]]{{Citation needed|date=July 2021}}, [[PL/SQL]]{{Citation needed|date=July 2021}}, [[PowerShell]]{{Citation needed|date=July 2021}}, [[Python (programming language)|Python]],<ref>{{Cite web|title=8. Compound statements - 8.7. Function definitions |url=https://docs.python.org/3/reference/compound_stmts.html#function-definitions|access-date=2021-10-28|website=Python documentation }}</ref> [[R (programming language)|R]],<ref>{{Cite web|title=10.3 Named arguments and defaults|url=https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Named-arguments-and-defaults |publisher=The Comprehensive R Archive Network |access-date=2021-10-28|website=An Introduction to R}}</ref> [[PHP]],<ref>{{Cite web|title=PHP: Function arguments - Manual - Named Arguments |url=https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments|access-date=2021-06-16|website=PHP }}</ref> [[Ruby (programming language)|Ruby]],<ref>{{Cite web|title=Ruby 2 Keyword Arguments|url=https://thoughtbot.com/blog/ruby-2-keyword-arguments |first1=Ian C. |last1=Anderson |access-date=2021-10-28|website=thoughtbot |date=21 July 2014}}</ref> [[Scala (programming language)|Scala]],<ref>{{Cite web|title=Named Arguments|url=https://docs.scala-lang.org/tour/named-arguments.html|access-date=2021-06-16|website=Scala Documentation}}</ref> [[Smalltalk]]{{Citation needed|date=July 2021}}, [[Swift (programming language)|Swift]]<ref>{{Cite web|url=https://docs.swift.org/swift-book/LanguageGuide/Functions.html#ID166|title=Functions |website=The Swift Programming Language (Swift 5.1) |access-date=2020-01-27}}</ref> and [[Visual Basic]].<ref>{{Cite web|last=KathleenDollard|title=Passing Arguments by Position and by Name - Visual Basic|url=https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/passing-arguments-by-position-and-by-name|access-date=2021-06-16|website=Microsoft Learn|language=en-us}}</ref> [[Objective-C]] does not have named parameters (even though parts of the method name may look like named parameters).<ref>''[https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/DefiningClasses/DefiningClasses.html#//apple_ref/doc/uid/TP40011210-CH3-SW5|iOS Developer Library - The Implementation of a Class Provides Its Internal Behavior]''</ref> <br>In [[C++]], you can achieve named parameters by using designated initializers since [[C++20]],<ref>{{Cite web|url=https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0329r4.pdf|title=Designated Initialization Wording}}</ref> like so: <syntaxhighlight lang="cpp"> struct A {int a{}, int b{} }; void foo(A bar) { std::cout << bar.a << bar.b; } foo({ .a = 1, .b = 3 }); </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)