MathGroup Archive 2010

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

Search the Archive

Re: locally changing Options

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108317] Re: locally changing Options
  • From: Raffy <adraffy at gmail.com>
  • Date: Sat, 13 Mar 2010 07:58:38 -0500 (EST)
  • References: <hnakgk$5oa$1@smc.vnet.net> <hndb35$dee$1@smc.vnet.net>

On Mar 12, 4:12 am, Raffy <adra... at gmail.com> wrote:
> On Mar 11, 3:34 am, hemmecke <hemme... at gmail.com> wrote:
>
>
>
>
>
> > In a function I'd like to temporarily say
>
> > foo[x_]:=Module[{...},
> >   ...
> >   SetOptions[RowReduce, Method->OneStepRowReduction];
> >   ...
> > ]
>
> > without affecting the global setting for RowReduce when I call foo.
>
> > My experiments wrapping the SetOptions with a Block structure were not
> > fruitful so far.
> > The only thing I can think of is something of the form
>
> >   method = Options[RowReduce, Method];
> >   SetOptions[RowReduce, Method->OneStepRowReduction];
> >   ... do something ...
> >   SetOptions[RowReduce,method]
>
> > But that looks ugly.
>
> > Any suggestions with built-in Mathematica features to achieve this kind=
 o=
> f
> > locality.
>
> > Ralf
>
> Block[
> {RowReduce = RowReduce[#1, Method -> "OneStepRowReduction", ##2] &},
> (* your code here *)
> ]

A few people emailed me today, noting that my solution above, while
simple, doesn't work and results in infinite recursion.  I apologize
for not testing my solution.

Anyway, after thinking about it, I felt that the simple fix would be:
Block[{RowReduce=System`RowReduce[#1,Method->...,##2]&}, ...]

However, this also results in recursion.  Something seems odd: how is
the blocked RowReduce scoping the fully qualified symbol
System`RowReduce? (Looking at the Trace, it appears that it is
dropping the System` context prior to evaluation...)

This works: Block[{Print=System`Print},Print[1]];
This doesn't: Block[{Print=System`Print[##] &}, Print[1]];

Really odd behavior can be found using the following:
Let $ContextPath = { ..., "Temp`", ..., "System`", ... }
Block[{Temp`Print=System`Print[1, ##] &}, Print[2]] will print "12"
and also cause Print to become shadowed.

I guess the problem boils down to: Why does System`Print simplify to
Print?


  • Prev by Date: Putting controls next to graphics in the Manipulate Display area
  • Next by Date: Using Piecwise with FourierTransform can cause kernel crash, version 7
  • Previous by thread: Re: Re: locally changing Options
  • Next by thread: Re: Re: locally changing Options