Question: how to add type with default initial value?

Is it possible in Maple to add new type, and assign initial/default value that the variable of that type will take on?

I can't figure if this is possible or not and if it, what is the correct syntax. This is something very common in strong typed Language such as Ada for example.

For example, in Ada one can create new type wiith default value like this

              type My_Float is digits 20   with Default_Value => 0.5;

Later on, when declaring variable of the above type, if no explicit value is given then, then the variable will have the value 0.5

             A: My_float;

Or one can override the default value:

             A: My_float := 0.1;

I am trying to do the same with Maple using that handle in AddType(typename, handler)

But no success. Here is an example

TypeTools:-AddType(age_type,t->evalb(t::nonnegint and t>0 and t<150));

Now, I want to change the above to tell TypeTool to have default value as say 30. So when I do 


Then the variable p will have value of 30 automatically.

Is this possible in Maple? 


After a little bit of trying things, I came up with this. May be not prefect, but does what I want for now.

The idea is to make the initialization of the variable, as a proc() which takes in default values. I plan to use this for record types, so this example below is meant for this use, but the idea is the same for other types.

TypeTools:-AddType(age_type,t->evalb(t::nonnegint and t<150));
TypeTools:-AddType(name_type,t->evalb(t::string and StringTools:-Length(t)<100));
make_person_type:=proc({the_age::age_type:=30, the_name::name_type:="joe doe"},$)::person_type;
   local p::person_type;
   return p
end proc;


And now one can make a variable of new type, which takes in default values like this


which returns 

              p := Record(age = 30, name = "joe doe")

And to set specific initial values:


Which returns

            p := Record(age = 35, name = "joe doe")

It would have been better is Maple allows one to set the default value for type when it is defined, so everything is in one place and there would have been no need to make an explicit proc() for to set the initial value of the variable.

Please Wait...