See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Please explain how LISP function "cond" works

  1. #1
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Explaination on conditional processing

    in the cond function, If something meets condition 1 and condition 2, does it fall under condition 1 then skip to the end of the cond function?

  2. #2
    All AUGI, all the time Avatart's Avatar
    Join Date
    2004-06
    Location
    Upsidedown in dreamtown
    Posts
    928
    Login to Give a bone
    0

    Default Re: Please explain how LISP function "cond" works

    Quote Originally Posted by ccowgill
    in the cond function, If something meets condition 1 and condition 2, does it fall under condition 1 then skip to the end of the cond function?
    As far as I know, it will return on the first instance of the condition being true and not read any further possibilities.

  3. #3
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,803
    Login to Give a bone
    0

    Default Re: Please explain how LISP function "cond" works

    Quote Originally Posted by ccowgill
    in the cond function, If something meets condition 1 and condition 2, does it fall under condition 1 then skip to the end of the cond function?
    Have you checked out the (cond) function in HELP (acad_dev.chm)?

    The first "test" in the list that is non-nil will cause it's expressions to be evaluated, and the results are returned. No further evaluation of any more "test" will be done.

    Example:
    Code:
    (cond
           ( (not (setq fn (findfile "sample.txt")))
              (princ "\nCannot find sample.txt"))
           ( (not (setq fh (open fn "r")))
              (princ "\nCannot open sample.txt."))
           (T (do_your_function_here))
        )
    If sample.txt cannot be found, the (cond) returns the first (princ) statement and then ends.
    If sample.txt is found, but cannot be opened, then the second (princ) statement is returned and the (cond) ends.
    If both of the first two tests are nil (meaning that the file exists and it is opened successfully), then the last test (T) will always evaluate as "true" and the following expression will be executed.


    Carl_hd_Collins was close, except that a statement doesn't have to be TRUE to execute, only non-nil.
    Last edited by rkmcswain; 2006-11-16 at 02:33 PM.
    R.K. McSwain | CAD Panacea |

  4. #4
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Please explain how LISP function "cond" works

    That's all I needed to know, thanks.

  5. #5
    All AUGI, all the time Avatart's Avatar
    Join Date
    2004-06
    Location
    Upsidedown in dreamtown
    Posts
    928
    Login to Give a bone
    0

    Default Re: Please explain how LISP function "cond" works

    Quote Originally Posted by rkmcswain
    Carl_hd_Collins was close, except that a statement doesn't have to be TRUE to execute, only non-nil.
    Sorry, that was what I meant, my Lispese failed me!

  6. #6
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,803
    Login to Give a bone
    0

    Default Re: Please explain how LISP function "cond" works

    Quote Originally Posted by carl_hd_collins
    Sorry, that was what I meant
    I figured so, but just wanted to clear it up
    R.K. McSwain | CAD Panacea |

  7. #7
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    4

    Default Re: Please explain how LISP function "cond" works

    [ Moderator Action = ON ] Cab, I have merged your informative post into the Anatomy of an AUTOLISP file thread. You can find the location of your post here.

    Thank you for your contribution.

    Richard
    Forum Moderator[ Moderator Action = OFF ]
    Last edited by Opie; 2006-11-18 at 05:08 PM. Reason: See Moderator Action

  8. #8
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,803
    Login to Give a bone
    0

    Default Re: Please explain how LISP function "cond" works

    Quote Originally Posted by CAB2k
    This is sure to be More than you ask for.
    Excellent information. Thanks.
    R.K. McSwain | CAD Panacea |

  9. #9
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Please explain how LISP function "cond" works

    Quote Originally Posted by CAB2k
    This is sure to be More than you ask for. . . .
    No it can’t be too much

    Hey CAB2k why not bring this great story and a to the bar desk in "Anatomy of an AUTOLISP file"
    Welcome in . . .


    : ) Happy Computing !

    kennet

  10. #10
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,096
    Login to Give a bone
    0

    Default Re: Please explain how LISP function "cond" works

    Quote Originally Posted by kennet.sjoberg
    No it can’t be too much

    Hey CAB2k why not bring this great story and a to the bar desk in "Anatomy of an AUTOLISP file"
    Welcome in . . .


    : ) Happy Computing !

    kennet
    kennet, I'll see what I can do to get it moved. No need to double post.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 16
    Last Post: 2012-07-16, 07:41 PM
  2. S::Startup ignores lisp "command" function
    By sshively.230498 in forum CAD Management - General
    Replies: 2
    Last Post: 2010-04-20, 12:09 PM
  3. Lisp and xp "shell" function
    By dwbrink in forum AutoLISP
    Replies: 7
    Last Post: 2008-10-30, 01:15 PM
  4. Replies: 4
    Last Post: 2006-11-10, 03:50 PM
  5. Please explain to me how the chain function works or how to make it work
    By stephen.coff in forum Dynamic Blocks - Technical
    Replies: 5
    Last Post: 2005-12-22, 02:50 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
  •