# System Function EC

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

# ⎕EC - Execute Controlled

 ⎕EC Execute Controlled "for a string expression"
Z←⎕EC R   where argument R is a string expression and returned Z is a 3-element [mixed, nested] vector.

 Z←⎕EC R R is executed, and the result Z is a 3-item vector.
R should be a string expression. ⎕EC is frequently used for testing and debugging purposes.

Return codes for Z: Normally, the first element of the return code (in variable Z) represents an integer in the range 0 to 5, where:
0 = Error
1 = Expression with a result which would display (for debugging purposes this means OK, R was not problematic.
2 = Expression with a result which would not display
3 = Expression with no explicit result
4 = Branch to a line
5 = Niladic goto / branch

The second item in Z (returned) is the value that would be returned by ⎕ET (quad event type, without altering the current value of ⎕ET). The third item returned is the actual result (IF one is generated); for return code 3 or 5 the third item is 0 0⍴0; for return code 4 the third item is the argument to the branch; for return code 0 the third item is ⎕EM.

```      Z←⎕EC 'a÷1'   ⍝ Right argument FAILS(a÷1, because variable "a" does NOT exist).
⍴Z
3                   ⍝ Thus a standard 3-element vector has been returned in Z
Z             ⍝ Let's see what Z looks like:
0  0 0  VALUE ERROR
⍎     a÷1
∧
Z     ⍝ first element in Z is the return code, a zero was generated in this case, indicating an error, as listed above.
0
Z
0 0
Z     ⍝ third element returned in Z is the actual nested string error message.
VALUE ERROR
⍎     a÷1
∧

⍝ A different test with "no problems" example:
Z←⎕EC '6÷0.5' ⍝ RIGHT argument SUCCEEDS(6÷0.5) because 6 can be divided by 0.5; under normal circumstances the answer would be 12.
⍴Z
3
Z
1  0 0  12
Z       ⍝ first element in Z is the return code, a one was generated in this case, indicating no problem, as per the list above.
1                ⍝ again, 1 = success, no problems encountered
Z
0 0
Z
12              ⍝ And Z correctly holds the expected answer.
```

The Execute Controlled system function normally takes a string as its right argument. In particular the left argument string may normally:

• call a function
• perform ANY allowed APL operation (e.g. addition, multiplication, division, subtraction, floor, ceiling, logic test, etc...)
• assign/set a value

System Variables (A value may be assigned to these except for ⎕DM)
ALX CT DM DT ELX FC FEATURE FPC IC IO
LR LX PP PR PW RL SA WSID
Niladic System Functions (a value cannot be assigned to these)
A AV EM ET LC NNAMES NNUMS SI SYSID SYSVER
T TC TCBEL TCBS TCESC TCFF TCHT TCLF TCNL TCNUL
TS WA
Monadic or dyadic system functions (a value cannot be assigned to these)
AT CR DC DFT DL DR EA EC ERROR ES
EX FMT FX MF NAPPEND NC NCREATE NERASE NINFO NL
NLOCK NREAD NRENAME NREPLACE NRESIZE NSIZE NTIE NUNTIE STOP TF
TRACE UCS VR
Note that quad functions and variables (except for the ⎕A family of functions) are case insensitive