Question: How to pass optional parameters to embedded procedures?


Let's suppose I define a procedure P which uses a Maple built-in procedure BP.
BP is a procedure which uses optional parameters, let's say a and b.

I would like to call P with the same optional parameter names than BP, that is to write something like this

P := proc(....., {a::a_type:=a:-default, b::b-type:=b_default)
       ....
       BP(...., 'a'=a, 'b'=b)
     end proc.

The execution of P(..., a=1) leads to the error unexpected option: 1=1
 

A workaround is to define P this way

P := proc(....., {P_a::a_type:=a_default, P_b::b-type:=b_default)
       ....
       BP(...., a = P_a, b = P_b)
     end proc.

# example

P(..., P_a=1, P_b="yes")

This works but it would be easier for the users to use the same option names in the definition of P than in the definition of BP.

Question: Is that possible?

Here is an illustrative example where I would prefer to write

ecdf(S, color="red", thickness=3)

instead of

ecdf(S, ecdf_color="red", ecdf_thickness=3)


 

restart

ecdf := proc(S, {ecdf_color::string:="blue", ecdf_thickness::posint:=1})
  local N   := numelems(S):
  local M   := sort(S):
  local opt := [color=ecdf_color, thickness=ecdf_thickness]:
  plots:-display(
    plot([ seq(op([[M[i], (i-1)/N], [M[i], i/N], [M[i+1], i/N]]), i=1..N-1) ], opt[])
    , plot([ [M[N], (N-1)/N], [M[N], 1] ], opt[])
    , plot([ [M[N], 1], [(max+(max-min)*0.2)(S), 1] ], opt[], linestyle=3)
    , plot([ [M[1], 0], [(min-(max-min)*0.2)(S), 0] ], opt[], linestyle=3)
  )
end proc:

S := Statistics:-Sample(Uniform(0, 1), 10):
ecdf(S)

 

ecdf(S, ecdf_color="red", ecdf_thickness=3)

 

 


 

Download ecdf.mw


Thanks in advance

 

Please Wait...