4

In the language nim, one can do the following thing:

let num = 5.add(3)

which would be the same as

let num = add(5,3)

So, basically you take the expression before the dot as the first argument to the function. I'm sure other languages have this feature, but none directly came to mind.

What I want to know is what name this syntax has

Dirk
  • 2,094
  • 3
  • 25
  • 28
  • It looks like Object-Oriented syntax. Most languages don't let you switch back and forth like this, you have to use one or the other depending on the type of function. – Barmar Dec 22 '14 at 18:14
  • Yes, it looks like it, but it isn't. This syntax can be used on any function, not just methods – Dirk Dec 22 '14 at 18:15
  • I'd say it was just using a "method declared in the type definition" (quoting from the following link). If you created your own which behaved like that, it would be called an [extension method](http://en.wikipedia.org/wiki/Extension_method) in C# and VB. – Andrew Morton Dec 22 '14 at 18:34

3 Answers3

7

In D lang this syntax is called Uniform Function Call Syntax (UFCS).

6

The manual says it's the method call syntax. It also mentions dot operators.

Grzegorz Adam Hankiewicz
  • 7,349
  • 1
  • 36
  • 78
0

TL;DR - Unified [Function] Call Syntax, or whatever you like, because there's no stable widely accepted term for that in software engineering.

The concern is based on the info about programming languages that somehow implement this feature:

  1. C++: The most generic name for the feature is possibly Unified Call Syntax as defined by Herb Sutter at open-std.org paper in cooperation with Bjarne Stroustrup as a possible new feature for further C++ standards.
  2. D2: In D language, and also in and RFC for the Rust Language it is called UFCS (Unified Function Call Syntax).
  3. MATLAB: In MATLAB they don't use any specific naming for the fact methods can be called either via function notation or via '.' (dot) syntax.
Rostyslav Dzinko
  • 39,424
  • 5
  • 49
  • 62