Mathieson
10-25-2007, 07:32 PM
I was working today on creating a function to force naming conventions, this is the main function. The function required several other functions inside of it that would be very specific to the needs of this main function, I'll call them sub-functions. I didn't want to start cluttering my script with these random functions that were specific to this one function, so wondered if it would be possible to place the sub functions inside of the main function. I played around with the idea and now have a working version of the main function.
Here is a basic example of what I am talking about..
fn mainFunction ar =
(
fn subFunction obj =
(
print obj
)
for x in ar do subFunction x
)
mainFunction #(2,3,4,2,35,65)
Now, I am doing this just for organizational purposes. I figure it does no harm as it is in the scope of the main function and the sub function still requires variables to be passed to it. This, for example, would not work..
fn mainFunction ar =
(
fn subFunction = -- obj has been removed from function definition
(
for x in ar do subFunction x -- function is calling parameter being passed to mainFunction
)
)
mainFunction #(2,3,4,2,35,65)
So, it still needs to be formatted as if it resides outside of the main function. As soon as I have a use for it outside of the function I can bring it outside and not have to change any code.
fn subFunction obj =
(
print obj
)
fn mainFunction ar =
(
for x in ar do subFunction x
)
mainFunction #(2,3,4,2,35,65)
Is this sub function technique legal to use? Can anybody seeing it causing any problems? I haven't had any issues with it yet, I am just curious.
Here is a basic example of what I am talking about..
fn mainFunction ar =
(
fn subFunction obj =
(
print obj
)
for x in ar do subFunction x
)
mainFunction #(2,3,4,2,35,65)
Now, I am doing this just for organizational purposes. I figure it does no harm as it is in the scope of the main function and the sub function still requires variables to be passed to it. This, for example, would not work..
fn mainFunction ar =
(
fn subFunction = -- obj has been removed from function definition
(
for x in ar do subFunction x -- function is calling parameter being passed to mainFunction
)
)
mainFunction #(2,3,4,2,35,65)
So, it still needs to be formatted as if it resides outside of the main function. As soon as I have a use for it outside of the function I can bring it outside and not have to change any code.
fn subFunction obj =
(
print obj
)
fn mainFunction ar =
(
for x in ar do subFunction x
)
mainFunction #(2,3,4,2,35,65)
Is this sub function technique legal to use? Can anybody seeing it causing any problems? I haven't had any issues with it yet, I am just curious.
