19 Oct
2006
19 Oct
'06
12:27 p.m.
Chris Weed wrote:
Hi, I can get the following code to compile and it prints 3 2 5 but I don't quite understand why it doesn't print 2 3 5 or how to get it to do so. I thought since it is binding 2 to _1, this would bind it to the a argument.
Calling bind( fx, _1, 2 ) with 3 will put the '3' in the _1 and pass the 2 intact, the result is fx( 3, 2 ). bind( fx, _1, _1 ) will call fx( 3, 3 ). bind( fx, 2, _1 ) calls fx( 2, 3 ). bind( fx, 4, 5 ) calls fx( 4, 5 ). Does it make sense now? bind is not an interpreter with a mini-language ("bind the second argument to 2"), you just pass the argument values, and _1 is substituted with the first input argument (3 in your case).