Lars Kyllingstad wrote:
Jason House wrote:
downs Wrote:

Let me say first that I don't use std.bind myself, but tools.base:fix
fills essentially the same need - creating full closures from dynamic
ones.

Say you have a function that takes a number and returns a delegate
that does something with that number.

void delegate() test(int i) { return { return i + 2; }; }

In 2.0 this will ......................

Oh.

Nevermind. I don't know what to use bind for after all :)

In fact, I suspect it's essentially useless in 2.0. Creating full
closures was my only use case :)

I look at bind as the difference between by reference and by value
semantics. When using scope delegates (or delegates that could be
scope delegates), this difference rarely matters. When passing data
between threads, the need to pass by value becomes more important. "By
value" may even require a deep copy.

Even though I can see uses for some kind of bind functionality in D2,
I need to see where all this "shared" object stuff goes before I know
what/if a D2 bind library should do.

I've always thought currying was the main point of std.bind. If I'm not
mistaken, currying is commonly a built-in feature of functional
programming languages, so if anything, std.bind could become more
useful/important in D2 than in D1.

I agree that the std.bind API could and should be improved.

-Lars

you don't need bind for currying, it's even possible to do this in C:

int foo(int a, int b) { ... }
int bar(int a) { return foo(a, _value); } // curry with some _value

Other languages provide useful syntax sugar for currying:
auto bar2 = foo(_, 500);

bar2 here will be a delegate that will do the the same as the above bar.

Reply via email to