Bug 1541 – std.bind is broken?

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2007-09-29T18:44:00Z
Last change time
2015-06-09T01:21:00Z
Keywords
patch
Assigned to
bugzilla
Creator
rayerd.wiz

Attachments

IDFilenameSummaryContent-TypeSize
188bind_dmd2004.patchFor std.bind in dmd2.004text/plain2299
195dmd2.006_src_phobos_std_bind.d.patchFixed std.bind for dmd2.006text/plain2299
283std_bind_for_dmd2022.txtFixed std.bind for dmd2.023 within limitationstext/plain11389

Comments

Comment #0 by rayerd.wiz — 2007-09-29T18:44:07Z
import std.bind, std.stdio; bool less(int a, int b) { return a < b; } void main() { writefln("10 < 20 =? ", less(10, 20)); auto less10 = bind(&less, _0, 10); writefln(" 5 < 10 =? ", less10(5)); } >dmd a.d C:\D\dmd\bin\..\src\phobos\std\bind.d(839): declaration _D3std4bind9EmptySlot6__ initZ forward declaration -- Thank you for your works!
Comment #1 by rayerd.wiz — 2007-10-03T06:57:25Z
Hi. I propose to apply a patch to "dmd\src\phobos\std\bind.d" file for this problem. --- bind.d Wed Oct 03 20:39:18 2007 +++ ~bind.d Wed Oct 03 20:38:20 2007 @@ -263,7 +263,7 @@ } - string toString() { + char[] toString() { return "()"; } } @@ -657,7 +657,7 @@ bind(&foo, tuple(23, 45)) --- */ -typeof(new BoundFunc!(FT, EmptySlot, Tuple!(ArgList))) bind(FT, ArgList...)(FT fp, ArgList args) { +typeof(new BoundFunc!(FT, NullAlias, Tuple!(ArgList))) bind(FT, ArgList...)(FT fp, ArgList args) { auto res = new DerefFunc!(ReturnType!(bind)); res.fp = fp; extractBoundArgs!(0, 0, ArgList)(res.boundArgs, args); ========= main.d for experimental code import std.stdio, std.bind; void main() { writefln("-less"); bool less(int a, int b){return a<b;} auto less5 = bind(&less, _0, 5); foreach (i; 0..7) { writefln(i, "<5 ", less5(i)); } writefln("-greater"); auto greater = bind(&less, _1, _0); auto greater3 = bind(greater.ptr, _0, 3); foreach (i; 0..7) { writefln(i, ">3 ", greater3(i)); } } ============= >dmd main C:\D\dmd\bin\..\..\dm\bin\link.exe main,,,user32+kernel32/noi; >main -less 0<5 true 1<5 true 2<5 true 3<5 true 4<5 true 5<5 false 6<5 false -greater 0>3 false 1>3 false 2>3 false 3>3 false 4>3 true 5>3 true 6>3 true
Comment #2 by rayerd.wiz — 2007-10-04T06:02:22Z
Created attachment 188 For std.bind in dmd2.004 Hi. I am Haruki Shigemori. Because I fixed std.bind for dmd2.004, please apply this patch to bind.d! ========================================= I:\D\projects\bind>type main.d import std.stdio, std.bind; void main() { writefln("-less (bind)"); bool less(int a, int b){return a<b;} auto less5 = bind(&less, _0, 5); foreach (i; 0..7) { writefln(i, "<5 ", less5(i)); } writefln("-greater (bind)"); auto greater = bind(&less, _1, _0); auto greater3 = bind(greater.ptr, _0, 3); foreach (i; 0..7) { writefln(i, ">3 ", greater3(i)); } writefln("-less (bindAlias)"); auto less2 = bindAlias!(less)(_0, 2); foreach (i; 0..7) { writefln(i, "<2 ", less2(i)); } writefln("-greater (bindAlias)"); auto greater4 = bindAlias!(greater)(_0, 4); foreach (i; 0..7) { writefln(i, ">4 ", greater4(i)); } writefln("-function composition"); int foo(int i) {return i*2;} int bar(int i) {return i*3;} auto fooBar = bind(&foo, bind(&bar, _0)); writefln(fooBar(5)); } I:\D\projects\bind>dmd main C:\D\dmd\bin\..\..\dm\bin\link.exe main,,,user32+kernel32/noi; I:\D\projects\bind>main -less (bind) 0<5 true 1<5 true 2<5 true 3<5 true 4<5 true 5<5 false 6<5 false -greater (bind) 0>3 false 1>3 false 2>3 false 3>3 false 4>3 true 5>3 true 6>3 true -less (bindAlias) 0<2 true 1<2 true 2<2 false 3<2 false 4<2 false 5<2 false 6<2 false -greater (bindAlias) 0>4 false 1>4 false 2>4 false 3>4 false 4>4 false 5>4 true 6>4 true -function composition 30
Comment #3 by rayerd.wiz — 2007-10-17T08:02:06Z
Created attachment 195 Fixed std.bind for dmd2.006
Comment #4 by bugzilla — 2008-12-09T14:11:27Z
When I apply the patches then try compiling the example code, I get: std\bind.d(991): Error: EmptySlot is not an lvalue
Comment #5 by rayerd.wiz — 2008-12-18T13:22:23Z
Created attachment 283 Fixed std.bind for dmd2.023 within limitations import std.stdio, std.bind; void main() { writefln("(bind(&less, _0, 5))"); bool less(int a, int b){return a<b;} auto less5 = bind(&less, _0, 5); for (int i=0; i<7; ++i) { writefln(i, "<5 ", less5(i)); } writefln("(bind(&less, 5, _0))"); auto not_less5 = bind(&less, 5, _0); for (int i=0; i<7; ++i) { writefln(i, ">=6 ", not_less5(i)); } writefln("(bind(&less, 3, 5))"); auto less_3_5 = bind(&less, 3, 5); writefln("3<5 ", less_3_5()); writefln("(bind(&less, 5, 3))"); auto less_5_3 = bind(&less, 5, 3); writefln("5<3 ", less_5_3()); writefln("(bind(bind(&less, _1, _0).ptr, _0, 3)"); auto greater = bind(&less, _1, _0); auto greater3 = bind(greater.ptr, _0, 3); for (int i=0; i<7; ++i) { writefln(i, ">3 ", greater3(i)); } writefln("(bindAlias!(less)(_0, 2))"); auto less2 = bindAlias!(less)(_0, 2); for (int i=0; i<7; ++i) { writefln(i, "<2 ", less2(i)); } writefln("(bind(&foo, bind(&bar, _0)))"); int foo(int i) {return i*2;} int bar(int i) {return i*3;} auto fooBar = bind(&foo, bind(&bar, _0)); writefln(fooBar(5)); // // Limitations // // writefln("(bindAlias!(greater)(_0, 4))"); // auto greater4 = bindAlias!(greater)(_0, 4); // for (int i=0; i<7; ++i) // { // writefln(i, ">4 ", greater4(i)); // } // auto fooFooBar = bindAlias!(foo)(bindAlias!(fooBar)(_0)); // auto fooFooBar = bindAlias!(foo)(bind(fooBar.ptr, _0)); // writefln(fooFooBar(5)); } I:\bind_repair>main (bind(&less, _0, 5)) 0<5 true 1<5 true 2<5 true 3<5 true 4<5 true 5<5 false 6<5 false (bind(&less, 5, _0)) 0>=6 false 1>=6 false 2>=6 false 3>=6 false 4>=6 false 5>=6 false 6>=6 true (bind(&less, 3, 5)) 3<5 true (bind(&less, 5, 3)) 5<3 false (bind(bind(&less, _1, _0).ptr, _0, 3) 0>3 false 1>3 false 2>3 false 3>3 false 4>3 true 5>3 true 6>3 true (bindAlias!(less)(_0, 2)) 0<2 true 1<2 true 2<2 false 3<2 false 4<2 false 5<2 false 6<2 false (bind(&foo, bind(&bar, _0))) 30
Comment #6 by rayerd.wiz — 2009-01-22T10:13:44Z
*** Bug 2602 has been marked as a duplicate of this bug. ***
Comment #7 by andrei — 2011-01-08T14:34:46Z
std.bind has been eliminated from Phobos. Sorry, Haruki!
Comment #8 by rayerd.wiz — 2011-01-08T15:52:00Z
(In reply to comment #7) > std.bind has been eliminated from Phobos. Sorry, Haruki! Don't worry, we have closure. std.bind is already unnecessary one!
Comment #9 by andrei — 2011-01-08T16:06:54Z
Thanks, Haruki - looking forward to other contributions!