3
ver1 = 2 x
verf[x_] := ver1
verf[3]

Result : 2 x

Expected Result : 6

In the above code sample, ver1 can change to expressions (4 x + 3,3 x etc)

What is wrong in the code? How can I achieve my objective?

  • 1
    Please also see: (11461) – Mr.Wizard Oct 10 '15 at 09:59
  • I missed 'Evaluate' in my code .. as suggested by @Enrique Pérez Herrero – rainversion_3 Oct 11 '15 at 12:53
  • 1
    If that is a solution for you simply use = (Set) rather than := (SetDelayed) and leave out Evaluate, for the same effect. I believed that you were looking for a somewhat different evaluation behavior as described in the marked duplicate; even if you are not you may wish to familiarize yourself with that. – Mr.Wizard Oct 12 '15 at 06:59

1 Answers1

1

If you do not want to use set delayed in ver1, this is ver1[x_]:= 2 x, you need to evaluate ver1 when verf is defined:

ver1 = 2 x
verf[x_] := Evaluate[ver1]
verf[3]