Carlos Mallen

20 Reputation

3 Badges

16 years, 173 days

MaplePrimes Activity


These are answers submitted by Carlos Mallen

Hi,

I managed to create a working example using $include.

My .mpl files are: MyLibrary.mpl, Sums.mpl, Products.mpl, and Divisions.mpl. The contents of these files are listed below:

MyLibrary.mpl

MyLibrary:=module()
  description "A sample Maple library.":
  option package, load = Setup:
  export MySum, MyProduct, MyDivision:
  global Sums, Products, Divisions:
  local Setup:

  Setup:=proc()
    read "Sums.mpl":
    read "Products.mpl":
    read "Divisions.mpl":
  end proc:

  MySum:=proc(a, b)
    return Sums:-MySum(a, b):
  end proc:
  MyProduct:=proc(a, b)
    return Products:-MyProduct(a, b):
  end proc:
  MyDivision:=proc(a, b)
    return Divisions:-MyDivision(a, b):
  end proc:

  Setup():

end module:

savelib(MyLibrary, "C://Personal//Sample Maple Libraries//Using Include//MyLibrary.mla"):

Sums.mpl

Sums:=module()
  export MySum:
  MySum:=proc(a, b)
    description "Returns the sum of a and b.":
    return a + b:
  end proc:
end module:

Products.mpl

Products:=module()
  export MyProduct:
  MyProduct:=proc(a, b)
    description "Returns the product of a and b.":
    return a*b:
  end proc:
end module:

Divisions.mpl

Divisions:=module()
  export MyDivision:
  MyDivision:=proc(a, b)
    description "Returns the division of a over b.":
    return a/b:
  end proc:
end module:

Then, in a Maple worksheet put these instructions:

Maple worksheet

restart:
read "C://Personal//Sample Maple Libraries//Using Include//MyLibrary.mpl":

restart:
march(open, "C://Personal//Sample Maple Libraries//Using Include//MyLibrary.mla"):
with(MyLibrary);
MySum(a, b);
MyProduct(a, b);
MyDivision(a, b);

I'm omitting the output of march. The rest is:

[MyDivision, MyProduct, MySum]
a + b
a*b
a/b

You can also use

$include "Sums.mpl":
$include "Products.mpl":
$include "Divisions.mpl":

instead of read in MyLibrary.mpl.

The local Setup routine in the MyLibrary module looks strange. Without it, calling the functions results in Maple complaining about Sums or Products or Divisions not being a module. After loading such modules, the functions worked OK, so I guessed Maple didn't have the necessary definitions. Using the Setup routine is a way of loading such modules.

Hope this helps. I guess this code can be improved, but for the moment, I'm OK with it.

Carlos Mallen

Page 1 of 1