DEVITG, it'll be my pleasure.
As you might know, COND works like a select-case function:
(cond ((is this true?) (then do this))
((ok, so is this true?) (then do this))
((hmm, is this true then?) (then do this))
...
)
(setq a 7)
(cond ((= a 9)(princ "No way this is printed"))
((= 0 (rem a 2))
(princ "Nope, the remainder of 7/2 is not 0")
(princ "This will not be printed, either")
)
((= a (* 2 3.5))
(princ "Yeah, this is true! Print me!")
)
)
Sorry about the silly example, but have a look at the conditions and forget everything else. COND runs down the "list" of conditions and evaluates each one. When - or if - it finds a condition that is not nil, it will execute not only the condition but also any following statements and RETURN the value of the last statement.
Hence, the silly example above will print "Yeah, this is true! Print me!" to the screen.
Now, remove all following statements, leaving only the conditions:
(setq a 7)
(cond ((= a 9))
((= 0 (rem a 2)))
((= a (* 2 3.5)))
)
What will this return? Again, it runs down all conditions and evaluates them. When - or if - it finds a condition that is not nil, it executes not only the condition but .. ummm, wait, there are no following statements! So, it will simply return the value of the condition - which in this case is T.
Let's take a look at the innermost COND (of course, we'll include the INITGET, without which the GETKWORD makes no sense):
(initget "Left Right")
(cond ((getkword "\nElbow direction [Left/Right] <Right>: "))
("Right")
)
Notice that there are only conditions within the COND. But it doesn't matter because we just learned that COND will return the value of the first non-nil condition when there are no statements following the condition.
So, GETKWORD will switch to AutoCAD and await an answer. We can expect three different answers to arrive:
1. the user hits Enter and GETKWORD returns nil
2. the user types "Left" (or "L" or "Le" ...) and GETKWORD returns "Left"
3. the user types "Right" (or "R" ...) and GETKWORD returns "Right"
How will COND react to each of these answers? Let's take them in reverse order:
3. Because GETKWORD is the condition and it returns "Right", COND will see this as a non-nil value and return the result of the condition - which is "Right"
2. The same as 3., only that GETKWORD returns "Left".
1. If the user hits Enter and causes GETKWORD to return nil, COND will jump to the next condition which simply is the string "Right". A string is not a non-nil value and will therefore be returned by COND.
Because "Right" is offered as the default answer, it shall also be returned if the user hits Enter. This is accomplished by inserting "Right" as a condition.
The outermost COND simply says: if the innermost COND returns "Left" then do CCW, otherwise do CW. The latter is triggered by "Right", which is triggered by the user typing "R" or by hitting Enter.
The outermost COND could easily be written as an IF if it makes more sense:
(if (= "Left"
(cond ((getkword "\nElbow direction [Left/Right] <Right>: "))
("Right")
)
)
(ccw)
(cw)
)