I came up with this idiom for defining functions so that the arguments can
be supplied in any order, or omitted and defaults used. Is it used anywhere
else? What do you think?
An example, say that the function for Gaussian integration...
Gaussint takes one required argument, a function %g.
The other arguments are limits and points, which default to [-1,1] and 20,
respectively.
The function definition then calls a routine gq with all the arguments.
gaussint(%g,[args]):=
block([s:append(args,[limits=[-1,1],points=20])],
subst(s, gq(%g,limits[1],limits[2],points)))$
gaussint(foo, limits=[0,inf]) then calls
gq(foo,0,inf,20);
gaussint(foo) calls gq(foo,-1,1,20)
gaussint(foo,points=40,limits=[-inf,0]); also works.
It might be useful to do some checking on the arguments' validity, e.g. the
names on the lhs are spelled correctly, and the values have the right types.
Thoughts? Should we use this more often? There is a chance of screwing
this up by, for example, doing limits:points before calling gaussint. Any
way around this?
RJF