Uniform function call syntax: Difference between revisions

Content deleted Content added
C++ proposal: dab link
Kepexx (talk | contribs)
added Rust as it's a well known language with UFCS
Tags: Reverted Visual edit
Line 1:
'''Uniform Function Call Syntax''' ('''UFCS''') or '''Uniform Call Syntax''' ('''UCS''') or sometimes '''Universal Function Call Syntax''' is a [[programming language]] feature in [[D (programming language)|D]],<ref name=":0" /> [[Nim (programming language)|Nim]],<ref>{{Cite web |title=Nim by Example - Procs |url=https://nim-by-example.github.io/procs/ |access-date=2024-05-19 |website=nim-by-example.github.io}}</ref> [[Rust (programming language)|Rust]],<ref>{{Cite web |title=Call expressions - The Rust Reference |url=https://doc.rust-lang.org/reference/expressions/call-expr.html#disambiguating-function-calls |access-date=2024-09-22 |website=doc.rust-lang.org}}</ref> Koka,<ref>{{Cite web |title=The Koka Programming Language |url=https://koka-lang.github.io/koka/doc/book.html |access-date=2024-05-19 |website=koka-lang.github.io}}</ref> and Effekt<ref>{{Cite web |last= |first= |title=Effekt Language: Introduction to Effekt |url=https://effekt-lang.org/docs/#function-application |access-date=2024-05-19 |website=Effekt Language}}</ref> that allows any [[function (computer programming)|function]] to be called using the syntax for method calls (as in [[object-oriented programming]]), by using the receiver as the first parameter and the given arguments as the remaining parameters.<ref>{{cite web|url=http://dlang.org/function.html#pseudo-member|title=Functions - D Programming Language|website=Dlang.org|accessdate=1 October 2017}}</ref> The same technique is used in the [[AviSynth]] scripting language under the name "OOP notation".<ref>{{cite web|title=Operators - Avisynth wiki|url=http://avisynth.nl/index.php/Operators#Operator_Precedence|quote=<code>a.function(b)</code> is equivalent to <code>function(a, b)</code>}}</ref>
 
UFCS is particularly useful when function calls are chained<ref name=":0">{{cite web|url=http://ddili.org/ders/d.en/ufcs.html|title=Programming in D - Universal Function Call Syntax (UFCS)|website=Ddili.org|accessdate=1 October 2017}}</ref> (behaving similar to [[Pipe (computer science)|pipe]]s, or the various dedicated [[Operator (computer programming)|operator]]s available in [[functional language]]s for passing values through a series of [[Expression (computer science)|expression]]s). It allows free-functions to fill a role similar to [[extension method]]s in some other languages. Another benefit of the syntax is related to completion systems in [[Integrated development environment|IDEs]], which use type information to show a list of available functions, dependent on the context. When the programmer starts with an argument, the set of potentially applicable functions is greatly narrowed down,<ref name="auto">{{cite web|title="Unified Call Syntax"|url=https://isocpp.org/files/papers/N4165.pdf|website=Isocpp.org|accessdate=1 October 2017}}</ref> aiding [[discoverability]].