Author Topic: Indeterminate number of arguments?  (Read 6554 times)

0 Members and 1 Guest are viewing this topic.

whdjr

  • Guest
Indeterminate number of arguments?
« on: October 07, 2004, 11:57:12 AM »
How would you setup a function to accept an indeterminate number of arguments?

ex:

(this_function arg1 arg2 arg3)
or
(this_function arg1 arg2)

Where this_function is the same function.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Indeterminate number of arguments?
« Reply #1 on: October 07, 2004, 12:04:38 PM »
Code: [Select]
(defun MyFunction ( ParameterList  / NumberOfParameters )
    (cond
        (   (eq 4 (setq NumberOfParameters (length ParameterList)))
            ;;  4 parameters
        )
        (   (eq 3 NumberOfParameters)
            ;;  3 parameters
        )
        ...
    )
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Indeterminate number of arguments?
« Reply #2 on: October 07, 2004, 12:05:47 PM »
in lisp you don't unless you send your arguments as a list ....

Code: [Select]

(defun myproggie ( argumentlist )
 ;;;do stuff here
)


then call it like so...

Code: [Select]

(myproggie (list arg1 arg2 arg3 ..... ))
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

whdjr

  • Guest
Indeterminate number of arguments?
« Reply #3 on: October 07, 2004, 12:10:58 PM »
Very snazzy thinking.
I'll have to try that.

Thanks guys.

whdjr

  • Guest
Indeterminate number of arguments?
« Reply #4 on: October 07, 2004, 12:13:15 PM »
I noticed in some of the express tools they call a function that could accept 2, 3, or 4 arguments, but they don't supply it as a list.

What gives?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Indeterminate number of arguments?
« Reply #5 on: October 07, 2004, 12:16:22 PM »
dang MP you beat me to it..
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Indeterminate number of arguments?
« Reply #6 on: October 07, 2004, 12:17:27 PM »
some expresstools are written as ARX programs... (in C++) you can have a variable number of arguments to C++ programs.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Indeterminate number of arguments?
« Reply #7 on: October 07, 2004, 12:20:36 PM »
Quote from: whdjr
I noticed in some of the express tools they call a function that could accept 2, 3, or 4 arguments, but they don't supply it as a list.

What gives?

You can write functions / procedures in C++ that have a variable number of arguments. You can in VB6 as well, but some of the express tools (ET) functions you refer to are (most likely) written in ARX (C++ based).

By the way I cannot recommend the use of  ET functions to anyone doing serious development. You cannot count on them being on a given computer, and when they're not; *poof* your program is instantly lobotomized; cannot run. So my advice is to stay as far away from ET stuff as possible, despite the presence of some useful stuff. If you need 3rd party tools consider using DOSLIB.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

whdjr

  • Guest
Indeterminate number of arguments?
« Reply #8 on: October 07, 2004, 12:29:33 PM »
I use it mainly for reference.
If there is something I can't live without I try to track what they did and rewrite it for my use.

Thanks for the warning though.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Indeterminate number of arguments?
« Reply #9 on: October 07, 2004, 12:42:51 PM »
Quote from: whdjr
I use it mainly for reference.
If there is something I can't live without I try to track what they did and rewrite it for my use.

Thanks for the warning though.

Here is some more reference 8)
http://theswamp.org/phpBB2/viewtopic.php?t=1922&highlight=number+arguments
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Indeterminate number of arguments?
« Reply #10 on: October 07, 2004, 01:04:01 PM »
Interesting thread CAB, but I must say that in all my years programming (now sadly measured in decades) I've found very few scenarios that ultimately required a function / procedure that would accept a variable number of arguments, at least very few that couldn't be solved by re-examining the problem and solution(s).

Still, it's an interesting read and if you do have one need that is more elegantly solved going this route it's useful info; thanks.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Indeterminate number of arguments?
« Reply #11 on: October 07, 2004, 01:21:28 PM »
Well there wasn't so much a need for this but a curiosity. Asking Why not.
And the next thing you know we are off on a 'Wild Goose Chase'.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

David Bethel

  • Swamp Rat
  • Posts: 656
Indeterminate number of arguments?
« Reply #12 on: October 07, 2004, 04:02:08 PM »
MP,

I use a single list parameter quite often just so I can have a varable number of parameters.

Code: [Select]
(setq data '("X20" "Y28" "Z14" "L24" "R36" "B3" "S12"))

(defun my_foo (input / x y z q w l d)

  (foreach a input
      (setq dtype (strcase (substr a 1 1)))
      (cond ((= dtype "X") (setq x (atoi (substr a 2))))
            ((= dtype "Y") (setq y (atoi (substr a 2))))
;;And so on
)

;;;And then make defaults for the missing atoms

(if (not r) (setq r 36))

;;;Or simply ingore them as that they are not needed for this particular style of the model



-David
R12 Dos - A2K

Columbia

  • Guest
Indeterminate number of arguments?
« Reply #13 on: October 08, 2004, 09:37:00 AM »
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...

Code: [Select]

(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...

Code: [Select]

(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.

Code: [Select]

(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...

Code: [Select]


;;; 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...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Indeterminate number of arguments?
« Reply #14 on: October 08, 2004, 10:59:23 AM »
I like the idea.
I would add Diameter to the list & test for (or Radius Diameter)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.