an exploitation of the single vs. multi argument behavior of Unevaluated
- To: mathgroup at smc.vnet.net
- Subject: [mg79041] an exploitation of the single vs. multi argument behavior of Unevaluated
- From: "Chris Chiasson" <chris at chiasson.name>
- Date: Mon, 16 Jul 2007 02:22:57 -0400 (EDT)
Unevaluated with multiple arguments is treated as Unevaluated[Sequence[arg1,arg3,etc]], where Sequence doesn't have its normal Sequence effect. Unevaluated with one argument has its intended behavior. Unevaluated with no arguments is treated as Unevaluated[Sequence[]]. Compare: In[1]:= f/@Unevaluated[] Out[1]= Sequence[] In[2]:= f/@Unevaluated[1] Out[2]= 1 In[3]:= f/@Unevaluated[1,2] Out[3]= Sequence[f[1],f[2]] In situations where I am using Unevaluated with a variable number of arguments, the behavior with a single argument would usually produce an error, so (on Maxim's recommendation) I usually explicitly specify Unevaluated@Sequence[args] on the right hand side of pattern transformation rules, where args can correspond to zero or more arguments. However, I found one situation where the single vs. multi argument behavior can be exploited. It involves needing to specify either one of two alternative pattern right hand sides to a function. (Also, specifying Sequence sequence either inside or outside of Unevaluated in this situation would produce undesirable results. i.e. Sequence[Unevaluated[a1],Unevaluated[a2]] or Unevaluated[Sequence[a1,a2]] would be bad.): Cases[AbsoluteOptions@EvaluationNotebook[],(str_String/;StringQ@Unevaluated@str)|(symb_Symbol/;AtomQ@Unevaluated@symb):>ToString@Unevaluated[str,symb],Infinity] The resulting list of strings is useful for exploring possible options of Cell via the string matching functions. P.S. For one of Mathematica 6's more annoying features, evaluate: AbsoluteOptions@$FrontEnd to receive: ToExpression::notstrbox: FEPrivate`FrontEndResourceString[GetFEKernelInit] is not a string or a box. ToExpression can only interpret strings or boxes as Mathematica input. >> P.P.S. The old v5 documentation search was good for some things. For instance, try figuring out what the "Margins" option is for by using Google search or the Mathematica 6 search. I suppose the old version's advantage in this case could be eliminated by adding a regular expression search to Mathematica 6. -- http://chris.chiasson.name/