Author Topic: Expression Nesting...  (Read 828 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Expression Nesting...
« 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

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Re: Expression Nesting...
« Reply #1 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

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
Re: Expression Nesting...
« Reply #2 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

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Re: Expression Nesting...
« Reply #3 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?
« Last Edit: February 20, 2020, 02:05:09 pm by Brian Alvarez »

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
Re: Expression Nesting...
« Reply #4 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.