Computer Science Canada

Functions inside records

Author:  Danjen [ Mon Mar 12, 2007 12:03 am ]
Post subject:  Functions inside records

Here's what I have so far:
code:

var Skill :
    record
        Firebolt : fcn
            Firebolt (sLv, intH : int) : real
    end record

put Skill.Firebolt(5,10)

It displays a variable has no value error ... where and how would I correct this?

Author:  Clayton [ Mon Mar 12, 2007 6:50 am ]
Post subject:  Re: Functions inside records

that's because you have not given Firebolt any value. All it knows is that Firebolt should hold a function with two integer parameters. You have to create the function outside of the record, and assign that function to Firebolt like so:

Turing:

fcn firebolt (sLvl, intH : int) : real
    result 5 %just randomly
end firebolt

var skill :
     record
         spell : fcn foo (sLvl, intH : int) : real
     end record

skill.spell := firebolt

put skill.firebolt (10, 22)


Wink


: