Jump to content

Understanding Lee Mac's coding?


Recommended Posts

Posted

Hello all,

 

While trying to learn ALOT of Lee Mac's his coding, i came across this very 'simple' piece of code...

 

;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object

(defun LM:acdoc nil
   (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
   (LM:acdoc)
)

 

Why is this code so 'complex' and isnt it just defined as:

(defun LM:acdoc ( / )
 (vla-get-activedocument (vlax-get-acad-object))
)

 

Since it seems to return the same value??

Posted

Hi Aftertouch

 

If already a function LM:acdoc (may be some old function) is loaded,

it will be replaced by Lee Mac's coding LM:acdoc (latest coding).

 

Its my understanding.

Posted (edited)

Welcome to learn LeeSp :D

 

I think Lee calls this a "run-time evaluation". The key is what happens when for the first time (LM:acdoc) is called.

 

Here are some observations from the console:

[s]_$ (defun printhello nil
 (eval (list 'defun 'printhello 'nil (print "Hello")))
 (printhello)
)
PRINTHELLO
_$ (printhello)

[color="red"]"Hello" "Hello"[/color] [color="green"]; !!![/color]
_$ (printhello)
[color="red"]"Hello"[/color]         [color="green"]; now it exits cleanly?[/color]
_$ (printhello)
[color="red"]"Hello"[/color]
_$ (printhello)
[color="red"]"Hello"[/color][/s]

 

[s]_$ (defun printhello nil
 (print "Hello")
)
PRINTHELLO
_$ (printhello)

[color="red"]"Hello" "Hello"[/color]
_$ (printhello)

[color="red"]"Hello" "Hello"[/color]
_$ (printhello)

[color="red"]"Hello" "Hello"[/color][/s]

 

Further than this my knowledge is restrained, so it would be nice if someone explained why he uses this.

Edited by Grrr
Posted

@Grrr:

Maybe this helps to explain your 'clean exit' issue?:

(type (print "Hello")) => STR

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.

Posted

Roy,

 

Thanks - now I see that my observation brings more confusion to this. So no difference in the returns:

_$ (defun test nil
 (eval (list 'defun 'test 'nil "return_this_string"))
 (test)
)
TEST
_$ (test)
"return_this_string"
_$ (test)
"return_this_string"
_$ (test)
"return_this_string"

_$ (defun test nil
 "return_this_string"
)
TEST
_$ (test)
"return_this_string"
_$ (test)
"return_this_string"
_$ (test)
"return_this_string"

 

And I'll stick to your message:

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

Alright, We got this case solved. Thanks for the toughts!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...