I wonder if i used 'if' too much?
Hi,
I'm working on improving my LISP as well so take what I say with a
grain of salt (and check me against the help file)

Regarding the "if" question... you can use
cond where you have a series
of options where only one is going to match. Similar to:
;-----------------------------------------------;
; Evaluate user input ;
;-----------------------------------------------;
; evaluate array mode and set values
(cond
((= mode "Calc")
(cond
((= typ "X")
(initget 1)
(setq qtx (getint "\nEnter Quantity on X axis: "))
(setvar "osmode" 191)
(initget 1)
(setq l (getdist "\nDistance on X axis or click points: ")
dist_X (/ l qtx))
(setvar "osmode" 0)
)
((= typ "Y")
(initget 1)
(setq qty (getint "\nEnter Quantity on Y axis: "))
(initget 1)
(setvar "osmode" 191)
(setq w (getdist "\nDistance on Y axis or click points: ")
dist_Y (/ w qty))
(setvar "osmode" 0)
)
((= typ "Grid")
(initget 1)
(setq qtx (getint "\nEnter Quantity on X axis: "))
(initget 1)
(setq qty (getint "\nEnter Quantity on Y axis: "))
(setvar "osmode" 191)
(initget 1)
(setq l (getdist "\nDistance on X axis or click points: ")
dist_X (/ l qtx))
(initget 1)
(setq w (getdist "\nDistance on Y axis or click points: ")
dist_Y (/ w qty))
(setvar "osmode" 0)
)
)
); mode Calc
((= mode "Mnl")
(cond
((= typ "X")
(initget 1)
(setq qtx (getint "\nEnter Quantity on X axis: "))
(setvar "osmode" 191)
(initget 1)
(setq dist_X (getdist "\nEnter offset distance on X axis or click points: "))
(setvar "osmode" 0)
)
((= typ "Y")
(initget 1)
(setq qty (getint "\nEnter Quantity on Y axis: "))
(setvar "osmode" 191)
(initget 1)
(setq dist_Y (getdist "\nEnter offset distance on Y axis or click points: "))
(setvar "osmode" 0)
)
((= typ "Grid")
(initget 1)
(setq qtx (getint "\nEnter Quantity on X axis: "))
(initget 1)
(setq qty (getint "\nEnter Quantity on Y axis: "))
(setvar "osmode" 191)
(initget 1)
(setq dist_X (getdist "\nEnter offset distance on X axis or click points: "))
(initget 1)
(setq dist_Y (getdist "\nEnter offset distance on Y axis or click points: "))
(setvar "osmode" 0)
)
)
); mode Mnl
); end mode cond
You can also find a lot of examples around here where people use
and to
continue executing statements until one returns nil as in:
(and
(do_this)
(do_that)
(do_the_other_thing)
)
where each of do_this, do_that and do_the_other_thing will happen as long
as the preceding statement does not return NIL.
Note the
and statement will return either T or NIL... not the result of the last
statement.
While I say this I will qualify with: I have not found it in my documentation
where execution is guaranteed to stop on the first NIL but it seems to work
for me. Perhaps someone with more knowledge than I can clarify if this is
the case and always was.
Have fun!