Question: Alternative Argument spelling in a procedure

This is something I use a fair bit. I have procedures with alternative spelling options for the colours Red Green and Blue.
Have shown a single example copied from  an overloaded procedure. It there a nicer way of handling this than what I am doing?
There is a section in help under "Procedure Parameter Declarations" on "Indexed Keyword Parameters"  but I don't see how to use it here. These procedures are used inside a package.

restart

 

GeomClr:="Blue";  # can be "Blue", "blue", "B", "b"  or;
                  #        "Green", "green", "G", "g"  or;
                  #        "Red2, "red", "R", "r";

Prntmsg:="y" ; #  or anything that is not"y"

 

"Blue"

 

"y"

(1)

spread:=proc(p0::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
              p1::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
              clr::`string`:= GeomClr,
              prnt::`string`:=Prntmsg)
           option overload;
           uses LinearAlgebra;
           #print(clr,p0,p1);
           if clr="b" or clr="B" or clr="blue" or clr="Blue" then
              if prnt="y" then
                print("Spread 2 [x,y] Points/Vectors wrt origin Blue");
              end if;
               return 1 - BilinearForm(p0, p1, conjugate = false)^2/(BilinearForm(p0, p0, conjugate = false)*BilinearForm(p1, p1, conjugate = false));
           elif clr="g" or clr="G" or clr="green" or clr="Green" then
              if prnt="y" then
               print( "Spread 2 [x,y] Points/Vectors wrt origin Green");
              end if;
               return -1/4*(p0[1]*p1[2] - p0[2]*p1[1])^2/(p0[1]*p0[2]*p1[1]*p1[2]);
           elif clr="r" or clr="R" or clr="red" or clr="Red" then
              if prnt="y" then
               print( "Spread 2 [x,y] Points/Vectors wrt origin Red");
               end if;
               return -(p0[1]*p1[2] - p0[2]*p1[1])^2/((p0[1]^2 - p0[2]^2)*(p1[1]^2 - p1[2]^2));
          end if;
          end proc:

sb:=spread(<3|2>,<4|-5>);

"Spread 2 [x,y] Points/Vectors wrt origin Blue"

 

529/533

(2)

sg:=spread(<3|2>,<4|-5>,"g");

"Spread 2 [x,y] Points/Vectors wrt origin Green"

 

529/480

(3)

sr:=spread(<3|2>,<4|-5>,"r");

"Spread 2 [x,y] Points/Vectors wrt origin Red"

 

529/45

(4)

1/sb+1/sr+1/sg

2

(5)

sr:=spread(<3|2>,<4|-5>,"r","n");

529/45

(6)

 


 

Download Q_2024-02-09_Alternative_Spelling_in_Proc.mw

This has been branched into the following page(s):
Please Wait...