escaping via .OR.
  • Vince

    escaping via .OR.

    by Vince » Sat Oct 21, 2006 2:34 pm

    In some languages the OR, in Capital the .OR. , operator does not evaluate the right hand argument/arguments if the left one returns TRUE.
    Testing this on version 7.4 and 7.41 shows me that Capital Script does escape the .OR. evaluation the same way. I haven't tested .AND. yet however I assume, at this point, that it's similar.
    Therefore the following code currently works as expected.

    OpenTable("TableName") .OR. Echo("Table failed to open")

    Although 'Return' does not actualy return a value to the script that calls it I am wondering if this is allowed by Capital Script in the case of the .OR. and .AND. operators, where it is the final part of the evaluation? If so I could effectively do the following.

    OpenTable("TableName") .OR. (Echo("Table failed to open") .AND. Return FALSE)

    I would like to use code constructs similar to the above to achieve more compact, and hopefully quicker, code. However, I would also like to be certain that in doing so it won't break on future releases.

    I know that .OR.ing conditions where one of those conditions doesn't actualy return anything to evaluate would not be allowed in many languages. However, my reasoning in this regard is that if Captial Script does allow it and there are no unpleasent side effects from calling 'Return' as the last part of such an evaluation, then I will use such constructs.

    Soon I will be rewriting quite a large script with the aim of improving it's performance and would be most grateful for an answer to the above.

    Thank you also for your previous excellent help.
    TIA
    Vince
  • COBS Tech Support
    Posts: 678
    Joined: Fri Sep 09, 2005 8:23 am

    by COBS Tech Support » Mon Oct 23, 2006 4:01 pm

    Expressions are evaluated from left to right until the outcome is determined by the language processor. So:

    a .Or. b

    will evaluate (execute) b if a is not TRUE. But it will not evaluate (execute) b if a is TRUE.

    Also with:

    a .And. b

    will evaluate (execute) b only if a evaluates to TRUE.

    This type of syntax evaluation is not expected to change in any future release, and will not change for the upcoming CAPITAL V8.

Who is online

Users browsing this forum: No registered users and 1 guest