Skip to main content
Tweeted twitter.com/#!/StackMma/status/306848476300451842
deleted 92 characters in body; edited tags
Source Link
Oleksandr R.
  • 23.2k
  • 4
  • 88
  • 129

I am trying to use a 'Module'Module having "local functions", i.e., those which I need to define only inside this module.

So I tried this:

norm[p_]:=Module[{

fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1

},

Max[fun1[p],fun2[p]]

];

norm[p_] := Module[{ fun1[p_] := p^2 + p - 1; fun2[p_] := p^3 - p^2 + p + 1 }, Max[fun1[p], fun2[p]] ]; 

The function is compiling ..., but when I try to evaluate it--say, say I try:

norm[2]

norm[2] 

Its giving me an error telling:

Module::lvsym: Local variable specification {fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1} contains fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1, which is not a symbol or an assignment to a symbol

Module::lvsym: Local variable specification {fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1} contains fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1, which is not a symbol or an assignment to a symbol

How do we surpassavoid this error  ? basically i am guessing the problem is I want to define a module with local variables and "local function" ... I want to give functions in the space between { ... }.

I am trying to use a 'Module' having "local functions", i.e, those which I need to define only inside this module.

So I tried this:

norm[p_]:=Module[{

fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1

},

Max[fun1[p],fun2[p]]

];

The function is compiling ... but when I try to evaluate it, say I try:

norm[2]

Its giving me an error telling:

Module::lvsym: Local variable specification {fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1} contains fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1, which is not a symbol or an assignment to a symbol

How do we surpass this error  ? basically i am guessing the problem is I want to define a module with local variables and "local function" ... I want to give functions in the space between { ... }

I am trying to use a Module having "local functions", i.e., those which I need to define only inside this module.

So I tried this:

norm[p_] := Module[{ fun1[p_] := p^2 + p - 1; fun2[p_] := p^3 - p^2 + p + 1 }, Max[fun1[p], fun2[p]] ]; 

The function is compiling, but when I try to evaluate it--say, I try:

norm[2] 

Its giving me an error telling:

Module::lvsym: Local variable specification {fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1} contains fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1, which is not a symbol or an assignment to a symbol

How do we avoid this error? I want to give functions in the space between { ... }.

Source Link
Pavithran Iyer
  • 1k
  • 1
  • 12
  • 17

Module with "local functions"

I am trying to use a 'Module' having "local functions", i.e, those which I need to define only inside this module.

So I tried this:

norm[p_]:=Module[{

fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1

},

Max[fun1[p],fun2[p]]

];

The function is compiling ... but when I try to evaluate it, say I try:

norm[2]

Its giving me an error telling:

Module::lvsym: Local variable specification {fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1} contains fun1[p_]:=p^2+p-1;fun2[p_]:=p^3-p^2+p+1, which is not a symbol or an assignment to a symbol

How do we surpass this error ? basically i am guessing the problem is I want to define a module with local variables and "local function" ... I want to give functions in the space between { ... }