TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: daron on November 05, 2003, 12:33:18 PM
-
In VBA, there is a way to make an argument optional.
Ex. Function test (Optional arg As Int)
You test this argument next in an IsMissing statement and do something to make the optional argument have a value.
What I want to know is can this be done in lisp?
Reason, I want to take a lisp routine that uses ssget and define an alias function like:
(defun c:vpl () (functionname)(princ))
or
(defun c:vpla () (functionname arg)(princ))
Thanks
-
Not sure I follow but, maybe something like this.
(defun fun (ss)
(if ss
(do this)
; else
(do something else)
)
)
You could do (fun nil) or (fun ss)
-
Yeah, that's what I thought. You have to always call the arguments contained. I'm reading a book on vba that mentions optional arguments. In that sense you don't need to call the argument when invoking the function, you just need to make sure the function sets the optional argument to something that will work. Kind of like a default value.
-
You can always pass a list as argument and handle the elements in an optional argument fashion.
-
I missed your reply Stig. Can you show me an example of what you mean. I'm not sure I follow you, here.
-
Well, it won't get rid of at least one argument.
Hmm, say you have routine that draws a single line between p1 and p2. The third "argument", if supplied, could be the layer to place the line on (I know, silly example). It should behave like (drawLine pt1 pt2 [layer]) but optional args not being an option, it could look like (drawLine args), where args is a list, either '(pt1 pt2) or '(pt1 pt2 layer).