MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: options to functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24154] Re: [mg24080] Re: options to functions
  • From: Maarten.vanderBurgt at icos.be
  • Date: Wed, 28 Jun 2000 22:50:38 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hallo Roger, David,

I had a similar problem some time ago. I guess it is related to the context
of the option  AtomName and the variable atomname in the package. I manged
to find out by putting a few print statement in my function. Using print
statements I found out that when it went wrong I was working with two
different variables: Global`myoption and
mypackages`package`Private`myoption.

It got solved the following way:

BeginPackage["`mypackages`package`"];

MyFunction::usage =
    "... With the option MyOption -> True MyFunction returns... In the
default case MyOption -> False only ... is returned.";

MyOption ::usage="MyOption is an option of MyFunction. It can be True or
False. See MyFunction."

Begin["`Private`"];

Options[MyFunction]={MyOption ->False};

MyFunction[x_, y_, z_, opts___] := Module[
{a,b, ...and other variables..., myoption},
a =...
b =...
myoption= MyOption /. {opts} /. Options[MyFunction];
If[myoption === True, a , b]]

End[];

Print[" .. `mypackages`package` v0 loaded"];

Protect[MyFunction];

EndPackage[];

I do not remember what exactly made it work, but I removed MyOption from
the Protect[ ] statement and included the MyOption::usage.


Maarten





dreiss at NOSPAMscientificarts.com (David Reiss) on 23-06-2000 08:26:47 AM


Subject: [mg24154]  [mg24080] Re: options to functions




In article <8ipnjn$ap7 at smc.vnet.net>, Roger Mason
<rmason at sparky2.esd.mun.ca> wrote:

> Hi,
>
> I am writing a function inside a package and wish to pass options to it.
>
> For testing purposes I have this (inside the Private context of the
> package):
>
> Options[XRDCoordList] = {AtomName -> False}
> ... (some functions defined here ...
>
> This is the troublesome function...
>
> XRDCoordList[name_String, atom_List, transl_List, opts___?OptionQ] :=
> Module[
>     { n = Length[atom], ans = {}, atomname },
>     atomname = AtomName /. { opts  } /. Options[XRDCoordList];
>     Do[
>       AppendTo[ans, Map[atom[[i]] + # &, transl] ] , {i, 1, n}];
>     ans = Flatten[ ans ];
>     Do[If[ans[[i]] >= 1,
>         ans[[i]] = ans[[i]] - 1](*If[ans[[i]] < 0,
>           ans[[i]] = ans[[i]] + 1]*) , {i, 1, Length[ans]} ];
>     (*If[atomname,
>         ans = Insert[ans, name, Table[n, {n, 1, Length[ans] - 3, 3} ] ];
>
>         Partition[ans, 4 ], Partition[ ans, 3 ]] *) atomname
>     ]
>
> When I invoke it using
>
> ca = XRDCoordList["ca", {{0, 0, 0}, {0, 0, 1/2}}, cenTransl,
>       AtomName -> True] // N
>
> it always returns False.
>
> I can't see what I've done wrong.
>
> Thanks,
>
> Roger Mason


This works (returns True) when I substitute a list for cenTransl
for Mathematica 4 on the Mac...


_David

--
) Scientific Arts: http://www.scientificarts.com
) Creative Services and Consultation for the Applied
) and Pure Sciences:: David Reiss: dreiss at !SPAMscientificarts.com
) [Remove the !SPAM to send email]







  • Prev by Date: Re: "misbehaving" Union function
  • Next by Date: Re: FindMinimum and Gradient
  • Previous by thread: options to functions
  • Next by thread: ClearCellOptions Dialog Box