Jump to page: 1 2
Thread overview
D doesn't have real closures
Sep 11, 2007
Brad Anderson
Sep 11, 2007
0ffh
Sep 12, 2007
Brad Anderson
Sep 12, 2007
0ffh
Sep 12, 2007
Walter Bright
Sep 13, 2007
Walter Bright
Sep 13, 2007
Russell Lewis
Sep 13, 2007
BCS
Sep 13, 2007
Russell Lewis
Sep 13, 2007
Guillaume B.
September 11, 2007
http://www.hans-eric.com/2007/09/11/d-doesnt-have-real-closures/

Please digg and reddit.

BA
September 11, 2007
Brad Anderson wrote:
> http://www.hans-eric.com/2007/09/11/d-doesnt-have-real-closures/
> 
> Please digg and reddit.
> 
> BA

You want multicast?

Well, for multicast functions (with one parameter) it seems to be
rather straightforward template programming:

---<snip>---
module multicastFunctions;

template mcf(T)
{
  class mcf
  {
    void function(T) fun;
    mcf next;

    void opCall(T x)
    {
      fun(x);
      if (next !is null)
        next(x);
    }

    mcf opCat(mcf n)
    {
      mcf m=this.dup();
      m.next=n.dup();
      return m;
    }

    mcf dup()
    {
      return new mcf(this);
    }

    this(mcf m)
    {
      this(m.fun,m.next);
    }

    this(void function(T) d,mcf n=null)
    {
      fun=d;
      next=n;
    }
  }
}

void fa(int x)
{
  printf("fa(%i)\n",x);
}

void fb(int x)
{
  printf("fb(%i)\n",x);
}

void main()
{
  mcf!(int) a=new mcf!(int)(&fa);
  mcf!(int) b=new mcf!(int)(&fb);
  mcf!(int) c=a~b;
  a(1);
  b(2);
  c(3);
}
---<snap>---

I am sure with all the templating wizzards floating around here
someone can come up with something that is not quite as full of
crap as my little proof of concept code, probably with multiple
parameter feature and whatnot; dirty and obvious hack for multi
parm would be to have N copies of the template for 0..N-1 parms.

Look ma, no C#!

Regards, Frank
September 11, 2007
"0ffh" <spam@frankhirsch.net> wrote in message news:fc6mea$4d8$1@digitalmars.com...
> Brad Anderson wrote:
> I am sure with all the templating wizzards floating around here
> someone can come up with something that is not quite as full of
> crap as my little proof of concept code, probably with multiple
> parameter feature and whatnot; dirty and obvious hack for multi
> parm would be to have N copies of the template for 0..N-1 parms.

Oh please, D has variadic templates :D  That, and I'd expect something like this to be a value type.

struct MCD(Args...)
{
    void function(Args)[] funcs;

    void opCatAssign(void function(Args) f)
    {
        funcs ~= f;
    }

    void opCall(Args args)
    {
        foreach(f; funcs)
            f(args);
    }
}

void fa(int x)
{
    Stdout.formatln("fa({})", x);
}

void fb(int x)
{
    Stdout.formatln("fb({})", x);
}

void main()
{
    MCD!(int) a;
    a ~= &fa;
    a ~= &fb;
    a(3);
}


September 12, 2007
Brad Anderson wrote:
> http://www.hans-eric.com/2007/09/11/d-doesnt-have-real-closures/
> 
> Please digg and reddit.
> 
> BA

Reddit:

http://programming.reddit.com/info/2o4we/comments

Digg:

http://www.digg.com/programming/D_doesn_t_have_real_closures
September 12, 2007
Jarrett Billingsley wrote:
>> Brad Anderson wrote:
>> I am sure with all the templating wizzards floating around here
>> someone can come up with something that is not quite as full of
>> crap as my little proof of concept code, probably with multiple
>> parameter feature and whatnot; dirty and obvious hack for multi
>> parm would be to have N copies of the template for 0..N-1 parms.
> 
> Oh please, D has variadic templates :D  That, and I'd expect something like this to be a value type.

It is quoted a bit like I wrote this blog post, but I did not.  I'm just the marketing guy here.

BA
September 12, 2007
Brad Anderson wrote:
> It is quoted a bit like I wrote this blog post, but I did not.  I'm just
> the marketing guy here.

Ups, sorry, my mistake!

Regards, Frank
September 12, 2007
"Brad Anderson" <brad@dsource.org> wrote in message news:fc7kh6$1jin$1@digitalmars.com...

> Jarrett Billingsley wrote:
>>> Brad Anderson wrote:
>>> I am sure with all the templating wizzards floating around here
>
> It is quoted a bit like I wrote this blog post, but I did not.  I'm just the marketing guy here.

Oops, misquote there.  Should've been 0ffh.


September 13, 2007
Brad Anderson wrote:
> http://www.hans-eric.com/2007/09/11/d-doesnt-have-real-closures/

I've posted a response on my blog:

http://jcesar.totumo.net/2007/09/13/d-should-have-real-closures/

Comments?

Thanks
September 13, 2007
Julio César Carrascal Urquijo wrote:
> Brad Anderson wrote:
>> http://www.hans-eric.com/2007/09/11/d-doesnt-have-real-closures/
> 
> I've posted a response on my blog:
> 
> http://jcesar.totumo.net/2007/09/13/d-should-have-real-closures/
> 
> Comments?
> 
> Thanks

On reddit:

http://programming.reddit.com/new
September 13, 2007
Walter Bright wrote:
> On reddit:
> 
> http://programming.reddit.com/new

Thank you for posting it. Here's the direct link:

http://programming.reddit.com/info/2oyuz/comments
« First   ‹ Prev
1 2