Uniform function call syntax: Difference between revisions

Content deleted Content added
Tags: Mobile edit Mobile web edit
Uniform function call syntax was already mentioned
 
Line 1:
{{Short description|Programming language feature}}
'''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> 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 |title=Functions |url=https://effekt-lang.org/tour/functions |access-date=2025-04-09 |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 |website=D Programming Language |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 |website=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=Universal Function Call Syntax (UFCS) |website=Programming in D |accessdate=1 October 2017}}</ref> (behaving similar to [[Pipe (computer science)|pipes]], or the various dedicated [[Operator (computer programming)|operators]] available in [[functional language]]s for passing values through a series of [[Expression (computer science)|expressions]]). 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]].