Question: Objects in Maple 16

May 15 2012 gwpatrick 15
Maple 16

(1) Does ModuleCopy, when automatically called from Object,  really get the a shallow copy of the object

as the first parameter in its parameter list? See below, which is copied directly from ?object,create. The

ModuleCopy has first argument new::Dollar but ModuleApply only passes its two arguments not three. I

couldn't find a reference to this feature in the docs.


(2) See below. Notice that the method in_circulation can be referred to via an unqualified name and that a global

in_circulation can be defined, and that can live independently of the Dollar:-in_circulation. Is it really

supposed to work that way? Surely the exports like  foo from Dollar ought only be avalaiable

by using qualified names like Dollar:-foo.

module Dollar() option object;
  local value := 0;
  local total::static := 0;
  export ModuleApply::static := proc( )
    global Dollar; Object(Dollar, _passed)
    end proc;
  export ModuleCopy::static := proc(new::Dollar, proto::Dollar, v::numeric, $)
    new:-value := v; total := total + new:-value; print("ModuleApply")
    end proc;

  export amount::static := proc( self::Dollar, $) return self:-value; end;
  export in_circulation::static := proc(self::Dollar, $) total; end;
  end module;

# When invoking ModuleCopy, Object must inserts as the firt argument the
# Object it is creating, presumably obtained from the shallow copy.

# in_circulation can be redefined globally but the module one still
# gets called. Strange.

in_circulation:=proc() print("BLECH") end;
in_circulation();                 #gets the one just above
in_circulation(Dollar);           #gets the Dollar version (!!)
Dollar:-in_circulation( Dollar ); #yeah, expected this

Please Wait...