COND question

Discussion in 'AutoCAD' started by Matt W, Sep 27, 2004.

  1. Matt W

    Matt W Guest

    I'm writing a home-grown "add selected" program and I'm running into a
    mental block...

    I'd like the program to perform certain tasks based on a block selected.
    For example, if the block is named BLOCK1 then do task 1, if it's called
    BLOCK2, then do task 2. If it's called something else, then do some other
    task.

    So..... I've got my COND statement structured something like this...

    (cond
    ((= strBlockName "Block1")
    ; do something here...
    )
    ((= strBlockName "Block2")
    ; do something else here...
    )
    ((= some other block name)
    ; do some other task here...
    )
    )

    And my question is this: What's the proper syntax for the last COND
    statement?!?

    [insert mental block here]
     
    Matt W, Sep 27, 2004
    #1
  2. Matt W

    James Allen Guest

    If what you posted covers all of your possible conditions, then you're
    already done. If you need a closing "if none of the preceding apply"
    statement, then ((t <then code here>)) would be your last statement.
     
    James Allen, Sep 27, 2004
    #2
  3. Matt W

    Tom Smith Guest

    Per James' reply, the traditional last condition is simply t. Since this
    always evaluates true, its associated result always fires.

    (cond
    ((test1)
    (result1)
    )
    ((test2)
    (result2)
    )
    ....
    (t
    (fallbackresult)
    )
    )
     
    Tom Smith, Sep 27, 2004
    #3
  4. Matt W

    Matt W Guest

    That's what I was looking for.
    Thanks gentlemen!


    --
    I support two teams: the Red Sox and whoever beats the Yankees.


    "Tom Smith" <nospam> wrote in message | Per James' reply, the traditional last condition is simply t. Since this
    | always evaluates true, its associated result always fires.
    |
    | (cond
    | ((test1)
    | (result1)
    | )
    | ((test2)
    | (result2)
    | )
    | ...
    | (t
    | (fallbackresult)
    | )
    | )
    |
    |
    | | > I'm writing a home-grown "add selected" program and I'm running into a
    | > mental block...
    | >
    | > I'd like the program to perform certain tasks based on a block selected.
    | > For example, if the block is named BLOCK1 then do task 1, if it's called
    | > BLOCK2, then do task 2. If it's called something else, then do some
    other
    | > task.
    | >
    | > So..... I've got my COND statement structured something like this...
    | >
    | > (cond
    | > ((= strBlockName "Block1")
    | > ; do something here...
    | > )
    | > ((= strBlockName "Block2")
    | > ; do something else here...
    | > )
    | > ((= some other block name)
    | > ; do some other task here...
    | > )
    | > )
    | >
    | > And my question is this: What's the proper syntax for the last COND
    | > statement?!?
    | >
    | > [insert mental block here]
    | >
    | > --
    | > I support two teams: the Red Sox and whoever beats the Yankees.
    | >
    | >
    | >
    |
    |
     
    Matt W, Sep 27, 2004
    #4
  5. Matt W

    Tom Smith Guest

    That's what I was looking for.

    Also, not directly related to your question, but occasionally useful to
    know...

    The "test" portion of the cond construction is required, but the "result" is
    optional, and can contain any number of expressions. In any case, the last
    thing evaluated is what's returned. Sometimes it's handy to set it up so
    that in the last "fallback" condition, the test itself is returned.

    (cond
    ((test1)
    (result1))
    ....
    ((princ "None of the conditions were met!"))
    )
     
    Tom Smith, Sep 27, 2004
    #5
  6. Matt W

    Adesu Guest

    Hi Matt ,I have a format formula for "cond",here below

    (setq list_m4 '(7.0 6.5 4.0 3.0 2.4)
    list_m5 '(8.5 8.0 5.0 4.0 3.1)
    list_m6 '(10.0 9.5 6.0 5.0 3.78)
    list_m8 '(13.0 12.5 8.0 6.0 4.78)
    list_m10 '(16.0 15.5 10.0 8.0 6.25)
    list_m12 '(18.0 17.5 12.0 10.0 7.5)
    list_m14 '(21.0 20.5 14.0 12.0 8.6)
    list_m16 '(24.0 23.5 16.0 14.0 9.7)
    list_m20 '(30.0 29.5 20.0 17.0 11.8)
    list_m24 '(36.0 35.5 24.0 19.0 14.0))
    ;----------------------------------------------------
    (prompt "\ M4 M5 M6 M8 M10 M12 M14 M16 M20 M24")
    (setq typ (getstring "\SELECT TYPE OF BOLT <M10>: "))
    (setq bolt
    (cond ((= typ "M4")(setq lpm4 list_m4))
    ((= typ "M5")(setq lpm5 list_m5))
    ((= typ "M6")(setq lpm6 list_m6))
    ((= typ "M8")(setq lpm8 list_m8))
    ((= typ "M10")(setq lpm10 list_m10))
    ((= typ "M12")(setq lpm12 list_m12))
    ((= typ "M14")(setq lpm14 list_m14))
    ((= typ "M16")(setq lpm16 list_m16))
    ((= typ "M20")(setq lpm20 list_m20))
    ((= typ "M24")(setq lpm24 list_m24))
    ) ; end of cond
    ) ; end of setq
     
    Adesu, Oct 19, 2004
    #6
  7. Matt W

    David Kozina Guest

    Adesu,

    Just a suggestion - do a newsgroup search and read the help files regarding
    nested association lists and the assoc function. Tony Tanzillo and Michael
    Puckett have both posted some nice functions for accessing such types of
    lists. [It may not be a bad idea for you to also reload all the message
    headers in customization (consult the help files for your newsgroup reader
    as to how to do this), and, in your free time, read ALL the messages posted
    by TT and MP, as well as Doug Broad, Jon Fleming, Vladimir Nesterovsky, and
    many others you have found to be helpful here. Even if you do not
    understand what they are talking about - at least at first, I would still
    suggest you do it - you will be amazed by the depth and quality of
    information to be found here for novice programmers like us.]

    Best regards,
    David Kozina

     
    David Kozina, Oct 19, 2004
    #7
  8. Matt W

    Jürg Menzi Guest

    And see also my answers to you in thread:
    it is funny with alert, 07/29/2004
    and
    lowercase at "cond", 08/09/2004

    Cheers
     
    Jürg Menzi, Oct 19, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.