[Date Index] [Thread Index] [Author Index]
same options for 30 functions?
Dear mathgroup- The short version of my question: Is there any graceful way to provide a default option for 30 or more functions in a package? I want to let the user change defaults in the middle of a run, via SetOptions or some similar operator. The long version: Consider a package function defined as f[a_, b_, g_String:$GroupName]:= whatever where g_String:$GroupName appears at the end of the argument list for nearly every function in the package, some 30 or 40 of them. $GroupName is a Global` variable that is assigned before initialization of the package. For example, one might set $GroupName = "C3v". Thus the user does not have to say f[a,b,"C3v"] every time- f[a,b] will do the job, with the default "C3v" understood. Here is the problem: You cannot change the default groupname in the middle of a run. You can change $GroupName, but it has no effect, because its value was used at the time the functions were defined, and it is never consulted again. I would like to write f[a_, b_, g_String:(delayed assignment of $GroupName)]:= whatever but I have not been able to cook up any way to accomplish this. If the assignment of $GroupName could be delayed, function f would pick up the new value on each use, and changes in $GroupName would be meaningful. I have read enough standard packages to know how to program a standard Mma option (like Trig->True) for a function , but for 30 functions with the same option the standard route seems quite ugly- every function would be split into three nested functions, with useful operations going on in only the innermost totally private function. This would almost double the size of the package, just to accomplish what seems like a simple little task. Any ideas? Thanks, Martin McClain, Chemistry Dept., Wayne State Univ, Detroit