Re: locally changing Options
- To: mathgroup at smc.vnet.net
- Subject: [mg108266] Re: [mg108224] locally changing Options
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Fri, 12 Mar 2010 07:09:40 -0500 (EST)
- References: <201003111134.GAA05909@smc.vnet.net>
hemmecke 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 of > locality. > > Ralf The way we do this in house is close to what you show. We simply enclose the sequence of before,work,after code within a special wrapper function called WithLocalSettings (in Internal` context). This forces the cleanup phase to happen even when there might be an interrupt (e.g. from an outer TimeConstrained). In your example it would be done as below. Internal`WithLocalSettings[ method = Options[RowReduce, Method]; SetOptions[RowReduce, Method->OneStepRowReduction] , (* now perform main task *) ... do something ... , (* now cleanup *) SetOptions[RowReduce,method] ] It is certainly possible that this will migrate to a different context in a future release. But this functionality is not going to be removed, as we use it in far too many places. Daniel Lichtblau Wolfram Research
- References:
- locally changing Options
- From: hemmecke <hemmecke@gmail.com>
- locally changing Options