Dynamic boolean expression's value

String str = "((true)&((false)|true))";
boolean result = xmethod(str);
xmethod????

public static void xmethod(String expression) {
// put your code here
}quite good, but you have one mistake in it, xmethod should return boolean, so:public static boolean xmethod(String expression) {
   boolean result;
   if (Boolean.valueOf(expression).booleanValue()) {
      result = true;
   } else (
      // put your code here
   return result;

Similar Messages

  • How to get dynamic boolean expression's value?

    String str = "((true)&((false)|true))";
    how to get the result of boolean from str?

    You will need to write a simple parser to parse the string and evaluate the expression.

  • Dynamic boolean expression evaluation

    Hey everyone,
    We have a table that consists of a couple key columns and a column containing a boolean expression. We want to select a number of rows based on the key columns and evaluate the boolean expression in the expression column for each, only returning the first row wherein the boolean expression evaluates to true.
    We are using a context to inject the test variables into the boolean expressions and currently we are selecting all the key rows in a PL/SQL procedure and going through the cursor evaluating each of the boolean expressions with an execute immediate.
    The expressions are currently formated in the columns as anonymous PL/SQL blocks that, when called, will either return true or false to the PL/SQL procedure. Upon returning true, the procedure stops looping and returns true to the caller.
    Psuedo-code would be:
    - set-up sys_context with condition variables
    - create cursor for: select * from expression_tbl et where <key matches>
    - begin loop through cursor
    - execute immediate cursor_row.expression using out :out_is_true
    - if out_is_true = 'Y' then return true
    - loop
    - return false
    The expressions (anonymous PL/SQL blocks) from the table look something like this:
    begin if ((''||sys_context('ctx', '1')||'' = 'FL') AND (''||sys_context('ctx', '3')||'' BETWEEN 1619 AND 4598) ) then :1 := 'Y'; end if; end;
    This works, but it seems like I should be able to do this another way and potentially extract more performance.
    So...a couple questions:
    1) I have read on ask Tom that a dynamic select statement (rather than an anonymous PL/SQL block) can evaulate the boolean expressions. I.E. rather than use an execute immediate clause on an anonymous PL/SQL block contained in the expression column, I would make the expression column compatible with a where clause and create this dynamic SQL query: 'select count(*) from dual where ' || expression. I would then execute that query and if it returns a row then the expression is true, otherwise it is false. My question is, does anyone think the performance of parsing the SQL and executing it would be better than that of executing an anonymous PL/SQL block for every row? Tom said that the SQL could incur a lot of hard-parses and kill performance, but how deathly is the constant compilation of anonymous PL/SQL blocks as shown above in comparison?
    2) Would there be any benefit to pulling the execute routines out of the PL/SQL block and issuing a query such as the following:
    select * from expression_tbl et where <key matches> AND pkg.eval_routine(et.expression) = 'Y' AND rownum <= 1.
    I realize that the evaulating routine would then need to either perform an execute immediate on et.expression (if we keep the current method in place) or formulate the dynamic SQL statement and execute it. But, could this be faster than doing the same loop through rows explicitely in PL/SQL?
    Doing this would trim my PL/SQL down to:
    - set up sys_context
    - execute the above select statmenet
    - if a row is returned then return true otherwise return false
    Seems more elegant, but the peformance is all that matters.
    3) Is there any built-in routine that I may be able to replace pkg.eval_routine from 2 with that would evaulate boolean expressions for me? Or any other way to inline the idea from 1 with 2? I can't think of one given the dynamic nature of the beast, but...maybe there's something I missed.
    Thanks everyone! Hopefully I've expressed myself clearly.

    Brian - According to Tom Kyte Doing PL/SQL inside Execute Immediate should be faster as you are already within the context of a PL/SQL engine. If we choose to do it in SQL then the PL/SQL engine has to hand it over to the SQL Engine for executing the dynamic Select statements and so might be a little slower. But I am not sure if the difference can be quantifiable unless u do your own test of both evaluators and run them for like a few thousand times in a loop.
    If you are using 10g R2 - you might want to look into DBMS_RLMGR package which is the API for the Oracle's version of the embedded business rule manager.
    I looked into it but it didn't fit our needs as its deficient with respect to rule versioning and effective and until date based business rule enforcement/ validation.
    After taking a shot at designing something home grown I feel its not that difficult to construct one that fit our needs inclusive of the features( rule versioning, effective and until dates) that I listed above as deficiencies in the Oracle embedded rule engine.
    If you don't have those requirements may be using the Business Rule manager API of 10g R2 might not be a bad anticipating it will be improved in future versions.
    Regards
    -Suren

  • Dynamic execution of boolean expression

    Hi folks,
    I want to execute a boolean expression dynamically, can you pls help me how to do it.
    For example,
    String str = " ( X & ( Y | Z ) ) " ;
    They value of X , Y or Z will be either true or false.
    After replacing their value, I will get string as follow
    String result = "( true & (false | true ) ".
    Now I want to execute the String as boolean expression in order to get
    a result as a true or false.
    So, i need a solution to implement this. The expression may be simple or compound . It is so urgent waiting for your reply.
    Appreciated if you provide sample code.
    Thx !
    With regards,
    Rahul

    Java is a compiled language (well, strictly, a semi-compiled language.) This means that stuff like parsing expressions only happens at compile time. Variable names don't exist at run time, neither does the code which analyses expressions.
    If you really need to do this kind of thing, therefore, all the code for parsing these expressions has to be a part of your program, and stuff like values for variable names will have to be set explicitly by your program, not in regular variables but in variable list for the "scripting engine" you invoke.
    You can either write your own expression analyser (not a trivial task if you haven't done it before) or you can search arround the web for one someone else has written and find out if it covers your requirements. BeenShell has been suggested. Find it on the web and study it's documentation.
    Incidentally when the new release of Java comes out it will include serveral such "Scripting engines" for languages like JavaScript or Jython, and such things will be less hastle.

  • Dynamic logic expression

    Hi Experts, 
    Iu2019m trying to build a routine with dynamic logical expressions but it's now working...
    Basically Iu2019m building a string with the expression, a and after the string it's completed Iu2019m calling a macro that consist in a if.
    if expression eq true
    return true value
    but the value returned by the macro it's always false, even when the logical expression it's true...
    i already tried the logical function BOOLC but apparently my version, ECC 6, doesnu2019t recognize it....
    Below goes the code, if anyone could help me Iu2019ll be appreciated.
    "Macro definition
    DEFINE check_condition.
    IF &1 EQ ABAP_TRUE.
        move 'X' to &2.
      endif.
    END-OF-DEFINITION.
    LOOP AT tab_regras."Rules
        CLEAR: str_cond, lv_result.
        LOOP AT dfies_tab WHERE fieldname CS 'ARGUMENTO'.
          CLEAR: lw_string, str_1, str_2, str_3.
          ASSIGN COMPONENT dfies_tab-fieldname OF STRUCTURE tab_regras TO <fs_field>.
          CHECK <fs_field> IS NOT INITIAL.
          SPLIT <fs_field> AT '/' INTO  str_1 str_2 str_3.
          ASSIGN (str_1) TO <fs_value1>.
    "     ASSIGN (str_2) TO <fs_value2>.
    "      ASSIGN (str_3) TO <fs_value3>.
          IF str_cond IS INITIAL..
            CONCATENATE <fs_value1> str_2 str_3 INTO str_cond SEPARATED BY space.
            CONTINUE.
          ENDIF.
          CONCATENATE str_cond 'and' <fs_value1> str_2 str_3 INTO str_cond SEPARATED BY space."string condition
        ENDLOOP.
        check_condition str_cond lv_result.
        CHECK lv_result EQ 'X'.
    Thanks in advance,
    Best Regards
    João Martins

    It would be helpful if you show us what is the example content of str_cond .
    Anyhow your check looks like you want to compare some condition with value X which abap_true denotes i.e.
    if field_1 = 10 and field_2 = 20 EQ 'X'. 
    endif.
    This doesn't make sense for me or maybe I am missing something which is hidden behid this str_cond . Your left hand side expression value must however be equal to right hand side value. So the conditon will only be true if
    if 'X' = 'X'.
    endif.
    Regards
    Marcin
    PS: please note that in ABAP there is no real boolean value, so you can't have condition like in JAVA or C
    if (true_condition)
    //do something
    you always have to compare two values (here abap_true which is X if fact).
    Edited by: Marcin Pciak on May 24, 2011 3:59 PM

  • Boolean Expression Evaluator

    Hello everyone...
    Does any one know how to create a Java program that will evaluate boolean expression... For example, the user may enter (T AND T) OR F statement and the program will check the expression is valid or not and in addition it gives the answer T for true. Does anyone know where to download the free sample code that will be able to help me.. thanks.
    URGENT!
    -Eugene-

    http://www.japisoft.com/formula
    Features :
    * Decimal, string, boolean operators (or, and, not, xor...)
    * Unicode
    * Boolean expression support : (A or B) and not ( C equals D )
    * String expression support : "abc" != "cba"
    * IF THEN ELSE expression
    * Short expression format : 2x+3y
    * Variable : A=(cos(PI + x )*2) + [y-x]^2
    * Multiple lines expression : A = 1 B = A + 1 ...
    * Functions with decimal, boolean or string arguments
    * Evaluation tree produced by a pluggable parsing system
    * Evaluation optimization for symbol value changes
    * Standard library with 24 mathematical functions
    * Delegate for resolving unknown functions or symbols
    * Extend or add a new library dynamically
    * Share multiple formula context
    * Override any functions from the current library by your one
    * Support for multithreaded computing
    * Many samples (library extension, graphes) for API interesting parts
    * JDK 1.1 compliant (tested on JDK1.1.8 and JDK1.4.2)
    Best regards,
    A.Brillant

  • Boolean Expression for get date

    Hi Experts,
    I am working boolean expression in ssis package. I want download files from ftp and the file name is mic_20141101-mi.txt. 
    I want to take yesterday files for that i am using expression but i want to give dynamic date which i want give in variable the specific date to download those files from FTP.
    For this process i am using Boolean Expression if i give the specific date in variable then its download specific date files from ftp or else its download yesterday files.
    Pls help to me for this scenario.
    Raj.

    You need to have a variable inside SSIS through which you pass the date value
    Once passed you can have a script task inside your package to check for the pattern of date variable value inside your file to select correct files
    see this for similar logic where i'm looking for files from current day
    http://visakhm.blogspot.in/2012/05/package-to-implement-daily-processing.html
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Dynamic action with set value on date field

    Hi,
    I'm using APEX 4.02
    I'm trying to calculate the age based on the date of birth dynamically on a form. I'm trying to do this with a (advanced)dynamic action with set value.
    I'm able to get this kind of action working based on a number field etc, but NEVER on a date field.
    I've read all posts on this subject but so far no solution. Even if I try to simply copy the value over to another date field or typecast it to a string ( to_char function ) it does not work. So for me the problem seems to be in the source field being a date field.
    I've tried using the source value as is in a select statement :
    select :P33_GEBOORTEDATUM from dual;
    and also type casted based on the date format :
    select TO_DATE(:P33_GEBOORTEDATUM,'DD-MON-YYYY') from dual
    but still no luck.
    On the same form I don't have any issues as long as the calculation is based on number fields, but as soon as I start using dates all goes wrong.
    Any suggestions would be greatly appreciated. If you need any extra info just let me know.
    Cheers
    Bas
    b.t.w My application default date format is DD-MON-YYYY, maybe this has something to do with the issue .... ?
    Edited by: user3338841 on 3-apr-2011 7:33

    Hi,
    Create a dynamic action named "set age" with following values.
    Event: Change
    Selection Type: Item(s)
    Item(s): P1_DATE_OF_BIRTH
    Action: Set value
    Fire on page load: TRUE
    Set Type: PL/SQL Expression
    PL/SQL Expression: ROUND( (SYSDATE - :P1_DATE_OF_BIRTH)/365.24,0)
    Page items to submit: P1_DATE_OF_BIRTH
    Selection Type: Item(s)
    Item(s): P1_AGE
    Regards,
    Kartik Patel
    http://patelkartik.blogspot.com/
    http://apex.oracle.com/pls/apex/f?p=9904351712:1

  • How to evaluate dynamic XPath expression in BPEL?

    I have an xml file where I keep many settings for my BPEL process. At runtime, I read the file and I want to select values from it based on values in the process payload.
    For example, imagine that the process payload is an order:
    <order>
    <header>
    <id/>
    <customer_id/>
    <team_id/>
    </header>
    <items>
    <item>
    <id/>
    <sku/>
    <price/>
    <quantity/>
    </item>
    </items>
    </order>
    Now, in my xml settings file, I have a section where I keep a mapping of "team_id" and "assignment_group", so that for each team id, I can select the appropriate group to whom a task should be assigned. The relevant section of the settings file will look something like this:
    <assignment_groups>
    <group team_id='0923230'>invoice_approvers</group>
    <group team_id='3094303'>order_approvers</group>
    <group team_id='3434355'>shipping_approvers</group>
    </assignment_groups>
    So, imagine I get an order input to my process where the team_id is '3094303'. Now I have to lookup the correct assignment group in my settings file.
    So, I construct the dynamic XPath expression
    /settings/assignment_groups/group[@team_id=3094303]
    I know that this would evaluate to "order_approvers". However, even though I have the XPath expression in a BPEL variable, and I have my settings file as a BPEL variable also, I don't know how to execute the XPath expression against the settings BPEL variable to retrieve the correct value.
    Any ideas appreciated.
    Thanks,
    Jack

    James:
    Thank you for the response. Incidentally, this is the very same document and section that I have been looking at for guidance. Specifically, the section titled "Dynamically indexing by Constructing an XPath at Run Time" on page 12-13.
    I tried to do something similar to the example at the top of page 13:
    <variable name="iterator" type="xsd:integer"/>
    <assign>
    <copy>
    <from expression="concat('/invoice/line-item[',bpws:getVariableData('iterator'), ']/line-total')"/>
    <to variable="xpath"/>
    </copy>
    <copy>
    <from expression="bpws:getVariableData('input', 'payload',bpws:getVariableData('xpath')) + ..."/>
    </copy>
    </assign>
    I am able to achieve the first copy operation to get my dynamic XPath into a BPEL variable and that's fairly straightforward. But I am unable to get the second copy to work. Specifically, I am not sure what to put in the second argument of the bpws:getVariableData function. I have tried many different combinations, but when I try to compile my program, I get the following compilation error:
    Error:
    [Error ORABPEL-10902]: compilation failed
    [Description]: in "C:\code\TrainingWS\SampleGetSettings\bpel\SampleGetSettings.bpel", XML parsing failed because "org.collaxa.thirdparty.jaxen.expr.DefaultFunctionCallExpr".
    [Potential fix]: n/a.
    Thanks,
    Jack

  • How to convert a boolean expression into a number in SQL (not PL/SQL)

    I have a boolean expression
    FIELD IN (SELECT FIELD FROM TABLE)
    which I would like to convert into a number, preferably into 0 for true and into 1 for false. The reason being that I want to sum the values in a HAVING clause.
    I have tried with DECODE, SIGN, TO_NUMBER, but all fail with an error message to the order of wrong type of argument.
    Does anyone have an idea?
    /poul-jorgen

    Hi, you can do it with case if you have Oracle 9i
    Regards
    Laurent
    select case when dummy in ('X') then 1 else 0 end from dual;

  • Pl/sql boolean expression short circuit behavior and the 10g optimizer

    Oracle documents that a PL/SQL IF condition such as
    IF p OR q
    will always short circuit if p is TRUE. The documents confirm that this is also true for CASE and for COALESCE and DECODE (although DECODE is not available in PL/SQL).
    Charles Wetherell, in his paper "Freedom, Order and PL/SQL Optimization," (available on OTN) says that "For most operators, operands may be evaluated in any order. There are some operators (OR, AND, IN, CASE, and so on) which enforce some order of evaluation on their operands."
    My questions:
    (1) In his list of "operators that enforce some order of evaluation," what does "and so on" include?
    (2) Is short circuit evaluation ALWAYS used with Boolean expressions in PL/SQL, even when they the expression is outside one of these statements? For example:
    boolvariable := p OR q;
    Or:
    CALL foo(p or q);

    This is a very interesting paper. To attempt to answer your questions:-
    1) I suppose BETWEEN would be included in the "and so on" list.
    2) I've tried to come up with a reasonably simple means of investigating this below. What I'm attempting to do it to run a series of evaluations and record everything that is evaluated. To do this, I have a simple package (PKG) that has two functions (F1 and F2), both returning a constant (0 and 1, respectively). These functions are "naughty" in that they write the fact they have been called to a table (T). First the simple code.
    SQL> CREATE TABLE t( c1 VARCHAR2(30), c2 VARCHAR2(30) );
    Table created.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE pkg AS
      2     FUNCTION f1( p IN VARCHAR2 ) RETURN NUMBER;
      3     FUNCTION f2( p IN VARCHAR2 ) RETURN NUMBER;
      4  END pkg;
      5  /
    Package created.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE BODY pkg AS
      2 
      3     PROCEDURE ins( p1 IN VARCHAR2, p2 IN VARCHAR2 ) IS
      4        PRAGMA autonomous_transaction;
      5     BEGIN
      6        INSERT INTO t( c1, c2 ) VALUES( p1, p2 );
      7        COMMIT;
      8     END ins;
      9 
    10     FUNCTION f1( p IN VARCHAR2 ) RETURN NUMBER IS
    11     BEGIN
    12        ins( p, 'F1' );
    13        RETURN 0;
    14     END f1;
    15 
    16     FUNCTION f2( p IN VARCHAR2 ) RETURN NUMBER IS
    17     BEGIN
    18        ins( p, 'F2' );
    19        RETURN 1;
    20     END f2;
    21 
    22  END pkg;
    23  /
    Package body created.Now to demonstrate how CASE and COALESCE short-circuits further evaluations whereas NVL doesn't, we can run a simple SQL statement and look at what we recorded in T after.
    SQL> SELECT SUM(
      2           CASE
      3              WHEN pkg.f1('CASE') = 0
      4              OR   pkg.f2('CASE') = 1
      5              THEN 0
      6              ELSE 1
      7           END
      8           ) AS just_a_number_1
      9  ,      SUM(
    10           NVL( pkg.f1('NVL'), pkg.f2('NVL') )
    11           ) AS just_a_number_2
    12  ,      SUM(
    13           COALESCE(
    14             pkg.f1('COALESCE'),
    15             pkg.f2('COALESCE'))
    16           ) AS just_a_number_3
    17  FROM    user_objects;
    JUST_A_NUMBER_1 JUST_A_NUMBER_2 JUST_A_NUMBER_3
                  0               0               0
    SQL>
    SQL> SELECT c1, c2, count(*)
      2  FROM   t
      3  GROUP  BY
      4         c1, c2;
    C1                             C2                               COUNT(*)
    NVL                            F1                                     41
    NVL                            F2                                     41
    CASE                           F1                                     41
    COALESCE                       F1                                     41We can see that NVL executes both functions even though the first parameter (F1) is never NULL. To see what happens in PL/SQL, I set up the following procedure. In 100 iterations of a loop, this will test both of your queries ( 1) IF ..OR.. and 2) bool := (... OR ...) ).
    SQL> CREATE OR REPLACE PROCEDURE bool_order ( rc OUT SYS_REFCURSOR ) AS
      2 
      3     PROCEDURE take_a_bool( b IN BOOLEAN ) IS
      4     BEGIN
      5        NULL;
      6     END take_a_bool;
      7 
      8  BEGIN
      9 
    10     FOR i IN 1 .. 100 LOOP
    11 
    12        IF pkg.f1('ANON_LOOP') = 0
    13        OR pkg.f2('ANON_LOOP') = 1
    14        THEN
    15           take_a_bool(
    16              pkg.f1('TAKE_A_BOOL') = 0 OR pkg.f2('TAKE_A_BOOL') = 1
    17              );
    18        END IF;
    19 
    20     END LOOP;
    21 
    22     OPEN rc FOR SELECT c1, c2, COUNT(*) AS c3
    23                 FROM   t
    24                 GROUP  BY
    25                        c1, c2;
    26 
    27  END bool_order;
    28  /
    Procedure created.Now to test it...
    SQL> TRUNCATE TABLE t;
    Table truncated.
    SQL>
    SQL> var rc refcursor;
    SQL> set autoprint on
    SQL>
    SQL> exec bool_order(:rc);
    PL/SQL procedure successfully completed.
    C1                             C2                                     C3
    ANON_LOOP                      F1                                    100
    TAKE_A_BOOL                    F1                                    100
    SQL> ALTER SESSION SET PLSQL_OPTIMIZE_LEVEL=0;
    Session altered.
    SQL> exec bool_order(:rc);
    PL/SQL procedure successfully completed.
    C1                             C2                                     C3
    ANON_LOOP                      F1                                    200
    TAKE_A_BOOL                    F1                                    200The above shows that the short-circuiting occurs as documented, under the maximum and minimum optimisation levels ( 10g-specific ). The F2 function is never called. What we have NOT seen, however, is PL/SQL exploiting the freedom to re-order these expressions, presumably because on such a simple example, there is no clear benefit to doing so. And I can verify that switching the order of the calls to F1 and F2 around yields the results in favour of F2 as expected.
    Regards
    Adrian

  • How to make dynamic actions using Set Value work in all browsers?

    I’m having a cross-browser incompatibility issue with dynamic actions using Set Value.  The dynamic action works like a charm on Chrome but has no effect on either IE or Firefox.  The code in oracle.apex.com and here are the credentials:
    Workspace: DDBA
    Username: [email protected]
    Password: redtruck12
    These code is on page 3 and here are the details:
    There are two report lists (Standard and Special) and some of the reports require additional information supplied in either select lists or text boxes.
    If the user selects a Standard report requiring a select list/text box, then the dynamic action sets the value of Special Reports to NULL (and vice-versa).
    The dynamic action is to prevent a simultaneous selection of both the Standard and Special reports.  To see how it works on Chrome, do this:
    Run Page 3
    Select the ‘Report for Search Criteria’ option from the Standard Report list.  A ‘Search Criteria’ text box appears
    Select the ‘Report by Release’ option from the Special Reports list.  A select list appears and the ‘Search Criteria’ text box disappears.
    If you do the same things on IE or Firefox, the text box does not disappear. 

    Hi,
    Things are going wrong with setting the item values to NULL. If you check your session state, you'll see that in chrome your items values indeed will be set to null, but in firefox they won't.
    Also I've noticed that you don't reset the other input fields, so their values persist in the session state. Since you submit your page every time you change one of the report select lists, this might lead to unexpected behaviour. Lastly, I've noticed you use a sql exists expression to manage the display/hide of your page items. A condition of type "Value of  expression 1 = expression 2" causes less overhead as you don't need to switch to the db sql engine for every item to validate.
    I'd suggest you rethink your specs and try to create:
    - One dynamic action (since a value of standard select excludes the value of special select, and vice versa)
    - Set the values for hidden items to null, also in session state
    - Use a refresh of region as extra event in your dynamic action, instead of submitting your page for every change.
    Regards,
    Vincent
    http://vincentdeelen.blogspot.com

  • Dynamic El expression evaluation

    Hello,
    I have a bean which returns me map of key-value pairs ( String,String) . In my jsff, I need to access the map's value based on key which is a a dynamic El expression
    <af:iterator id="i1" value="#{bindings.leaderBoardEntities.collectionModel}"
    var="entity" rows="#{bindings.leaderBoardEntities.rangeSize}">
    <af:image id="i2" source="#{pageFlowScope.ImagesBean.imageUrlPair[entity.displayName]}"
    shortDesc="user info"
    inlineStyle="width:50px;height:50px;"/>
    </af:iterator>
    I am unable to evalue the key for the map.
    I tried,
    source="#{pageFlowScope.ImagesBean.imageUrlPair[entity.displayName]}
    source="#{pageFlowScope.ImagesBean.imageUrlPair['#{entity.displayName}']}
    source="#{pageFlowScope.ImagesBean.imageUrlPair['${entity.displayName}']}
    source="#{pageFlowScope.ImagesBean.imageUrlPair[#{entity.displayName}]}--this is syntactically wrong
    However , this works
    source="#{pageFlowScope.ImagesBean.imageUrlPair['Twitter']}
    Kindly help me

    Hi,
    this is because the row does not have a setDisplayName and getDisplayName method. It has setAttribute(int), setAttribute(String) as well as getAttrinute(int), getAttribute(String) methods. So the input you provide is constantly null
    Frank

  • Short-circuiting boolean expressions

    There is a term used in other languages to describe the behavior of compiled code which evaluates boolean expressions: short circuiting. Basically, it means that if a term in an expression determines its value, then following terms never get evaluated, since they are irrelevant. For example, I have noticed that this always works in AppleScript:
    if class of x is not integer or x > 32 then . . . .
    But this will throw an exception if x is something that can’t be coerced into a number:
    if x > 32 or class of x is not integer then . . . .
    It looks to me that the reason the first always works is that Applescript is short-circuiting, and therefore there is no attempt to evaluate the inequality if x is of inappropriate class.
    Does anyone know if Applescript’s behavior is sufficiently well defined that I can be confident it will always short circuit? I know I can avoid the issue by breaking such expressions into separate, nested, if statements. If there is no such assurance that is what I will probably make a habit of doing. But I thought I'd ask if this is really necessary.

    Hello
    Short-circuiting is well-defined in AppleScript.
    cf. ASLG > Operator References (p.179 of ASLG pdf)
    http://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/Appl eScriptLangGuide/AppleScriptLanguageGuide.pdf
    Regards,
    H

  • Evaluating boolean expressions from a string

    Hi All,
    In my program I am dynamically generating boolean expressions.
    Hence, I store the expression as a string. I want to be able to determine if that expression evaluates to true/false.
    For eg, String expr = "1 < 2";
    I want to be able to evaluate expr and print false(in this case)
    How can I do that? Are there any class that come with JDK1.4 for doing this or can you point me to some API that I can use for this.
    Thanks,
    Vijay

    I can't count how many times this has been askedhere.
    Try searching the forums.Give yourself credit - you could count it if you
    wanted to.
    OK, maybe so. But I can't count it off the top of my
    head. :-) But easier than counting the hairs on your head (well.....presuming you do have some....)
    Really, it's bizarre how much this gets
    asked. I think I'll start a new thread about it...Be realistic....the integer to string or string to integer gets asked a lot more often!

Maybe you are looking for

  • One Target for multiple items

    Does anyone know how to set up a drag and drop activity where you can have 1 target that multiple items get dragged to? For example, an activity where you would drag multiple images into a trash can. I've tried, and it seems like once one items goes

  • Problem with webcam go plus

    hi.sorry,have problem speak engl....i am italy ............mi dice che mnca la firma digitale ...mi dice un nome di un file wcgopvid.nt,sconosciuto ?che devo fare?

  • Media Smart Photo Printing

    I have a new HP and it has Media Smart. I transferred all of my photos to the new PC and they all loaded into Media Smart. I can access the pictures but when I try to print them it goes to the Fax center. I can get a pop up that says local printer bu

  • New DSL connection prevents screen share, videochat

    Previously, I was able to videochat and screen share with a remote computer using ichat. With that particular remote computer, I was never able to use vnc or finder-originated screen sharing, so I've always relied on ichat. I switched from cable to V

  • Help Getting Sound Card To W

    I just installed my sound card and installed the driver. And the sound was working for a few minutes, but now that I restard my computer the sound does not work anymore. I have tried disabling the motherboard sound from the BIOS. I have made sure tha