Functon in function

Functon in function

saitoib
Advocate Advocate
755 Views
2 Replies
Message 1 of 3

Functon in function

saitoib
Advocate
Advocate

Hi all!

Sorry for the rudimentary question, but...

 

In Lisp, a lot of people define functions inside functions, is there an advantage over defining them outside functions?

I'm confused because I don't see this method in general programming.

 

Thank you.

Saitoib
0 Likes
Accepted solutions (1)
756 Views
2 Replies
Replies (2)
Message 2 of 3

hak_vz
Advisor
Advisor
Accepted solution
(defun main_function (parameter_1 / local_function local_variable)
(defun local_function ()

)
)

This way we create localized function that is part of main function so it can not affect some other code that may have functions or variables defined with same name. This is common practice in other languages, let say javascript.

When you create your code you can have outer function that when finished you make local. It is a good an proposed code writing practice. 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 3

saitoib
Advocate
Advocate

Thank you very much.
I'm convinced.

 

Saitoib
0 Likes