Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
aesh
Posts: 18
Registered: ‎02-03-2012
Message 1 of 3 (107 Views)
Accepted Solution

Unexpected result from "OR"

107 Views, 2 Replies
02-29-2012 02:35 PM

Has anyone run into this before?

 

I'm making a conditional statement for a list, but when I add the 'or' operator, it applies the action to all the values, not just the ones I called in the statement.

 

I'm starting with this and it works fine:

(start_list "a2")
  (cond
    ((= val "0")
    (add_list "1/8"))

    ((= val "1")
    (add_list "1/8"))

    ((= val "2")
    (add_list "1/8")(add_list "3/16")(add_list "1/4"))  etc...

  );cond
(end_list)

 but when I change it to this, it applies the first action to ALL the values and disregards the rest of the statement:

 

      (start_list "a2")
        (cond
          (or (= val "0")(= val "1")
          (add_list "1/8"))

          ((= val "2")
          (add_list "1/8")(add_list "3/16")(add_list "1/4"))  etc...
           
        );cond
      (end_list)

 

I think your test condition isn't wrapped correctly.  The brackets around the (or...) statment should include the two conditional tests, and there should be another set of parent brackets wrapping the (or...) and the resulting (add_list...) call.  Each branch of a (cond...) is effectively a list, with the first element in that list the test to see if the rest of the elements of that list are to be evaluated.

*Expert Elite*
dgorsman
Posts: 5,512
Registered: ‎10-12-2006
Message 2 of 3 (106 Views)

Re: Unexpected result from "OR"

02-29-2012 02:50 PM in reply to: aesh

I think your test condition isn't wrapped correctly.  The brackets around the (or...) statment should include the two conditional tests, and there should be another set of parent brackets wrapping the (or...) and the resulting (add_list...) call.  Each branch of a (cond...) is effectively a list, with the first element in that list the test to see if the rest of the elements of that list are to be evaluated.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Contributor
aesh
Posts: 18
Registered: ‎02-03-2012
Message 3 of 3 (99 Views)

Re: Unexpected result from "OR"

02-29-2012 03:41 PM in reply to: dgorsman

That did the trick, 

 

Thank you!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.