Author Topic: optional argument like vba  (Read 5566 times)

0 Members and 1 Guest are viewing this topic.

daron

  • Guest
optional argument like vba
« 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

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
optional argument like vba
« Reply #1 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)
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
optional argument like vba
« Reply #2 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.

SMadsen

  • Guest
optional argument like vba
« Reply #3 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.

daron

  • Guest
optional argument like vba
« Reply #4 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.

SMadsen

  • Guest
optional argument like vba
« Reply #5 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).