It appears that the system works this way:

There is a place in each stack frame where (the result of the 
most-recent sentence not in a T block) is saved.

There is another place in each stack frame where (the result of the most 
recent sentence in a T-block) is saved.  This result is tested at the 
end of the T-block.  This value is set to i. 0 0 when a T block (even an 
empty one) starts execution, and also when a catch. block starts.

Can anyone verify that this is how it works?

Henry Rich

testcases follow, if anyone is interested

    (falseif =: 3 : 0) ''
smoutput 'falseif'
'initial return'
if. 0 do. end.
)
falseif
initial return

    (emptyif =: 3 : 0) ''
smoutput 'emptyif'
'initial return'
if. do. end.
)
emptyif
initial return

    (trueif =: 3 : 0) ''
smoutput 'trueif'
'initial return'
if. do. 'true branch' end.
)
trueif
true branch

    (nestedemptyif =: 3 : 0) ''
smoutput 'nestedemptyif'
0
if. if. do. end. do. 'true branch' else. 'false branch' end.
)
nestedemptyif
true branch

    (nestedfalseemptyif =: 3 : 0) ''
smoutput 'nestedfalseemptyif'
0
if. 0 if. do. end. do. 'true branch' else. 'false branch' end.
)
nestedfalseemptyif
true branch

    (nestedtrueemptyif =: 3 : 0) ''
smoutput 'nestedtrueemptyif'
0
if. 1 if. do. end. do. 'true branch' else. 'false branch' end.
)
nestedtrueemptyif
true branch

    (nestedfalseemptywhile =: 3 : 0) ''
smoutput 'nestedfalseemptywhile'
0
if. 0 while. 0 do. end. do. 'true branch' else. 'false branch' end.
)
nestedfalseemptywhile
true branch

    (nestedfalseemptyfor =: 3 : 0) ''
smoutput 'nestedfalseemptyfor'
0
if. 0 for. do. end. do. 'true branch' else. 'false branch' end.
)
nestedfalseemptyfor
true branch

    (nestedfalseemptyselect =: 3 : 0) ''
smoutput 'nestedfalseemptyselect'
0
if. 0 select. case. do. end. do. 'true branch' else. 'false branch' end.
)
nestedfalseemptyselect
true branch

    (nestedfalsetrueselect =: 3 : 0) ''
smoutput 'nestedfalsetrueselect'
0
if. 0 select. 1 case. do. end. do. 'true branch' else. 'false branch' end.
)
nestedfalsetrueselect
true branch

    (nestedfalsetry =: 3 : 0) ''
smoutput 'nestedfalsetry'
0
if. 0 try. catch. end. do. 'true branch' else. 'false branch' end.
)
nestedfalsetry
false branch

    (nestedtruefail =: 3 : 0) ''
smoutput 'nestedtruefail'
0
if. 1 try. 0 + ' ' catch. end. do. 'true branch' else. 'false branch' end.
)
nestedtruefail
true branch

    (nestedfalsefail =: 3 : 0) ''
smoutput 'nestedfalsefail'
0
if. 0 try. 0 + ' ' catch. end. do. 'true branch' else. 'false branch' end.
)
nestedfalsefail
true branch

    (nestedtruefailnestedempty =: 3 : 0) ''
smoutput 'nestedtruefailnestedempty'
0
if. 1 try. 0 + ' ' catch. end. if. do. r =. 'true branch' else. r =. 
'false branch' end. do. end.
r
)
nestedtruefailnestedempty
true branch

    (nestedfalsefailnestedempty =: 3 : 0) ''
smoutput 'nestedfalsefailnestedempty'
0
if. 0 try. 0 + ' ' catch. end. if. do. r =. 'true branch' else. r =. 
'false branch' end. do. end.
r
)
nestedfalsefailnestedempty
true branch



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to