returns an empty string, as documented.
eventually trying to use the return value will cause an exception
Trying to invoke
the return value (an empty string) will cause an exception. There is another way to use the return value which will not:
I was initially going to remove IsFunc because this is more efficient than
f := Func(name)
may create a closure which is immediately destroyed, whereas
does not. Still, it is probably rare that one would call
and not follow it with:
Func(fn) to retrieve the reference;
%fn%() to call the function by name; or
- an assignment to store the function name to be called later (either with a dynamic function call or as a method).
In all of those cases, it is better to first retrieve the reference with
f := Func(fn)
, validate it, and then use/store the reference. On the other hand, in some cases it is more convenient for Func(fn) to throw: when fn is expected to be valid, especially if the current function can't continue without a valid Func.
One problem with exceptions is that handling one requires multiple statements - i.e. there aren't any syntax shortcuts, probably because they're supposed to be used only in "exceptional" circumstances. That doesn't necessarily have to be the case for AutoHotkey.
It might be helpful to have a "non-dynamic" operator or other syntax for a function reference, which can be validated at load-time (and could be more succinct). I think fincs suggested
, but I couldn't find the post (and I didn't like the look of it at the time).