Can the argument to RETURN be a function expansion?

Apr 13, 2010
236
3
58
The Hague
#1
Could it be that the function @AppStatus (that expands to a number) is not allowed there?

Code:
function AppStatus=`%@MAX[%?,%_?,%_syserr,%nAppExit]`
function ValidValue=`%@IF[defined %1 .AND. %@AppStatus[] == 0,0,1]`
Please advice.
 
#2
Your example seems to work.
Code:
v:\> function AppStatus=`%@MAX[%?,%_?,%_syserr,%nAppExit]`

v:\> function ValidValue=`%@IF[defined %1 .AND. %@AppStatus[] == 0,0,1]`

v:\> echo %@AppStatus[]
0

v:\> echo %@validvalue[path]
0

v:\> echo %@validvalue[pat]
1

v:\> seterror 5

v:\> echo %@AppStatus[]
5

v:\> echo %@validvalue[path]
1

v:\> echo %@validvalue[pat]
1
 
#3
I don't know what that had to do with the subject of your post, but, yes, RETURN's argument can be a function expansion.
Code:
v:\> type return.btm
echo %@exec[gosub foo]
quit

:foo
return %@eval[1+1]

v:\> return.btm
2
 
Apr 13, 2010
236
3
58
The Hague
#4
Thanks for your reply, Vince.
I am getting stubborn errors and am grasping for reasons.
Well not errors, but errand behavior. The errors occur when I use

return %@ValidValue[...]

which expands @AppStatus[] internally - and disappear when I simply

return %@IF[defined <envar>,1,0]

This happens not in one location of the code but in several locations and independently.

The debugger doesn't help much either in scenario's like this.
So, in a bout of despair . . . I began to wonder if perhaps that particular combination of function expansions could somehow be against a rule I overlooked or forgot about. I didn't and don't see any problem with it either, but - it appears at least - that we're both wrong.

Never mind, I'm working around it with the simpler variant, so at least I'm not stuck. I just can't code what I want to code.