Safer casts
Janice Caron
caron800 at googlemail.com
Tue May 13 02:24:01 PDT 2008
2008/5/13 Yigal Chripun <yigal100 at gmail.com>:
> the main thing for me is the syntax:
> look at Nemerle, for example.
> Here's a snippet:
>
> class MoreFunctions {
> static run_twice (f : int -> int, v : int) : int
> {
> f (f (v))
> }
>
> static run_adder (x : int) : void
> {
> def f (y : int) : int { x + y }; // <==== this is a nested function
> System.Console.WriteLine ("{0}", run_twice (f, 1))
> }
>
> public static Run () : void
> {
> run_adder (1);
> run_adder (2);
> }
> }
And the same thing in D:
class MoreFunctions
{
static run_twice!(alias f)(int v)
{
f(f(v))
}
static run_adder (x : int) : void
{
int f(int y) { return x + y; };
writefln("{0}", run_twice!(f)(1))
}
void main()
{
run_adder(1);
run_adder(2);
}
}
What's your point?
More information about the Digitalmars-d
mailing list