Debug ECL programming

In the ECL language, operations such as OUTPUT cannot be performed in the definition, complicating our view of intermediate variables. This blog introduces debugging tips for several ECL programming language.

Use WHEN to output intermediate variables

Unlike programming languages such as C++ and Python, in ECL, the OUTPUT operation cannot be performed in the function definition. It will prompt

WHEN must be used to associate an action with a definition

We can use WHEN to output intermediate variables. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//a FUNCTION with side-effect Action
namesTable := FUNCTION
namesRecord := RECORD
STRING20 surname;
STRING10 forename;
INTEGER2 age := 25;
END;
o := OUTPUT('namesTable used by user <x>');
ds := DATASET([{'x','y',22}],namesRecord);
RETURN WHEN(ds,O);
END;

z := namesTable();
OUTPUT(z);

For multiple outputs, SEQUENTIAL can be used. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
//a FUNCTION with side-effect Action
namesTable := FUNCTION
namesRecord := RECORD
STRING20 surname;
STRING10 forename;
INTEGER2 age := 25;
END;
ds := DATASET([{'x','y',22}],namesRecord);
RETURN WHEN(ds,SEQUENTIAL(OUTPUT('namesTable used by user <x>'), OUTPUT('test2')));
END;

z := namesTable();
OUTPUT(z);

Logging with Std.System.Log

By using Std.System.Log, some logs can be recorded. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
IMPORT Std.System.Log AS Syslog;

//a FUNCTION with side-effect Action
namesTable := FUNCTION
namesRecord := RECORD
STRING20 surname;
STRING10 forename;
INTEGER2 age := 25;
END;
ds := DATASET([{'x','y',22}],namesRecord);
RETURN WHEN(ds, Syslog.addWorkunitInformation('test1234'));
END;

z := namesTable();
OUTPUT(z);

In Helpers of ECL Watch, in EclAgentLog, you can find the corresponding log.

image-20230619044834916

In embedded languages, use assert to check intermediate variables

When we need to debug some embedded Python codes, we cannot use the print function to print intermediate variables and can only output them externally by means of an assert False, 'message'. For example, if I want to view the summary of the model I defined, I can use the following:

1
2
3
4
5
# Debug
stringlist = []
mod.summary(print_fn=lambda x: stringlist.append(x))
short_model_summary = "\n".join(stringlist)
assert 1 == 0, short_model_summary