Author Topic: Make an argment optional?  (Read 2093 times)

0 Members and 1 Guest are viewing this topic.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Make an argment optional?
« on: April 19, 2005, 02:07:16 PM »
How is this done?  I have a routine:

Code: [Select]
(defun FilterList (AList Filter  / TruncString )

(if (not Filter)
(alert "No Filter Set")
(progn
(setq FilterList '())
(foreach Obj Alist
(setq TruncString(substr(nth 0(TGS:StringToList(cdr Obj)";"))3 4))
(if (= (strcase Filter) TruncString)
(setq FilterList (cons Obj FilterList))
)
)
FilterList
)
)
)

that take 2 arguments but I only really need the first one all of the time.  If the second one is supplied then I want to use it.  How do I go about this?

BTW: This routine takes a list and a filter and checks the filter against a certian thing in the list if it matches the filter it adds it to a new list which will be sent to a list box.  The reason for the optional argument is if no filter is suppied I want the whole list sen to the listbox

Thanks
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Make an argment optional?
« Reply #1 on: April 19, 2005, 02:08:58 PM »
Pass but one argument, a list. Need more info than this?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Make an argment optional?
« Reply #2 on: April 19, 2005, 02:53:45 PM »
Some ideas ... coded blind / not tested, as I don't have one of the functions you're calling.

Code: [Select]
(defun FilterList ( arguments / filter result )

    ;;  first item in arguments is alist
    ;;
    ;;  second item in arguments is filter
   
    (cond
   
        (   (setq filter (cadr arguments))

            (foreach item (car arguments) ;; alist (implied)
           
                (if
                   
                    (eq (strcase filter)
                        (strcase
                            (substr    
                                (car
                                    (TGS:StringToList
                                        (cdr item)
                                        ";"
                                    )
                                )
                                3
                                4
                            )
                        )    
                    )
                   
                    (setq result
                        (cons
                            item
                            result
                        )
                    )
                )
            )
           
            ;;  even though you can have a local variable
            ;;  named the same as the function hosting it
            ;;  I think this is a better tact
           
            result
           
        )
        ((alert "No Filter Set"))
    )
)

;;  formerly you'd call FilterList thusly

(FilterList alist filter)

;;  now like so

(FilterList (list alist filter))

;;  or

(FilterList (list alist))
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
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.