Code Red > AutoLISP (Vanilla / Visual)

optional argument like vba

(1/2) > >>

daron:
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

Mark:
Not sure I follow but, maybe something like this.

--- Code: ---
(defun fun (ss)
  (if ss
     (do this)
     ; else
     (do something else)
   )
)

--- End code ---


You could do (fun nil) or (fun ss)

daron:
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.

SMadsen:
You can always pass a list as argument and handle the elements in an optional argument fashion.

daron:
I missed your reply Stig. Can you show me an example of what you mean. I'm not sure I follow you, here.

Navigation

[0] Message Index

[#] Next page

Go to full version