www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - extreme curring (proposal)

reply Thorsten <thorstenkiefer gmx.de> writes:
Hi, at the moment it is not possible, but it wold be nice to have in the future.
(But maybe not very necessary)

R delegate(U) Curry1(R,X...,U...)(R delegate(X,U) dg,X args)
{
	struct Foo
	{
		typeof(dg) dg_m;
		X args_m;
		
		R bar(U xs)
		{
			return dg_m(args_m,xs);
		}
	}
	
	Foo* f = new Foo;
	f.dg_m = dg;
	foreach (i, arg; args)
		f.args_m[i] = arg;
	
	return &f.bar;
}

I know that "double variadic template arguments" are not possible with the
current version, right ?
Mar 03 2007
parent reply Tom S <h3r3tic remove.mat.uni.torun.pl> writes:
Thorsten wrote:
 Hi, at the moment it is not possible, but it wold be nice to have in the
future.
 (But maybe not very necessary)
 
 R delegate(U) Curry1(R,X...,U...)(R delegate(X,U) dg,X args)
 {
 	struct Foo
 	{
 		typeof(dg) dg_m;
 		X args_m;
 		
 		R bar(U xs)
 		{
 			return dg_m(args_m,xs);
 		}
 	}
 	
 	Foo* f = new Foo;
 	f.dg_m = dg;
 	foreach (i, arg; args)
 		f.args_m[i] = arg;
 	
 	return &f.bar;
 }
 
 I know that "double variadic template arguments" are not possible with the
current version, right ?
 
You could try std.bind : http://digitalmars.com/d/phobos/std_bind.html Examples in the independent package: http://www-users.mat.uni.torun.pl/~h3r3tic/bind2.zip -- Tomasz Stachowiak
Mar 03 2007
next sibling parent Thorsten <thorstenkiefer gmx.de> writes:
Tom S Wrote:

 Thorsten wrote:
 Hi, at the moment it is not possible, but it wold be nice to have in the
future.
 (But maybe not very necessary)
 
 R delegate(U) Curry1(R,X...,U...)(R delegate(X,U) dg,X args)
 {
 	struct Foo
 	{
 		typeof(dg) dg_m;
 		X args_m;
 		
 		R bar(U xs)
 		{
 			return dg_m(args_m,xs);
 		}
 	}
 	
 	Foo* f = new Foo;
 	f.dg_m = dg;
 	foreach (i, arg; args)
 		f.args_m[i] = arg;
 	
 	return &f.bar;
 }
 
 I know that "double variadic template arguments" are not possible with the
current version, right ?
 
You could try std.bind : http://digitalmars.com/d/phobos/std_bind.html Examples in the independent package: http://www-users.mat.uni.torun.pl/~h3r3tic/bind2.zip -- Tomasz Stachowiak
Yea OK, that seems much more powerful than my approach. Thanks !!
Mar 03 2007
prev sibling parent Thorsten <thorstenkiefer gmx.de> writes:
Tom S Wrote:

 Thorsten wrote:
 Hi, at the moment it is not possible, but it wold be nice to have in the
future.
 (But maybe not very necessary)
 
 R delegate(U) Curry1(R,X...,U...)(R delegate(X,U) dg,X args)
 {
 	struct Foo
 	{
 		typeof(dg) dg_m;
 		X args_m;
 		
 		R bar(U xs)
 		{
 			return dg_m(args_m,xs);
 		}
 	}
 	
 	Foo* f = new Foo;
 	f.dg_m = dg;
 	foreach (i, arg; args)
 		f.args_m[i] = arg;
 	
 	return &f.bar;
 }
 
 I know that "double variadic template arguments" are not possible with the
current version, right ?
 
You could try std.bind : http://digitalmars.com/d/phobos/std_bind.html Examples in the independent package: http://www-users.mat.uni.torun.pl/~h3r3tic/bind2.zip -- Tomasz Stachowiak
By the way there is an error on the http://digitalmars.com/d/phobos/phobos.html web page. Because when you click an std.bind, you are sent to http://digitalmars.com/d/phobos/std_bind, which is not available.
Mar 03 2007