R-alpha: Re: R-beta: ?faq example of scoping
Luke Tierney
luke@stat.umn.edu
Wed, 6 Aug 1997 15:59:51 -0500 (CDT)
Robert Gentleman wrote:
>
> I like Thomas' example. Kurt can you include it in the FAQ.
>
> Recently I have been doing a lot of programming that has required either
> optimization or zero-finding. Unfortunately most of the functions need
> some arguments to be optimized over and have other parameters that depend on
> the data but are fixed with respect to optimization. With R scoping rules
> this is a trivial problem; simply make up the function with the required
> definitions in the same environment and scoping takes care of it. With
> Splus my solution has been to add an extra parameter to the function and
> to the optimizer to pass in these extras. That's fine for optimizers I
> write myself but it doesn't work for the builtin ones. Fortunately I haven't
> yet found a one-d problem that some thought and bisection won't take care
> of.
>
> robert
>
There might also be some use for a clean dynamic scoping mechanism to
to make it easier to make things like the minimizers in optimize.c
reentrant. In 0.49 at least they use a static variable, and I think
things would go bad if they were called recursively. THis may not be
likely for a minimizer, but it would be very reasonable for an
integrator. You could save previous values of the globals on the C
stack, but with the need to provide protection for non-local exits on
errors this can get messy. A dynamic binding mechanism, preferably
with a separate name space like dynamic-bind stuff in Scheme, would
make this easier.
luke
--
Luke Tierney
University of Minnesota Phone: 612-625-7843
School of Statistics Fax: 612-624-8868
206 Church Street email: luke@stat.umn.edu
Minneapolis, MN 55455 USA WWW: http://www.stat.umn.edu
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-