Subject: interface for numerical integration, roots etc
From: John Lapeyre
Date: Wed, 26 May 2010 21:07:14 +0200
On Wednesday 26 May 2010 19:31:28 Robert Dodier wrote:
> On Wed, May 26, 2010 at 4:33 AM, John Lapeyre <pdl at johnlapeyre.com> wrote:
> > highlevelfunc(blob, [x,0,1],[y,a,b], u=v, maxiterations -> 10, eq1 -> c=d);
> > highlevelfunc(blob, [x,0,1],[y,a,b], u=v, maxiterations => 10, eq1 => c=d);
>
> Mma differs from Maxima in much more fundamental ways than
> syntax: it doesn't help to use the same syntax when programs are
> going to work differently anyway.
I didn't explain well what I was trying to do. I don't want
to copy Mma, at least not just for the sake of looking like Mma. I was
just looking for a good notation. I think -> or => or some
kind of ascii-art arrow is used frequently for keyword
arguments. For example the perl-tk package uniformly uses
=> for setting options. So does pdl (perl matlab-like
package). In that case it is a key,value pair in a hash. In
Mma's case they are sort of overloading their way to write a
rule (so you could argue that it was not a good idea for Mma
to use -> for options)
As Richard wrote, and I did in my previous post, using '='
for different things can make it a bit difficult for a human
to parse.
The characteristics I find most important are:
1. Some notation that says key,value. So options(a,b,c,d,e)
to mean a takes value b, etc. doesn't do this. But
'=','->','=>', ':>' do this.
2. A routine should be able to easily separate an argument list into two
structues: 1) a list of the non-keyword arguments in their original
order 2) a hash or something holding the key,value pairs of the
keyword arguments. It must be able to do this without knowing anything
about the number or purpose or kind of objects in the argument list.
So having optname=optval in a flat list will not work. Using -> or =>
will work. Using options(opt1=val1,opt2=val2) will work.
3. Slightly less important. The notation shouldn't give you a headache.
Richard's example of solve([a*x+b=c],opts=[method=default]) is not
very soothing. Or worse
foo([a*x+b=c],opts=[method=default,auxeq=x^2=(1-y)])
Compare to
foo([a*x+b=c],method->default,auxeq->x^2=(1-y))
I wish I knew more about syntax for keyword arguments in other languages.
At first I didn't like : and &aux and &rest in lisp, but I am used to it
now.
regards,
John