TASK
An Investigation. R and tail recursion. Lazy evaluation in R.
SOLUTION
With a Google's help i found this message:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/73651.html
> Some functional languages have a feature called tail recursion that
> can provide performance improvements if you write your recursions
> to take advantage of it:
>
> http://en.wikipedia.org/wiki/Tail_recursion
>
> but I don't think R supports it. Is this likely to become available
> in R?
No. For a start, this is usually done by compilers, which we don't got.
In addition, it would be very difficult to do tail recursion optimization
and not break most of the sys.* functions, which give explicit access to
all the frames that would be optimized away.
-thomas
Alas, R doesn't have tail recursion optimization.
That explains last error messages about stack fault.
Now, what do they mean, when they write:
"R is a functional language, with lazy evaluation"?
Here is the answer:
http://tolstoy.newcastle.edu.au/R/help/03b/0731.html
"...R is a functional language, with lazy evaluation and weak dynamic
typing (a variable can change type at will: a <- 1 ; a <- "a" is
allowed). Semantically, everything is copy-on-modify although some
optimization tricks are used in the implementation to avoid the worst
inefficiencies.
Parameter passing is according to the "pass-by-value illusion", i.e.
what is really getting passed down to a function is a "promise", which
embodies the expression used in the call. This is at the core of the
lazy evaluation mechanism: The result of the expression is not
computed until needed. It also allows a function to get hold of the
the expression itself: This is useful for labeling plots but it also
allows some variants of "pass-by-name"-like semantics via evaluation
in the environment of the caller..."
But...
Extra!Extra!
I found more sensational materials...
"Besides lazy evaluation in R is not really lazy evaluation!"
http://www.postech.ac.kr/~gla/paper/R-ism-dec-8.ppt
CONCLUSIONS
So, my first impression, when i started this blog, was:
"Incredibly! Such perfect program for data analysis, visualization,
uses functional language." Now i see, R is not perfect.
понедельник, 22 октября 2007 г.
День третий (an investigation)
на
13:49
Подписаться на:
Комментарии к сообщению (Atom)

Комментариев нет:
Отправить комментарий