Product: TIBCO Spotfire®
Parsing error with if-else statement in Data Function
Why do I get a parsing error when calling if-else statements in my Data Functions?
Example:
if (2+2 ==4) print("true")
else print("not true")
runs from an S+ script window, but reports an error if run in a Spotfire Data Function:
Problem in parse(n = n, file = file): Syntax error: illegal name ("print")
after "else" on input line 2,
file "c:/documents and settings/ajack/desktop/script1.ssc"
Use traceback() to see the call stack
Symptoms:
Parsing error when running data function
Cause:
Parsing differences between S+ and Spotfire Data Functions
The parsing of if-else statements differs if running from an S+ script window to running from a Spotfire Data Function. When run from within a Data Function, the "else" part of the if-else *must* be on the same line as the end of the "if" part.
For example:
if (2+2 == 4) {print("true")
} else print("not true")
runs OK whether directly in S+ or from within a Spotfire Data Function, since the "else" is on the same line as the closing curly bracket of the "if" clause.
Comments
0 comments
Article is closed for comments.