function foo()
errmsg("foo called");
end;
function fooCaller(fooResult)
//!!!if fooCaller() has no instructions here, fooResult is never evaluated and thus foo() is never called
end;
PROC SOME_PROC
//!!!error message in foo() not shown when calling fooCaller()
fooCaller(foo());
This probably was there since ISSA. It always amazes me how after 20+ years working with CSPro, I still find these quirks
Wow, that is a quirk! Without even looking at the C++ code, I know that it's true that if a function has no body, that the arguments aren't evaluated. I'll change that for CSPro 8.1.
or just lean into lazy evaluation and don't evaluate any expressions until they are used. The set of CSPro users who also program in Haskell will be forever grateful
Wouldn't foo() expression still be evaluated in this case even with lazy evaluation? fooResult is not a pointer to foo() here. It is a different expression altogether. fooResult expression is not used, but foo() expression is clearly used. What CSPro is doing here is double-lazy evaluation . Where calls into functions with no body are completely skipped even if used.
Binding function parameters via lambda expressions could result in the the lazy evaluation that Josh mentions. For instance in C++:
int GetArgument() { return 1; }
void func1(int x) { }
void func2(std::function<int()> get_x) { }
func1(GetArgument());
func2([] { return GetArgument(); });
With func2, with the argument passed using a lambda expression, the actual GetArgument function would only be called on demand. I have no idea how Haskell works, but theoretically a programming language could wrap all function arguments in some object that lends itself to lazy evaluation.