Re: function is not callable using argument types ()

2016-12-12 Thread Bauss via Digitalmars-d-learn

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


Re: function is not callable using argument types ()

2016-12-10 Thread Stefan Koch via Digitalmars-d-learn

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.


function is not callable using argument types ()

2016-12-10 Thread Suliman via Digitalmars-d-learn

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?







function ... is not callable using argument types

2015-01-01 Thread Suliman via Digitalmars-d-learn


 I need to pass some config to ddbc driver. When I use static 
const all work ok.

static const string PGSQL_UNITTEST_HOST = localhost;
static const intPGSQL_UNITTEST_PORT = 5432;
static const string PGSQL_UNITTEST_USER = postgres;
static const string PGSQL_UNITTEST_PASSWORD = Infinity8;
static const string PGSQL_UNITTEST_DB = test2;

But using static const mean that settings will be hardcoded. But 
I need to read it from config file.


So I need so simply declared it as:

this(parseConfig parseconfig)
{

string PGSQL_UNITTEST_HOST = parseconfig.dbhost;
intPGSQL_UNITTEST_PORT = parseconfig.dbport;
string PGSQL_UNITTEST_USER = parseconfig.dbuser;
string PGSQL_UNITTEST_PASSWORD = parseconfig.dbpass;
string PGSQL_UNITTEST_DB = parseconfig.dbname;
...
}

But when I do it like above code stop compile and I am getting 
error:


source\app.d(218): Error: function 
ddbc.drivers.pgsqlddbc.PGSQLDriver.generateUrl (string host, 
ushort port, string dbname) is not callable using argument types  
(string, int, string)


I looked at driver source code and have found next code:

class PGSQLDriver : Driver {
// helper function
	public static string generateUrl(string host, ushort port, 
string dbname) {
		return postgresql:// ~ host ~ : ~ to!string(port) ~ / 
~ dbname;

}
	public static string[string] setUserAndPassword(string 
username, string password) {

string[string] params;
params[user] = username;
params[password] = password;
params[ssl] = true;
return params;
}

So it's look like that it can accept strings and ints without 
problem.


And I really can't understand why it's accept only static const 
string constructions...




Re: function ... is not callable using argument types

2015-01-01 Thread Tobias Pankrath via Digitalmars-d-learn

On Thursday, 1 January 2015 at 13:09:21 UTC, Suliman wrote:

But why variant:
static const int PGSQL_UNITTEST_PORT = 5432;

do not require of implicit convert to!short() at connection 
string?


As I said the compiler infers that 5432 is between short.min and 
short.max. Try it with something out of this range.


BTW: If you just want to have a global constant, I'd use enum or 
immutable:


enum PGSQL_UNITTEST_PORT = 5432;
immutable PGSQL_UNITTEST_PORT = 5432;


Re: function ... is not callable using argument types

2015-01-01 Thread Tobias Pankrath via Digitalmars-d-learn




So it's look like that it can accept strings and ints without 
problem.


And I really can't understand why it's accept only static 
const string constructions...




int does not implicitly convert to short. It does in the 
hardcoded version, because the compiler can prove that the value 
is between short.min and short.max.


Use to!short() to convert it to short.


Re: function ... is not callable using argument types

2015-01-01 Thread Suliman via Digitalmars-d-learn

But why variant:
static const int PGSQL_UNITTEST_PORT = 5432;

do not require of implicit convert to!short() at connection 
string?


Re: function ... is not callable using argument types

2015-01-01 Thread bearophile via Digitalmars-d-learn

Suliman:


But why variant:
static const int PGSQL_UNITTEST_PORT = 5432;

do not require of implicit convert to!short() at connection 
string?


Because value range analysis now propagates the range even across 
expressions if they are const. It's a recent improvement to make 
the D compile a bit less stupid.


Bye,
bearophile


Re: function ... is not callable using argument types

2015-01-01 Thread Ali Çehreli via Digitalmars-d-learn

On 01/01/2015 05:09 AM, Suliman wrote:

But why variant:
static const int PGSQL_UNITTEST_PORT = 5432;

do not require of implicit convert to!short() at connection string?


Walter Bright explains the reasons in his Value Range Propagation article:

  http://www.drdobbs.com/tools/value-range-propagation/229300211

Ali