View Full Version : What is advantage and disadvantage use this
Adesu
2006-07-13, 03:08 AM
I hope get asnwerd from expert in lisp,especially if we use this code system,I got this code from "Rkmcswain_codes".
and what is the best for use in code model 1 or model 2
MODEL 1
(defun c:labelme (/ bla..bla)
(defun format2sta (n / b a x)
(bla..bla..bla)
)
(bla..bla..bla)
)
MODEL 2
(defun format2sta (n / b a x)
(bla..bla..bla)
)
(defun c:labelme (/ bla..bla)
(setq bla (format2sta bla))
(bla..bla..bla)
)
rkmcswain
2006-07-13, 04:11 AM
In Model 1 - (format2sta) is a local function
In Model 2 - (format2sta) is a global function
Sorry if that isn't expert enough for you... ;)
...what is the best for use in code model 1 or model 2
R.K. answered the global/local issue so I'll address this with a very definitive:
It Depends
If you are writing code for others and you don't wish your functions used by others, one way to do this is by embedding the function within the calling function....thereby making it a Local function.
However, if this function is one that can/will be utilized in other routines more than just a few times, it is often better to make it a global function so the same function need be loaded only once and can be called from any other routine.
HTH,
Jeff
Adesu
2006-07-14, 02:45 AM
R.K. answered the global/local issue so I'll address this with a very definitive:
It Depends
If you are writing code for others and you don't wish your functions used by others, one way to do this is by embedding the function within the calling function....thereby making it a Local function.
However, if this function is one that can/will be utilized in other routines more than just a few times, it is often better to make it a global function so the same function need be loaded only once and can be called from any other routine.
HTH,
Jeff
Hi Jeff &Rkmcswain,
Thanks a lot for your both comment,it need to add memory in my brain,yes I understand,but I prefer like to system model 2.
Hi Jeff &Rkmcswain,
Thanks a lot for your both comment,it need to add memory in my brain,yes I understand,but I prefer like to system model 2.
If you use a lot of global functions, you will need to supply those functions when sharing any routines that reference them. Two common routines that seem to be forgotten by myself and others is converting Degrees to Radians and Radians to Degrees.
rkmcswain
2006-07-14, 03:34 AM
Hi Jeff &Rkmcswain,
Thanks a lot for your both comment,it need to add memory in my brain,yes I understand,but I prefer like to system model 2.
To echo Jeff's comments, it's really not a matter or "preference" IMO, but rather of needs or design. There is no need to pollute the lisp environment with a function that is only used within a larger function.
I suppose another way of doing that might be to use the (lambda) function inline.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.