Joe Riel

9660 Reputation

23 Badges

20 years, 17 days

MaplePrimes Activity


These are replies submitted by Joe Riel

Thanks.  I was pretty sure there was a way to "map" %a over an rtable, but didn't think of using an empty printf_rtable modifier.  Nifty.  That is

printf("%{}a\n", some_rtable) 

is roughly equivalent to

printf("%s\n", map(convert, some_rtable, string));

Thanks.  I was pretty sure there was a way to "map" %a over an rtable, but didn't think of using an empty printf_rtable modifier.  Nifty.  That is

printf("%{}a\n", some_rtable) 

is roughly equivalent to

printf("%s\n", map(convert, some_rtable, string));

Your use of _params is a nice idea and clearer than using _npassed.  I'm with you on keeping it simple.  While overload has its place, it can be exceptionally difficult to debug (more on that later), so unless there is a pressing reason for using overload, Doug's approach is probably the way to go.

Another way to implement Doug's suggestion, but without using _params, is

f := proc(a::list, b::list:=NULL, $)
   if b = NULL then
        print("received ONE list");
        # note that the above message is premature in that it will be printed when f is called with no arguments.
   else
        print("received TWO lists");
   end if;
end proc:

Your use of _params is a nice idea and clearer than using _npassed.  I'm with you on keeping it simple.  While overload has its place, it can be exceptionally difficult to debug (more on that later), so unless there is a pressing reason for using overload, Doug's approach is probably the way to go.

Another way to implement Doug's suggestion, but without using _params, is

f := proc(a::list, b::list:=NULL, $)
   if b = NULL then
        print("received ONE list");
        # note that the above message is premature in that it will be printed when f is called with no arguments.
   else
        print("received TWO lists");
   end if;
end proc:

While the comment help states that (* ... *) are multiline comments, a better term is delimited comments. In contrast, the # comment character is delimited by the end of the line.  Note that you can nest delimited comments, so

(*  (*  inner comment *)  ...  *)

is interpreted as a single comment. 

It may also work in Maple 12, though probably not in the gui.  As was mentioned in the commentary to one of the recent threaded-programming blogs by Darin Ohashi, some set (**) as the prompt string in tty maple.  That allows cutting and pasting tty output, with the prompts, into a tty session and having it directly executed.  Previously the prompt (>) would have to be removed to make it valid syntactically.

It may also work in Maple 12, though probably not in the gui.  As was mentioned in the commentary to one of the recent threaded-programming blogs by Darin Ohashi, some set (**) as the prompt string in tty maple.  That allows cutting and pasting tty output, with the prompts, into a tty session and having it directly executed.  Previously the prompt (>) would have to be removed to make it valid syntactically.

Here's a small "improvement", it also handles rtables, but returns true only if both are not also a Vector, Matrix, or Array (specializations of rtables).

VerifyNested := proc(x,y,ver:=NULL)
local typ;
    for typ in '[Vector,Matrix,Array,rtable,array,set,list,relation,range,record,nothing]'
    while not x::typ and not y::typ do end do;
    if typ = 'nothing' then
        return verify(x,y,ver)
    else
        return proc(typ) verify(x,y,'typ(nested(ver))') end proc(typ);
    end if;
end proc:
VerifyTools:-AddVerification('nested'=VerifyNested);

 

Hmm, not so sure that makes sense.  Is an rtable never not a Vector, Matrix, or Array?

Rather than selecting a completely new set, it is better to append the needed number of values.  Thus

S := {};
while nops(S) < n do
   S := S union {seq(R(), i = 1..n-nops(S))};
end do;

That is what combinat:-randcomb does.

Rather than selecting a completely new set, it is better to append the needed number of values.  Thus

S := {};
while nops(S) < n do
   S := S union {seq(R(), i = 1..n-nops(S))};
end do;

That is what combinat:-randcomb does.

Actually, the manual page for save is not entirely clear.  That is, it states that the saved arguments are "evaluated to names".  So one should, then, be able to do

x[1] := 23:
save x[1], "/tmp/junk.mpl";
Error, save can only save names
type(evaln(x[1]), name);
                   true

I think that the help page and the error should replace "names" with "symbols".

 

 

Actually, the manual page for save is not entirely clear.  That is, it states that the saved arguments are "evaluated to names".  So one should, then, be able to do

x[1] := 23:
save x[1], "/tmp/junk.mpl";
Error, save can only save names
type(evaln(x[1]), name);
                   true

I think that the help page and the error should replace "names" with "symbols".

 

 

The Maple objects 1, 1.0, 1.00 are all different.  When the comparison is between two numerical objects, Maple will look at, and compare, the numerical quantities.  However, if the comparison is between two lists (more generally, nonnumerical quantities), Maple only looks at the surface, that is, whether they are the same object.  So the list [1] does not equal the list [1.0].  If you want to compare whether two lists of numerical quantities are numerically equal, you need to compare each element.  While not the most efficient, you could use verify:

verify([1,2], [1.0, 2.0], list);
                                              true

 

This can be easily extended to handle approximate equality (i.e. roundoff):

verify([1,2.001], [1,2.0], list(float(5,digits=2)));
                                                            true

verify([1,2.001], [1,2.0], list(float(5,digits=5))); 
                                                           false


Rather than ssystem("echo $some_env_var")[2]  you can use getenv("some_env_var").

Seems like some of that defense might have been applied to SaveSession.  It has a number of unprotected global variables:

> save SaveSession, "/tmp/SaveSession.mpl":
> !mint -q /tmp/SaveSession
Procedure SaveSession( archiveName::string ) on lines 1 to 23
  These names were used as global names but were not declared:  assertlevel, 
      cpulimit, datalimit, environment, errortable, imaginaryunit, latexwidth, 
      longdelim, stacklimit, traceproc, watchtable

First 113 114 115 116 117 118 119 Last Page 115 of 195