(_DisEval
'(defun AcDoc nil
(vla-get-ActiveDocument (vlax-get-acad-object))
)
)
>> (LIST (QUOTE DEFUN) (QUOTE ACDOC) nil (LIST (QUOTE vla-get-ActiveDocument) (LIST (QUOTE vlax-get-acad-object))))
>> Pretty-printed:
(LIST 'DEFUN 'ACDOC nil
(LIST 'vla-get-ActiveDocument (LIST 'vlax-get-acad-object))
)
(_DisEval
'(LM:ssget "\nSelect lines, arcs and/or polylines to extend: "
'("_:L"
(
(-4 . "<OR")
(0 . "LINE,ARC")
(-4 . "<AND")
(0 . "LWPOLYLINE")
(-4 . "<NOT")
(-4 . "&=") (70 . 1)
(-4 . "NOT>")
(-4 . "AND>")
(-4 . "<AND")
(0 . "POLYLINE")
(-4 . "<NOT")
(-4 . "&=") (70 . 87)
(-4 . "NOT>")
(-4 . "AND>")
(-4 . "OR>")
)
)
)
)
>>
(LIST 'LM:SSGET
'"\nSelect lines, arcs and/or polylines to extend: "
(LIST 'QUOTE
(LIST '"_:L"
(LIST
(CONS -4 "<OR")
(CONS 0 "LINE,ARC")
(CONS -4 "<AND")
(CONS 0 "LWPOLYLINE")
(CONS -4 "<NOT")
(CONS -4 "&=")
(CONS 70 1)
(CONS -4 "NOT>")
(CONS -4 "AND>")
(CONS -4 "<AND")
(CONS 0 "POLYLINE")
(CONS -4 "<NOT")
(CONS -4 "&=")
(CONS 70 87)
(CONS -4 "NOT>")
(CONS -4 "AND>")
(CONS -4 "OR>")
)
)
)
)
_$ (eval (eval (eval (eval (eval (_DisEval (_DisEval (_DisEval (_DisEval '(ssget "_:L-I" '((0 . "CIRCLE")(8 . "0"))))))))))))
<Selection set: 2f>
_$ ( (lambda (n c / r ) (setq r c) (repeat n (setq r (_DisEval r))) r) 5
'(defun AcDoc nil
(vla-get-ActiveDocument (vlax-get-acad-object))
)
)
(LIST
'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'LIST))
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'LIST))
)
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'LIST))
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
)
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'DEFUN))
)
)
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'LIST))
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
)
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'ACDOC))
)
)
nil
(LIST
'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'LIST))
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'LIST))
)
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'LIST))
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
)
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
(LIST 'LIST
(LIST 'QUOTE 'QUOTE)
(LIST 'QUOTE 'vla-get-ActiveDocument)
)
)
)
(LIST
'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'LIST))
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'LIST))
)
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'LIST))
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
)
(LIST 'LIST
(LIST 'QUOTE 'LIST)
(LIST 'LIST (LIST 'QUOTE 'QUOTE) (LIST 'QUOTE 'QUOTE))
(LIST 'LIST
(LIST 'QUOTE 'QUOTE)
(LIST 'QUOTE 'vlax-get-acad-object)
)
)
)
)
)
)
_$ ( (lambda (n c / r ) (setq r c) (repeat n (setq r (eval r))) r) 7 ; try from 5 up to 7
( (lambda (n c / r ) (setq r c) (repeat n (setq r (_DisEval r))) r) 5
'(defun AcDoc nil
(vla-get-ActiveDocument (vlax-get-acad-object))
)
)
);; (lambda)
#<USUBR @0000001c064381b0 ACDOC>
(mapcar 'eval
(eval
(eval
(_DisEval
'(list
;; Bunch of codes...
(defun AcObj nil
(vlax-get-acad-object)
)
(defun AcDoc nil
(vla-get-ActiveDocument (vlax-get-acad-object))
)
(defun AlertHello nil
(alert "Hello")
)
(defun SayHi nil
(princ "Hi")
)
;; ... bunch of codes
); list
)
)
)
)
(mapcar 'eval
(eval
(eval
(_DisEval
'(list
;; i.e. paste the whole lisp content from here:
;; http://www.lee-mac.com/lisp/html/2DProjectionV1-0.html
); list
)
)
)
)
> Command: (setq a (hook '(+ 1 2)))
> ((LAMBDA nil (+ 1 2)))
>
> Command: (eval a)
> 3
>
> Command: (setq a (hook '(+ 1 2))
> (_> b (hook '(+ 1 3))
> (_> c (hook '(+ 1 4))
> (_> d (hook '(+ 1 5))
> (_> e (hook '(+ 1 6))
> (_> f (hook '(+ 1 7)))
> ((LAMBDA nil (+ 1 7)))
>
> Command: (mapcar 'eval (mapcar 'eval '(a b c d e f)))
> (3 4 5 6 7 8)
Personal preference that’s presumably ok with the lisp police.
... specific expressions are evaluated <at declaration time> ... whilst others are evaluated <at run time> ...
(defun mp-get-owner-1 ( object / owner )
(vl-catch-all-apply
(function
(lambda ( )
(setq owner
(vla-objectidtoobject
(vla-get-activedocument (vlax-get-acad-object))
(vla-get-ownerid object)
)
)
)
)
)
owner
)
(defun mp-get-owner-2 ( object )
(eval
(list 'defun 'mp-get-owner-2 '( object / owner )
(list 'vl-catch-all-apply
(list 'function
(list 'lambda nil
(list 'setq 'owner
(list
'vla-objectidtoobject
(vla-get-activedocument (vlax-get-acad-object))
(list 'vla-get-ownerid 'object)
)
)
)
)
)
'owner
)
)
(mp-get-owner-2 object )
)
(setq obj (vlax-ename->vla-object (car (entsel))))
(mp-benchmark
'(
(mp-get-owner-1 obj)
(mp-get-owner-2 obj)
)
)
Elapsed milliseconds / relative speed for 32768 iteration(s):
(MP-GET-OWNER-2 OBJ).....1125 / 1.35 <35% faster>
(MP-GET-OWNER-1 OBJ).....1516 / 1.00 <slowest>
(did multiple tests, observed everything from 29-41% speed increase).
*sigh* ...I'm beginning to think people believe "obfuscation" equals "better".It's not really that at all ... it's very legible to me :? \disclaimeraside ... not catering to others.
_$
Benchmarking ...................Elapsed milliseconds / relative speed for 65536 iteration(s):
(OR *ACADOBJECT* (SETQ *ACADOBJECT* ...).....1344 / 1.06 <fastest>
(SETQ *ACADOBJECT* (COND (*ACADOBJEC...).....1422 / 1.00 <slowest>
; 1 form loaded from #<editor "<Untitled-0> loading...">
_$
I always wondered why you smart mother truckers did the fancy 'eval shite .. going to have to look into this closer. *beers*Code: [Select](defun mp-get-owner-1 ( object / owner )
(vl-catch-all-apply
(function
(lambda ( )
(setq owner
(vla-objectidtoobject
(vla-get-activedocument (vlax-get-acad-object))
(vla-get-ownerid object)
)
)
)
)
)
owner
)Code: [Select](defun mp-get-owner-2 ( object )
(eval
(list 'defun 'mp-get-owner-2 '( object / owner )
(list 'vl-catch-all-apply
(list 'function
(list 'lambda nil
(list 'setq 'owner
(list
'vla-objectidtoobject
(vla-get-activedocument (vlax-get-acad-object))
(list 'vla-get-ownerid 'object)
)
)
)
)
)
'owner
)
)
(mp-get-owner-2 object )
)Code: [Select](setq obj (vlax-ename->vla-object (car (entsel))))
(mp-benchmark
'(
(mp-get-owner-1 obj)
(mp-get-owner-2 obj)
)
)
Elapsed milliseconds / relative speed for 32768 iteration(s):
(MP-GET-OWNER-2 OBJ).....1125 / 1.35 <35% faster>
(MP-GET-OWNER-1 OBJ).....1516 / 1.00 <slowest>
(did multiple tests, observed everything from 29-41% speed increase).
TLDR: Wifey says speed isn't everything.
An aside, I prefer encapsulating objects when applicable, eliminates superfluous processing and it's tidy; win.
smart
mother trucker
*beers*
:-Dsmart
debatablemother trucker
irrefutable*beers*
*clank*
Whilst I applaud the code you have shared, note that quoting every nested expression in the supplied list is not quite achieving the same result as both mine & MP's example functions, in which certain specific expressions are evaluated immediately as part of the function definition (e.g. references to objects, such as the active document object), whilst others are evaluated when the function itself is evaluated.
Consider the difference in the result of the following function definitions, as may be illustrated through the use of defun-q:Code - Auto/Visual Lisp: [Select]
...
*sigh* ...I'm beginning to think people believe "obfuscation" equals "better".
Code: [Select](defun LM:acdoc nil
When first called, Lee's LM:acdoc function redefines itself. The new definition directly returns the active document object and is therefore a (minute) bit faster than the less complex function proposed by Aftertouch.
(eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
(LM:acdoc)
)
Code: [Select](setq obj (vlax-ename->vla-object (car (entsel))))
(mp-benchmark
'(
(mp-get-owner-1 obj)
(mp-get-owner-2 obj)
)
)
Elapsed milliseconds / relative speed for 32768 iteration(s):
(MP-GET-OWNER-2 OBJ).....1125 / 1.35 <35% faster>
(MP-GET-OWNER-1 OBJ).....1516 / 1.00 <slowest>
(did multiple tests, observed everything from 29-41% speed increase).
TLDR: Wifey says speed isn't everything.
An aside, I prefer encapsulating objects when applicable, eliminates superfluous processing and it's tidy; win.
p.s. self modifying functions will not work if compiled with option 'Optimize and link' set
p.p.s. a way around is to setq function to nil before redefining
No `encapsulating' is not the proper term. Encapsulating a methodology reserved for OOP and classes;
it has to do with public and private methods exposed to API users (getter's and setter's).
... I went back to university a number of years ago and formally studied OOP technologies.
Adopting and perpetuating bad programming practice--especially under the guise of "better than"--is not good for anyone.