# Assigning values to variables inside Module using user defined function

Say I'm defining a function with some local variables, for which I'm using Module. Now, I want to assign some value (or perhaps a list of values or a list of list, etc.) to some of those variables. Can I use a previously user defined function (which itself might have been built using Module) to do so? Here is an example (probably not the best) of what I am asking for, hope it's clear enough:

f[y_]:= y^2

SinFunction[x_]:=Module[{g},
g = f[x];
Sin[g]
]

SinFunction[0.5]


0.247404

I mean it does work, in this case, but is it a good practice? What could possibly have gone wrong?

• I see no problem with what you're doing here, regardless of whether or not f uses Module. The idea behind scoping constructs is that you can nest them, so this is perfectly allowable. – Sjoerd Smit Feb 27 '19 at 14:20
• You just need to watch out when you nest them explicitly: enforcing-correct-variable-bindings – Kuba Feb 27 '19 at 14:24
• Thank you @SjoerdSmit ! I thought that the idea was correct. The reason I asked is that I'm trying to find out where the error comes from in my code and I thought I might have been due to the way I constructed my functions. Thanks again! – amator2357 Feb 27 '19 at 14:25
• Thanks @Kuba. I'll look into it. – amator2357 Feb 27 '19 at 14:25