Ronan

1371 Reputation

16 Badges

13 years, 229 days
East Grinstead, United Kingdom

MaplePrimes Activity


These are replies submitted by Ronan

@Carl LoveThis looks to be a best pratical option in general. It might be a day or two before I get back to this. Is _rest the required name, i.e something specified inside Maple. Could a name such as Additionaloptions be be used? 

A 3d pdf is attached. It is from a CAD systen. You can rotate the image like you can do with a 3D plot in Maple. Adobe will give you a warning when opening this.

I will look into the  EPS export.

CAD_3D_bolt.zip

@Kitonum @Carl Love @Preben Alsholm ​​​​​​​@sand15 these are all great answers. 

@sand15 That deserves a vote up.

@Carl Love I like that.

@Carl Love I find sometimes it works and sometimes not. About 50-50. I find it useful because it scrolls directly to the response clicked on.

 

@acer   That is precisely what I was trying to achieve.

@rlopez That is good to know. I never think of using the the Student Package.

Same here. It took minutes after clicking submit to post a simple question this evening.

@Preben Alsholm I realised about an hour ago, I could get myself into a lot of trouble with altering the default. In a couple of months time when I probably would have forgotten about it.

@acer I see what you mean about foo. I hadn't thought about it before then. Yes it definately gets irrating when someone keeps adding to a specification. Basically there are no extra requirements.  There is no point in trying to handle obscure possibilities. I am just trying to catch wrong arguments being passed and the procdeures doing a wrong interpretation. The $ is a very simple way of catching that. Especially if a number is passed.

Is this safe? I wrapped expects around  coerce  to catch non string entries. Though the error message is rather unwieldy.
 

restart;

 

p := proc(c::expects(coerce(proc(s::string)
                      local L:=StringTools:-LowerCase(s);
                      piecewise(member(L,["blue","b"]),"Blue",
                                member(L,["green","g"]),"Green",
                                member(L,["red","r"]),"Red",
                                ERROR("\"%1\" does not coerce",s))
                    end proc)):="Blue")

  return c;

end proc:

 

p("bLUe"), p("Blue"), p("blue"), p("b"), p("B");

"Blue", "Blue", "Blue", "Blue", "Blue"

(1)

p("ReD"), p("Red"), p("red"), p("r"), p("R");

"Red", "Red", "Red", "Red", "Red"

(2)

p("GreEn"), p("Green"), p("green"), p("g"), p("G");

"Green", "Green", "Green", "Green", "Green"

(3)

p("God");

Error, (in p) "God" does not coerce

 

p("black");

Error, (in p) "black" does not coerce

 

p();

"Blue"

(4)

p(foo);

Error, invalid input: p expects its 1st argument, c, to be coercible via proc (s::string) local L; L := StringTools:-LowerCase(s); piecewise(member(L,["blue", "b"]),"Blue",member(L,["green", "g"]),"Green",member(L,["red", "r"]),"Red",ERROR("\"%1\" does not coerce",s)); end proc, but received foo

 

p(5)

Error, invalid input: p expects its 1st argument, c, to be coercible via proc (s::string) local L; L := StringTools:-LowerCase(s); piecewise(member(L,["blue", "b"]),"Blue",member(L,["green", "g"]),"Green",member(L,["red", "r"]),"Red",ERROR("\"%1\" does not coerce",s)); end proc, but received 5

 

 


 

Download 2024-02-10_Q_coercion_ex2-1.mw

@mmcdara  Ahh. I use Geomclr:= "...." as the global colour setting but can be changed specifically.

I now notice you put the optional parameters in {  }. The makes you have to do clr =...    but has the advantage of allowing skipping one if desired. Nice. 

@acer 

I have experimented with catching an incorrect input. How should I get it to produce an error instead on skipping on. An empty input p() is fine.
 

restart;

p := proc(c::coerce(proc(s::string)
                      local L:=StringTools:-LowerCase(s);
                      piecewise(member(L,["blue","b"]),"Blue",
                                member(L,["green","g"]),"Green",
                                member(L,["red","r"]),"Red",
                               `not`(menber(L,["blue","b","green","g","red","r"])))
                    end proc):="Blue")

  return c;

end proc:

p("bLUe"), p("Blue"), p("blue"), p("b"), p("B");
             "Blue", "Blue", "Blue", "Blue", "Blue"

p("ReD"), p("Red"), p("red"), p("r"), p("R");
               "Red", "Red", "Red", "Red", "Red"

p("GreEn"), p("Green"), p("green"), p("g"), p("G");
          "Green", "Green", "Green", "Green", "Green"

p("God"),p("black")

 not menber("god", ["blue", "b", "green", "g", "red", "r"]), 

   not menber("black", ["blue", "b", "green", "g", "red", "r"])


p()
                             "Blue"

 

@mmcdara This makes things much neater. I will try setting it up as a procedure that is called inside the package, as this is used in various places. Yes I do need to put in checks for the 0 denominator.

I notice one has to enter
spread2(...clr="Red" , prnt =false) 
instead of
spread2(....."Red" , false)

Why is that? 


  I do like that you skip clr
spread2(p0 , p1, prnt=false)

 Module...
    export spread....,
 Coltest(clr)
local col := substring(StringTools:-Capitalize(clr), 1..1);
           local COL := `if`(col="R", "Red", `if`(col="G", "Green", "Blue"))  
return col
end proc;
spread2:=proc(
               ....
               {clr::string:="Blue"}, 
               {prnt::boolean:=true}
             )
           ....
          Coltest(clr); 
           ....
           if `not`(member(col, {"R", "G", "B"})) then
             error cat("allowed colors are red, green or blue, received ", clr)
           end if:

           if prnt then
             print(cat("Spread 2 [x,y] Points/Vectors wrt origin ",  COL));
           end if:
                 
           if col = "B" then
               return ....

           elif col="G" then
               return ....

           elif col="R" then
               return ....
          end if;
          end proc:



 

 

 

First 9 10 11 12 13 14 15 Last Page 11 of 32