On Saturday, 2 June 2018 at 22:01:02 UTC, Ali Çehreli wrote:
On 06/02/2018 02:44 PM, greatsam4sure wrote:

> is it possible to define infix function in D
>
> 3.min(5)// 3: where min is a function, works in D
> 3 min 5 // does not work.

This is called universal function call syntax (UFCS) in D. The idea is simple: You can pull the first argument out as if the function is a member function of that argument. So, in your case it already works because there is already a min() function that works with two (actually, many) parameters:

import std.algorithm;

void main() {
    assert(min(3, 5) == 3);
    assert(3.min(5) == 3);
}

However, many people don't like overusing it; it works well only in cases where the first parameter is arguably the "main character" in the operation. For example, min doesn't look good because all parameters have equal roles in that function.

Ali

Thanks for your reply to my question.
Your book: programming in D is real a great help learning D. I will appreciate it if your can expand the book to advance use of D. That is, dealing with D advance use Case. I discover that the D language is very advance but I am lock in the elementary yet don't know the way out. This is because D is the most Higher programming language that I ever use. Better still you can direct me to more materials about D. I am already familiar will all D books.

thanks

Reply via email to