Author Topic: Entmod & IF, why does it work?  (Read 2204 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Entmod & IF, why does it work?
« on: March 11, 2011, 06:42:13 PM »
Afternoon everyone,

I have been struggling with a simple task and am wondering why the IF statement doesn't need a PROGN when used in the ENTMOD function.
Here's an example:
Code: [Select]
              (entmod
                [color=green](if (assoc 8 (setq eList (entget ent)))[/color] ; testexpr
                  [color=purple](subst (cons 8 "Text") (assoc 8 eList) eList)[/color] ; thenexpr
                  [color=blue](append eList '((8 . "Text")))[/color] ; elseexpr
                )
              ) ; _entmod

According to the help file,
Quote
IF
Conditionally evaluates expressions
(if testexpr thenexpr [elseexpr])

So how does this end up running both scenarios, ...  or does it?
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Entmod & IF, why does it work?
« Reply #1 on: March 11, 2011, 07:15:33 PM »
It doesn't run them both. It is saying:

(entmod elist)

(elist) is being defined as either the original that HAS an (assoc 8) in the list modified to suit OR the original list with the new (assoc 8) dotted pair added to it)

(if (elist contains a value for (assoc 8))
   then change it
   else add it
)