@CodeDing wrote:
....
Is there a way that I can apply the COND function to an unknown list size?
...,
To that core question of how to use (cond) over a list of conditions of unknown length, which seems to be the goal, maybe the way to go is not to use (cond) itself if it's making itself difficult, but to simulate what (cond) does.
Taking your second function from Message 1, and putting the result into a thelist variable:
(setq thelist (mapcar 'list '(nil "1" "a")))
returns:
((nil) ("1") ("a"))
Then if we apply this [lightly tested]:
(setq done nil)
(while (and thelist (not done)); still something left, hasn't found non-nil test yet
(if (eval (caar thelist)); first item's first item is not, or does not evaluate to, nil
(progn ; then -- go with it
(setq done T); to stop (while) loop
(if (= (length (car thelist)) 1); no "result" code following test expression
(eval (caar thelist)); then -- return the item or what it evaluates to
(eval (cdr (eval (caar thelist)))); else -- run what follows test expression
); if
); progn
(setq thelist (cdr thelist)); else [nil] -- take first item off, check next
); if
); while
it returns "1" [for me], the first non-nil item in the list, as you would expect of (cond).
If we use your other case:
(setq thelist (mapcar 'list '(T "1" "a")))
it returns T.
I tried making it more complicated, such as to define something with a test expression and something arbitrary to do if it's non-nil [as one would expect to encounter within a (cond) function]:
(setq test '("1" (command "_.zoom" "_extents") (setvar 'cecolor "2")))
Then I put that test variable into thelist:
(setq thelist (mapcar 'list (list what test "1" "a")))
The what is a non-existent variable, for trial purpose. When I run the code above, it bypasses what for returning nil, and runs what's in the TEST after its initial test expression that is not nil, that is, it does the ZOOM command and System Variable setting called for in it.
Kent Cooper, AIA