Author Topic: Testing argument  (Read 2693 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Testing argument
« on: October 12, 2004, 09:28:16 AM »
I want to test to see what the user suplied to my function. If i have a nested procedure, that i alow the user to call, how can i test to see if what they typed is correct? This is what i have returned to me: #<USUBR @03591474 ...>. I cant think of a good way to test to see if the supplied is actualy my nested procedure name.

...Tell ya what, here is a brief example.

Code: [Select]
(defun main-proc (arg)
  ;; nest a procedure.
  (defun nested-proc ()
    (princ "Hi, I'm talking to you from a nested procedure."));_ end defun

  (if (eq arg 'nested-proc) ; <-- this obviously dosent work...
    ;; if the argument suplied is "nested-proc" then we are good
    ;; and can call our nesteed procedure.
    (arg)
    );_ end if
  );_ end defun
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Testing argument
« Reply #1 on: October 12, 2004, 10:17:26 AM »
Try this ....
Code: [Select]
(defun main-proc (arg)
  (defun nested-proc ()
    (princ "Hi, I'm talking to you from a nested procedure."))
  (if (eq (read arg) 'nested-proc)
    (eval (list(read arg)))
  )
)
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

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Testing argument
« Reply #2 on: October 12, 2004, 10:49:28 AM »
Using that way, i would have to supply the main with a string.  I cant do that; Im actualy doing some teting/work on some higher order stuff.  --more specificaly, the use of "free variables" instead of "bound variables" but i ran into a small snag...
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Testing argument
« Reply #3 on: October 12, 2004, 10:54:10 AM »
Make sure you test main-proc for recursive calls too. :twisted:
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
Testing argument
« Reply #4 on: October 12, 2004, 11:08:58 AM »
Let me see if I get this straight ....
You are defining a sub-routine local to the main routine, which will be executed when you call the main routine from where?
Can you not use...
Code: [Select]
(main-proc "this-proggie")

or do you want to use
Code: [Select]
(defun this-proggie() (princ "\nDo something))
(main-proc this-proggie)


I think I am confused ...

but maybe this is more to your liking ...
Code: [Select]

(defun main-proc (arg)
(defun nested-proc ()
(princ "Hi, I'm talking to you from a nested procedure."))
(if (eq (type arg) 'SUBR)
(arg)
)
)
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

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Testing argument
« Reply #5 on: October 12, 2004, 05:37:49 PM »
Im sorry, I got busy after lunch. But I did some more thinking and at lunch Jenny called so i never got arround to posting this.

The reason  im doing this is because the article i was working on turned into crap, so i thhought i would do some playing arround with the subject of a procedures "formal parameters" (arguments) and the Free vs Bound Variables procedure design.

But this is what i came up with sofar.

Code: [Select]
;;; Subject of thought:
;;; ---------------------
;;; The use of Free Variables to design "methods" instead
;;; of designing/using black-box procedures. --which may
;;; cause cross referencing and the inability to remove a
;;; method in whole from a application.
;;;
;;; Testing procedure:
;;; ---------------------
;;; Line "object"?!
;;;
;;; This is modeled after the basic premise of a CLASS in OOP; in that
;;; this procedure will handle the entity in itself and return the desired info.
;;; You call this procedure and give the public procedure to perform on
;;; that 'object'.  This is only a working idea about how to structure a
;;; procedure to operate on Free variables instead of building black-box
;;; procedures that operate on bound variables.
;;;
;;; Design Criteria:
;;; ---------------------
;;; - Offer public functions for a line "obj" allowing the retrieval of;
;;;   o A line if no entity is been retrieved.
;;;   o The Start point
;;;   o The Endpoint
;;; - Be smart enough to have some small level of control and intelligence.
;;;
;;; Version I:
;;; ---------------------
;;;
;;; line
;;; arg - The public function to be called.
;;; ent - given if startpoint or endpoint is requested.
;;;       otheriwise nil.
;;; Command: (line `get nil)
;;; Select object: <Entity name: 7ef6d358>
(defun line (arg ent / ent)
   ;; local helper functions
   (defun GetData (code entity)
     (cdr (assoc code (entget entity))))
   ;; public function of "object"
    (defun `get () (setq ent (car (entsel))))
   ;; get a selected entity from the user
    (defun `startpt () (GetData 10 ent))
   ;; retrieve the startpoint of the entitiy
    (defun `endpt () (getdata 11 ent))
   ;; retrieve the endpoint of the entity
  (arg)
 )

;;; Version II
;;; Begin testing for argument values before calling procedure.
(defun line (arg ent / ent)
   ;; local helper functions
   (defun GetData (code entity)
     (cdr (assoc code (entget entity))))
   ;; public function of "object"
    (defun `get () (setq ent (car (entsel))))
   ;; get a selected entity from the user
    (defun `startpt () (GetData 10 ent))
   ;; retrieve the startpoint of the entitiy
    (defun `endpt () (getdata 11 ent))
   ;; retrieve the endpoint of the entity
  (if (= ent 'nil)
    ;; if the ent is nil -- the user must not have selected anything yet.
    (if (= (type arg) 'USUBR) ; check to see if the arg is a sub
      (arg) ; if it is, then run it
      (setq ent (`get))); If the arg isnt a subrut then assign to `get
    )
 )

;;; Version III
;;; Testing the value of the arguments has obvious limitations and should
;;; be re-thunk.
(defun line (arg ent / ent)
  ;; local helper functions
   (defun GetData (code entity)
     (cdr (assoc code (entget entity))))
  ;; public function of "object"
   (defun `get () (setq ent (car (entsel))))
   ;; get a selected entity from the user
   (defun `startpt ()
     (cond
       ((eq ent nil)
        (GetData 10 (`get)))
       ((T (GetData 10 ent)))))
   ;; retrieve the startpoint of the entitiy
   (defun `endpt ()
     (cond
       ((eq ent nil)
        (GetData 11 (`get)))
       ((T (GetData 11 ent)))))
;;; @@@@ ====================================================================== @@@@ ;;;
;;; @@@@ Non, of this testing is necessary; preform check in nested procedures! @@@@ ;;;
;;; @@@@ ====================================================================== @@@@ ;;;
   ;; retrieve the endpoint of the entity
;;;  (if (= ent 'nil)
    ;; if the ent is nil -- the user must not have selected anything yet.
;;;    (if (= (type arg) 'USUBR) ; check to see if the arg is a sub
;;;      (arg) ; if it is, then run it
;;;      (setq ent (`get))); If the arg isnt a subrut then assign to `get
      (arg)
;;;    )
 )

;;;
;;; Over all thoughts/discoveries:
;;; It's futile to test to see what argument is given to a procedure.
;;; Greater control is achieved with a combination of both testing inside
;;; the nested procedures and before the procedure call.
;;;
;;; Using Free variables allows for greater "share-ability" of procedures/methods.
;;; -ie it eliminates the black-box use of procedures in apps.
;;;
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org