How to Make Several Expressions Act like OneThere will be times when you will want several expressions to be evaluated depending on the results of a predicate. As an example, lets assume that you have decided to make the 2 dimensional and 3 dimensional box programs part of the C:MAINBOX program to save memory. You could place the code for these functions directly in the C:MAINBOX program and have a file that looks like figure 5.5. When this program is run, it acts exactly the same way as in the previous exercise. But in figure 5.4, thefunctions BOX1 and 3DBOX are incorporated into the if expression as arguments.
<
(defun C:MAINBOX (/ pt1 pt2 pt3 pt4 h choose)
(setq choose (getstring "\nDo you want a 3D box <Y=yes/Return=no>? "))
(if (or (equal choose "y")(equal choose "Y"))
(progn ;if choose = Y or y then draw a 3D box
(getinfo)
(setq h (getreal "Enter height of box: "))
(procinfo)
(output)
(command "change" "Last" "" "Properties" "thickness" h ""
"3dface" pt1 pt2 pt3 pt4 ""
"3dface" ".xy" pt1 h ".xy" pt2 h
".xy" pt3 h ".xy" pt4 h ""
);end command
);end progn
(progn ;if choose /= Y or y then draw a 2D box
(getinfo)
(procinfo)
(output)
);end progn
);end if
);end MAINBOX
We are able to do this using the progn function. Progn allows you to have several expression where only one is expected. Its syntax is as follows:
(progn
(expression1) (expression2) (expression3) . . .
)
Next -> How to Test Multiple Conditions