Joe Riel

7637 Reputation

20 Badges

13 years, 298 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@Christopher2222 The Maple macro command isn't all that useful for its intended purpose, which, as mentioned in the first sentence of the help page, is to be "a simple abbreviation facility to be used when writing Maple functions and library code."  While it may have been used for that many releases ago, when Maple library procedures were table-based and hence globally assigned, the transition to modules makes it almost pointless.  The reason is that the call to macro must be at the global level; that doesn't work well when the source for a procedure in which you want to define and use a macro is located in a separate file that is at a lower part of module hierarchy. Maple's preprocessor macros are better suited for this purpose as they can be locally defined and undefined. 

@Christopher2222 Converting to a string and parsing is going to ensure the names are globals.

 

While you should first try with the correct format, it is possible that the Maple server has been configured to restrict the ability to write to external files.

@acer If the assignment operator could be overloaded (it currently cannot---a good thing) it could be made to do something, though without some other mechanism it isn't clear what. There are a few assignments that use a special syntax on the lhs: directly assigning to a remember table and assigning content of an rtable are two examples.

@acer Nice options.  The third can be slightly simplified by dropping the i in the seq: [seq(4..1,-1)].

@Carl Love The answer is that I wasn't thinking about thread-safety. It's good that you brought that up.

Be sure to define and check the corner cases.  Specifically, what do you want for, say, [1,1,2,2].  Is 1 or 2 the second-highest element?  What about [1,1,1,1]?  Or for the empty list (Maple's max returns -infinity).

@Carl Love Nice explanation and example. A nit---probably best ignored---is that Maple error messages generally start with a lower case letter, they look better that way as the usual output is "Error, <the error message>".

You could use two prismatic joints to enforce a planar motion.  The planar joint could also be used.  A different approach would be to use the sphere-rectangle contact, though that would allow motion off the surface (bouncing).

@a_simsim It helps to know why two backslashes are required, in a Maple string, to represent a Windows directory separator. The backslash is used as an escape character, to permit entering special characters (new-lines, tabs, arbitrary ascii). As such, to enter the escape character itself, you need two of them, the first "escapes" the second.

Have someone do it for you. Snarky answer aside, what are you trying to make efficient?  The execution of the procedure, or the creation of the procedure? The usual concern is the former. 

@Ramakrishnan On line 95 there is a call to SetProperty that is missing its package name (should be DT:-SetProperty); without the package name it returns unevaluated.

In the embedded component code sections, the "use DocumentTools in ... end use;" wrappers are no longer needed as there are no exports of DocumentTools being used in the code.  It probably isn't worthwhile to remove the wrappers, but it is something to consider for the next worksheet.

 

@Carl Love Nice extension, particulary the use of an operator for a positional argument. Hmm. Is there a type 'operator'? There should be.  Probably there should be a check for the number of dimensions of an rtable; it seems unlikely anyone would want to sort a 2 or higher dimensioned rtable by the linear order.

@Kitonum The OP should be aware that this method is horrendously inefficient.  The issue is that every swap generates an entirely new list.  Such manipulations should be done on a mutable structure; here an Array or Vector would be appropriate. The changes to the code are easy:

BubbleSort := proc(L::list(numeric))
local A, n, k, m;
    A := Array(L);
    n := upperbound(A,1);
    for k from 0 to n-2 do
        for m from 1 to n-k-1 do
            if A[m] > A[m+1] then
                # swap elements at indices m, m+1
                (A[m],A[m+1]) := (A[m+1],A[m]);
            end if;
        od;
    od;
    convert(A, list);
end proc:

To expand on acer's response, there are two usages of the uses keyword:  uses DocumentTools and uses DT=DocumentTools.  The former makes all the exports of DocumentTools available in the procedure (or module).  The latter provides a shorthand that expands subsequent uses of DT to DocumentTools.  While the former may be more convenient, if you unintentionally use an export of DocumentTools the result may not be what you expect. Further, if at a later date new exports are added to DocumentTools, there may be a conflict with your code. Unless it is throwaway code, I invariably use the second form; I find it safer and clearer.  A minor downside with using the second form is that mint (Maple's syntax checker) will throw occasional nags about the shortname being undeclared.

1 2 3 4 5 6 7 Last Page 1 of 176