[99] in mathematical software users group
Re: maple questions(compare matrices;packages;parameters)
daemon@ATHENA.MIT.EDU (Reid M. Pinchback)
Thu Jun 24 12:09:12 1993
To: siman@BOURBAKI.MIT.EDU
Cc: msug@Athena.MIT.EDU
In-Reply-To: Your message of Wed, 23 Jun 93 18:16:42 -0400.
Date: Thu, 24 Jun 93 12:08:36 EDT
From: "Reid M. Pinchback" <reidmp@Athena.MIT.EDU>
Oops, I didn't notice the questions appended to your original email.
>(1) when I read the linear algebra package via with(linalg) it automatically
> replace the debugging tool *trace* with the *trace* function for matrices.
> Is there anyway I can keep both, say by renaming one of them?
Something like this should do the trick.
> # load linalg, to get the routines you want.
> with(linalg):
> # establish a new name for the linalg/trace routine
> lintrace := linalg[trace];
> # get back the debugging trace routine from the standard library
> readlib(trace);
I haven't tested this, but it should work.
> Now, one can read part of a library; is it possible to do the opposite
> thing, e.g. read all the linalg package *except* the trace function?
No, at least not without a lot of effort. You could extract the package
table for linalg, and build a new version of it that is missing a few
routines. You'll want to look at "First Leaves" and the Maple language
reference manual to see what is involved.
> (2) I've come up with a cute trick to do a "call by name" parameter passing
> (cf. Pascal), and I wonder if it is valid Maple: say I have a procedure
> with two parameters,
> gcdlat(x,y)
> In addition to the procedure's function, I'd to change the value of the
> parameter y. I do so by the following:
This works... in fact, there are a number of Maple routines that already do
this kind of thing.
> Is this valid Maple? Is there any subtly I should be aware of?
With a little fiddling, its valid, but people who are big on
functional programming would cringe. You also have to really keep
track of how the internal procedural evaluation interacts with the
content of the delayed-evaluation variable. Its very easy to get some
really nasty hard-to-trace bugs when you do this. Depending on how
you intend to use the procedure, its usually simpler to just return a
sequence or a list, and extract the return values you want from there.
> One more thing: matrices seem to be passed by name -- maple does not
> complain when I modify the entries (it does for ordinary variables), and
> the modified values stay there after the procedure is over. Is it related
> to that "last name" evaluation business?
Yes. In the former case, it is almost like you are trying to modify a
constant. Actually, from a logical perspective, you are trying to
locally rebind a symbol that is already globally bound. In the latter
case, you are updating the data structure that the formal parameter is
pointing to, not the formal parameter itself. This is one reason (but
not the only one) for having last-name evaluation in the first place.
You gain flexibility, but you also gain potential debugging problems.
For large complex data structures, the beneficial performance impact
can be quite significant, although functional programming purists will
(perhaps reasonably) point out that the extra time spent debugging can
outweigh the execution advantages.
-----------
Reid M. Pinchback
Faculty Liaison
Academic Computing Services, MIT