Question: How to set a globals default value for a variable in a package?

In the test package below I want the the Value of Clr to be "B" when the package is loaded. How do I achieve that?
 

restart

mylibdir := cat(kernelopts(homedir), kernelopts(dirsep), "maple", kernelopts(dirsep), "toolbox", kernelopts(dirsep), "personal", kernelopts(dirsep), "lib")

"C:\Users\Ronan.Ronan-PC\maple\toolbox\personal\lib"

(1)

``

libname := mylibdir, libname

"C:\Users\Ronan.Ronan-PC\maple\toolbox\personal\lib", "C:\Program Files\Maple 2016\lib", "C:\Users\Ronan.Ronan-PC\maple\toolbox\personal\lib"

(2)

``

``

``

"RTest:=module()  option package;  export  Sums;    global Clr;  Clr:=B;  Sums:=proc(p1,p2,c:=Clr)  if c=B or c=b  then    p1+p2  elif c=G or c=g then  p1-p2  elif c=R or c=r  then      if p2 =0 then "Not Valid"       else ( p1)/(p2)        end if  else "Error"  end if  end proc;    end module; "

_m655171968

(3)

``

savelib('RTest')

restart

``

with(RTest)

[Sums]

(4)

"At This point I want the value of Clr to be automaticially   B"

Sums(2, 3)

"Error"

(5)

RTest:-Sums(2, 3, b)

5

(6)

``

RTest:-Sums(2, 3, r)

2/3

(7)

RTest:-Sums(2, 3, g)

-1

(8)

Clr := g

g

(9)

RTest:-Sums(2, 3)

-1

(10)

RTest:-Sums(2, 3, b)

5

(11)

RTest:-Sums(2, 3)

-1

(12)

RTest:-Sums(2, 0, r)

"Not Valid"

(13)

``


 

Download Module_Test_global_Var.mw

Please Wait...