Results 1 to 4 of 4

Thread: If and functions...

  1. #1
    Member
    Join Date
    2009-03
    Posts
    25
    Login to Give a bone
    0

    Question If and functions...

    Looking at this code I'm having some trouble understanding the if and function and how it works. This might be a simple but I'm just starting out...

    (if (and (> b a) (< b (* a b)))
    b
    a)

    I know that in the if statement, the predicate is evaluated and if true, the consequent is evaluated and returns it's value. If it's false, the alternative is evaluated and returns it's value.

    In the and statement, the expressions are evaluated left to right, one at a time. If any of the expressions are false, then that and expresson is false and the rest of the expressions are not evaluated. If all of the expressions are true, the value of the and expression is the value of the last one.

    I understand these individually, but what happens when both of these are in the same coding. Does the and expression cross out the if since it is written latter?

    Any help would be appreciated.

    Thanks

  2. #2
    Super Moderator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,722
    Login to Give a bone
    0

    Default Re: If and functions...

    From the HELP file...

    AND returns... Nil, if any of the expressions evaluate to nil; otherwise T. If and is issued without arguments, it returns T.

    Everything is evaluated from the inside out.
    So the (>) and (<) functions are evaluated first, then the (and) function, then the (if) function.

    Assume that b is greater than a, so this returns TRUE.
    Assume that a times b is greater than b, this returns TRUE.
    At this point the (and) statement is going to return TRUE, and the (if) statement will eval the first expression, or "b"
    R.K. McSwain | CAD Panacea |

  3. #3
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: If and functions...

    With if, if the expression is non nil, then it will execute what is the first expression of the if statement, and return the last item evaluated. With and, it only returns T or nil, not the last item evaluated. So if all the items in the and statement are true,then the first expression in the if statement will be evaluated and returned.

    Hope that helps.

  4. #4
    Member
    Join Date
    2009-03
    Posts
    25
    Login to Give a bone
    0

    Default Re: If and functions...

    That clears it up. I see what it's saying now. Thanks.

Similar Threads

  1. Replies: 0
    Last Post: 2012-11-24, 07:38 PM
  2. Looking for the functions used in AutoCAD
    By clovis in forum VBA/COM Interop
    Replies: 5
    Last Post: 2006-09-29, 02:12 PM
  3. Hydro Functions
    By marty.72337 in forum AutoCAD Civil 3D - General
    Replies: 2
    Last Post: 2006-03-31, 02:31 PM
  4. VBA functions n Text
    By bweir in forum Inventor Wish List
    Replies: 2
    Last Post: 2005-10-06, 02:39 PM
  5. I don't always use Map Functions...
    By aharris in forum AutoCAD Map 3D - Wish List
    Replies: 8
    Last Post: 2004-07-29, 02:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •