Open twesterhout opened 3 years ago
hi @twesterhout thanks for the bug report. First class functions/lambdas are more of a prototype in Chapel today and need some more attention to arrive at a stable language design point. Related to that, the implementation is not complete. (Issue #8351 tracks the shortcomings of the current implementation).
The documentation we do have is available here -- https://chapel-lang.org/docs/main/technotes/firstClassFns.html -- and this documentation points out that we don't currently support capturing a generic function/lambda.
So here is an example that is inspired by your bug report but that compiles and runs today. It makes two changes:
config var isHammingWeightFixed: bool = true;
var projFn: func(int, int);
if isHammingWeightFixed {
projFn = lambda(x:int) { return x; };
} else {
projFn = lambda(x:int) { return x+1; };
}
writeln(projFn(1));
Please let us know if this workaround is sufficient for what you are doing.
Hello @mppf, sorry for the delay. I've tried out your workaround and it seems to work for my use case, thanks! Somehow I missed this part and thought that variables of function type can never be declared, only deduced.
@twesterhout - no worries, thanks for getting back to me. Since you have a workaround & there are other issues to fix with first-class functions, I'm expecting that we'll put off fixing this issue (probably until we have a more concentrated effort on fixing up the first class function support).
until we have a more concentrated effort on fixing up the first class function support
Which may get attention during this upcoming release cycle. We're currently starting to kick around priorities and resourcing.
Summary of Problem
The compiler crashes with internal error:
Steps to Reproduce
Source Code:
Compile command:
chpl -o error error.chpl
Configuration Information
chpl --version
: 1.24.1$CHPL_HOME/util/printchplenv --anonymize
:gcc --version
orclang --version
: gcc 10.3.0module list
: