dynamically created symbol -- Good Thing To Do?



I'm trying to empty out my old "to do" email, hence the very delayed reply.

In general, creating variable names on the fly is as bad an idea in a CAS
as it is in any other programming environment.  And most of the time when
beginners ask about doing this, they really have no good reason to. However,
there are three (stupid) practical reasons that you might want to do it in
Maxima:

   1. On input, it's easier to type x1 than x[1].  On the other hand,
   makelist(concat(x,i),i,1,5) is surely uglier than makelist(x[i],i,1,5).
   2. A few parts of Maxima don't treat subscripted variables as
   variables/symbols.  I don't think there are many cases like this left, but
   I think there are a few.  For example, lambda([x[1]], ...) doesn't work
   properly.
   3. On output, x1 can be more compact or easier to read than a subscript
   in some cases.

You might think that operations involving simple symbols would be faster
than on subscripted symbols, but that is not true in general.  In fact,
some operations are faster on subscripted symbols (for the curious:
orderlessp(a[1],a[2]) vs orderlessp(a1,a2)).  But this is almost never
going to matter.

           -s


On Thu, Jun 28, 2012 at 10:24 AM, Bill Wood <william.wood3 at comcast.net>wrote:

> I've followed this thread with interest.  I'm an experienced programmer,
> and whenever I've seen this question (how to create variable names on
> the fly) from Python or lisp programmers it has almost always been the
> case that the inquirer was a beginner and the Right Answer was to first
> explain why it was a bad idea (creating variable names at run time makes
> the program extremely hard to debug because you can't read the text of
> the program and even determine the space of variables, much less
> determine what relationships are being violated) and then help the
> inquirer solve their problem in a manageable way.
>
> Here, however, in the context of a CAS with a programming (scripting?)
> language facility, I consider myself to be a rank beginner.  So what do
> the experts believe to be best practice?  Is the ability to create named
> variables at run time one of the facilities that make maxima scripting
> really shine, or is it a dubious practice here as well?
>
> Thanks,
>
> --
> Bill Wood
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>