# Defining function [duplicate]

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?

## marked as duplicate by rhermans, xyz, Mr.Wizard♦Oct 10 '15 at 9:58

• Please also see: (11461) – Mr.Wizard Oct 10 '15 at 9:59
• I missed 'Evaluate' in my code .. as suggested by @Enrique Pérez Herrero – rainversion_3 Oct 11 '15 at 12:53
• 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 6:59

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]