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