TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: daron on November 05, 2003, 12:33:18 PM

Title: optional argument like vba
Post 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
Title: optional argument like vba
Post by: Mark on November 05, 2003, 01:22:46 PM
Not sure I follow but, maybe something like this.
Code: [Select]

(defun fun (ss)
  (if ss
     (do this)
     ; else
     (do something else)
   )
)


You could do (fun nil) or (fun ss)
Title: optional argument like vba
Post by: daron on November 05, 2003, 01:33:44 PM
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.
Title: optional argument like vba
Post by: SMadsen on November 06, 2003, 05:47:57 AM
You can always pass a list as argument and handle the elements in an optional argument fashion.
Title: optional argument like vba
Post by: daron on November 11, 2003, 11:24:10 AM
I missed your reply Stig. Can you show me an example of what you mean. I'm not sure I follow you, here.
Title: optional argument like vba
Post by: SMadsen on November 11, 2003, 02:02:09 PM
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).