Created attachment 1587
Example of error using partial with delegate reference
Trying to use "partial" from "std.function" with a variable referring to a function or delegate does not behave as expected. See "example_error.d" for unexpected behaviour.
ketmar, on #d observed that the issue is either with DMD or with phobos:
either `is(typeof(basic) == function)` should be true there (and then it's dmdfe bug), or `partial` should use `isCallable` (and then it's phobos bug)
He was able to provide a fix with the following:
i changed `static if (is(typeof(fun) == delegate) || is(typeof(fun) == function))` line in `partial` to `static if (isCallable!fun)`
Which I will attach as an example.
Comment #1 by abc.mikey — 2016-02-27T14:05:03Z
Created attachment 1588
Examle of "fixed" partial
Comment #2 by abc.mikey — 2016-02-27T14:17:11Z
Example of error:
auto partial_application () {
// definition of a basic function on 3 parameters using lambda syntax
auto basic = (float a, float b, float c) => a + b / c;
// partially apply value to basic
import std.functional : partial;
alias partial!(basic, 1) apply1;
return &apply1;
// Error: partial(Ts...)(Ts args2) is not an lvalue
}
void main(string[] args) {
auto test = partial_application();
import std.stdio : writeln;
writeln("result: ", test(1, 2, 3));
}
Comment #3 by petar.p.kirov — 2018-08-24T14:10:28Z
Since the https://github.com/dlang/phobos/pull/6497 was merged, a fixed version of the example above compiles:
auto partial_application () {
// definition of a basic function on 3 parameters using lambda syntax
auto basic = (float a, float b, float c) => a + b / c;
// partially apply value to basic
import std.functional : partial;
alias partial!(basic, 1) apply1;
return &apply1; // now OK, didn't compile before
}
void main(string[] args) {
auto test = partial_application();
import std.stdio : writeln;
writeln("result: ", test(2, 3)); // 1 + (2/3) = 1.66667
}
I see no reason why the GitHub -> Bugzilla integration didn't close the issue automatically, so I'm closing it manually.
Comment #4 by johannes.loher — 2018-08-26T09:04:45Z
It seems, this was not actually closed. Closing it now.