Oxygen Basic

Programming => Problems & Solutions => Topic started by: Brian Alvarez on February 20, 2020, 02:42:57 AM

Title: Expression Nesting...
Post by: Brian Alvarez on February 20, 2020, 02:42:57 AM
Im having trouble with this:

Code: [Select]
Result = (IIF(Eval(RIGHT(Conc, 1)="S"), 10, 20))
Code: [Select]
ERROR: ERROR: expression nesting
WORD: )
IN: evaluator
LINE: 1087
FILE: "main source

And this:

Code: [Select]
Result = (IIF(RIGHT(Conc, 1)="S", 10, 20))
Code: [Select]
ERROR: Linker found unidentified names:
1087 mid "main source"
1100 mid "main source
Title: Re: Expression Nesting...
Post by: Brian Alvarez on February 20, 2020, 02:46:37 AM
If i add my own right function:

Code: [Select]
ERROR: Linker found unidentified names:
1090 right "main source"
1103 right "main source
Title: Re: Expression Nesting...
Post by: Charles Pegge on February 20, 2020, 08:01:11 AM
Hi Brian,

Yes I see the problem of functions inside boolean-compare expressions.

Here is an alternative way:

Code: [Select]
macro iif int(R,X,A,B)
  if X
    R=A
  else
    R=B
  endif
end macro

string s="qq"
int result

result = iif (ucase(s) = "QQ", 10, 20)
print result '10
Title: Re: Expression Nesting...
Post by: Brian Alvarez on February 20, 2020, 01:54:35 PM
The problem is that sometimes even the iif could be used inline. like this:


Code: [Select]
result = iif (ucase(s) = "QQ", 10, 20) + xyz
edit:
nevermind, it works. The more you know. How does thes macro works?
Title: Re: Expression Nesting...
Post by: Charles Pegge on February 20, 2020, 02:51:18 PM
The macro function is processed first, storing the result in temp variable R. The macro call expression is then replaced by R.

This is how macro functions can be used inline within any expression.