In doing some serious development I have found a very large need for the use of a variable argument list.
Let me explain just a little, and maybe you can see my point (or think I'm just plain nutsoid
)
Anyway... I use the Active-X entity creation routines (vla-addLine, vla-addCircle, etc...) to automate my entity creation libraries. So now what I have is a function sort of like this...
(defun Util-Add-Circle (/ activeSpaceObject centerPoint radius returnObject)
....
(setq returnObject
(vla-addCircle
activeSpaceObject
(vlax-3d-point centerPoint)
radius
)
)
)
So now I use this function in the following manner...
(defun DoSomething (/ pt rad)
(setq pt (getpoint "\nPick center point...")
radius (getdistance "\nEnter radius: ")
)
(Util-Add-Circle pt radius)
)
But now I want to change the properties of the newly added function so I add the following lines to the DoSomething function.
(defun DoSomething (/ pt rad o)
(setq pt (getpoint "\nPick center point...")
radius (getdistance "\nEnter radius: ")
)
(setq o (Util-Add-Circle pt radius))
(vla-put-layer o "NewLayer")
(vla-put-Color o acRed)
)
I kept finding that cumbersome in every single drawing routine I had. I wasn't sure that would always want to change the same number of properties in the function so I re-wrote the Util-Add-Circle routine to take a dotted pair list of properties. That way I can have a dynamic list of properties that I want to change at runtime. I just need to make sure that the center point and the radius arguments are always supplied. But that's only small error trapping/checking. But to illustrate my point just a little...
;;; function call
(Util-Add-Circle (list (cons "Center" pt) (cons "Radius" 0.3) (cons "Layer" "NewLayer") (cons "Color" acRed)))
(defun Util-Add-Circle (propList)
(vla-addCircle
activeSpaceObject
(vlax-3d-object (cdr (assoc "Center" propList)))
(cdr (assoc "Radius" propList))
)
(mapcar '(lambda (x) (vlax-put-property (car x) (cdr x)) propList)
)
Of course, this snippet is not really complete. The proplist should have the "Center" and "Radius" atoms removed from the list before the mapcar is applied. And there is not sufficient error trapping. But I wanted to deliver here was a viable and most definitely usable way to illustrate the need for variable argument lists. However, I'm not going to try to say that these argument lists can or even should be used every where. But there applicable locations.
I hope I didn't confuse the issue any...