www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - function is not callable using argument types ()

reply Suliman <evermind live.ru> writes:
import std.stdio;
import std.concurrency;

void main()
{

void sp(int i)
{
	receive((int i)
	{
		writeln("i: ", i);
	});
}

	auto r = new Generator!int(
	{
		foreach(i; 1 .. 10)
			yield(i);
	});

	foreach(e;r)
	{
		sp.send(e); //Error: function app.main.sp (int i) is not 
callable using argument types ()
	}

}


What I am doing wrong? How "receive" can be named? Is it's method 
or what? Why it's without return type?
Dec 10 2016
next sibling parent Stefan Koch <uplink.coder googlemail.com> writes:
On Saturday, 10 December 2016 at 08:41:56 UTC, Suliman wrote:
 import std.stdio;
 import std.concurrency;

 void main()
 {

 void sp(int i)
 {
 	receive((int i)
 	{
 		writeln("i: ", i);
 	});
 }

 	auto r = new Generator!int(
 	{
 		foreach(i; 1 .. 10)
 			yield(i);
 	});

 	foreach(e;r)
 	{
 		sp.send(e); //Error: function app.main.sp (int i) is not 
 callable using argument types ()
 	}

 }


 What I am doing wrong? How "receive" can be named? Is it's 
 method or what? Why it's without return type?
Sp is not in global scope but defined in main. Therefore it does not participate in UFCS.
Dec 10 2016
prev sibling parent Bauss <jj_1337 live.dk> writes:
On Saturday, 10 December 2016 at 08:41:56 UTC, Suliman wrote:
 import std.stdio;
 import std.concurrency;

 void main()
 {

 void sp(int i)
 {
 	receive((int i)
 	{
 		writeln("i: ", i);
 	});
 }

 	auto r = new Generator!int(
 	{
 		foreach(i; 1 .. 10)
 			yield(i);
 	});

 	foreach(e;r)
 	{
 		sp.send(e); //Error: function app.main.sp (int i) is not 
 callable using argument types ()
 	}

 }


 What I am doing wrong? How "receive" can be named? Is it's 
 method or what? Why it's without return type?
Read: https://dlang.org/spec/function.html#pseudo-member
Dec 12 2016