Re: [R] Formal definitions of R-language.

2003-07-20 Thread Richard A. O'Keefe
Murad Nayal [EMAIL PROTECTED] wrote:
recursion, as far as I know, is inefficient in
S/R. which tend to discourage purely functional programming.

It's not so much that _recursion_ is slow, as that function calling
is slow (whether recursive or not).  A large part of the reason is
that the S function calling convention was designed to favour
human ease-of-use much more than ease of compilation.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Formal definitions of R-language.

2003-07-20 Thread Thomas Lumley
On Mon, 21 Jul 2003, Richard A. O'Keefe wrote:

 Murad Nayal [EMAIL PROTECTED] wrote:
   recursion, as far as I know, is inefficient in
   S/R. which tend to discourage purely functional programming.

 It's not so much that _recursion_ is slow, as that function calling
 is slow (whether recursive or not).  A large part of the reason is
 that the S function calling convention was designed to favour
 human ease-of-use much more than ease of compilation.


The biggest problem with recursion in comparison to languages like Scheme
and compiled LISPs may be that R can't eliminate any of the recursions.
Even tail-recursion elimination (which is compulsory in Scheme) isn't
possible without changing the semantics of the language, because functions
like sys.frame() give access to all the frames that would be optimised out
of existence.

In my experience recursive functions run reasonably well in R until they
hit the stack limit.

-thomas

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Formal definitions of R-language.

2003-07-17 Thread M.Kondrin
Hello!
Some CS-guys (the type who knows what Church formalism is) keep asking 
me questions about formal definitions of R-language that I can not 
answer (or even understand). Is there some freely available papers which 
I can throw at them where it would be explained is R 
functional/OOP/procedural language, does it use weak/strong, 
dynamic/static typization, does it use lazy or ...(do not know what) 
evaluation, what sort of garbage collector it uses?
Thanks.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Formal definitions of R-language.

2003-07-17 Thread Uwe Ligges
M.Kondrin wrote:

Hello!
Some CS-guys (the type who knows what Church formalism is) keep asking 
me questions about formal definitions of R-language that I can not 
answer (or even understand). Is there some freely available papers which 
I can throw at them where it would be explained is R 
functional/OOP/procedural language, does it use weak/strong, 
dynamic/static typization, does it use lazy or ...(do not know what) 
evaluation, what sort of garbage collector it uses?
Thanks.
R ships with a draft version of the manual R Language Definition.
Another source is Venables  Ripley (2000): S Programming, Springer.
Uwe Ligges

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Formal definitions of R-language.

2003-07-17 Thread Douglas Trainor
Uwe Ligges wrote:

M.Kondrin wrote:

Hello!
Some CS-guys (the type who knows what Church formalism is) keep 
asking me questions about formal definitions of R-language that I can 
not answer (or even understand). Is there some freely available 
papers which I can throw at them where it would be explained is R 
functional/OOP/procedural language, does it use weak/strong, 
dynamic/static typization, does it use lazy or ...(do not know what) 
evaluation, what sort of garbage collector it uses?
Thanks.


R ships with a draft version of the manual R Language Definition.
Another source is Venables  Ripley (2000): S Programming, Springer. 


Tell the CS-guys to grab the source code and chew on the LALR 
context-free grammar stuff in the file gram.y as in:

   R-1.7.1/src/main/gram.y

R Language Definition lives at:

   http://cran.r-project.org/doc/manuals/R-lang.pdf

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Formal definitions of R-language.

2003-07-17 Thread M.Kondrin
Douglas Trainor wrote:
Uwe Ligges wrote:

M.Kondrin wrote:

Hello!
Some CS-guys (the type who knows what Church formalism is) keep 
asking me questions about formal definitions of R-language that I can 
not answer (or even understand). Is there some freely available 
papers which I can throw at them where it would be explained is R 
functional/OOP/procedural language, does it use weak/strong, 
dynamic/static typization, does it use lazy or ...(do not know what) 
evaluation, what sort of garbage collector it uses?
Thanks.


R ships with a draft version of the manual R Language Definition.
Another source is Venables  Ripley (2000): S Programming, Springer. 


Tell the CS-guys to grab the source code and chew on the LALR 
context-free grammar stuff in the file gram.y as in:

   R-1.7.1/src/main/gram.y

R Language Definition lives at:

   http://cran.r-project.org/doc/manuals/R-lang.pdf





Thanks for your answers!
I have already read R Language Definition but it is rather hmmm... 
evasive (?). For example:

 R belongs to a class of programming languages in which subroutines
have the ability to modify or construct other subroutines and evaluate
the result as an integral part of the language itself.  This is similar
to Lisp and Scheme and other languages of the functional programming
variety, but in contrast to FORTRAN and the ALGOL family.
Being similar to other functional programming language does not mean 
being the one itself, or does it? About typing it (not this passage I 
mean but RLD in a whole) said nothing.
This thing about LALR is very good. I will try it on them.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Formal definitions of R-language.

2003-07-17 Thread Murad Nayal


some comments. I am still learning S/R so please let me know if I am
missing something.

M.Kondrin wrote:
 
 Hello!
 Some CS-guys (the type who knows what Church formalism is) keep asking
 me questions about formal definitions of R-language that I can not
 answer (or even understand). Is there some freely available papers which
 I can throw at them where it would be explained is R
 functional/OOP/procedural language,

R is object oriented in the sense that the basic entities of the
language (data elements, language elements etc.) are complex entities
with type and defined behavior (objects). it has inheritance,
polymorphism, operator overloading etc. you can define constructors for
objects, but as far as I know no destructors (you can define clean up
routines on libraries though).

it has has elements of being a functional language like the fact that
programs are composed of expressions that are turned into function
objects that get evaluated. it also supports lambda expressions. it is
not a pure functional language because functions can and do have side
effects, it has persistent state and assignments, and it has flow of
control statements. also, recursion, as far as I know, is inefficient in
S/R. which tend to discourage purely functional programming.

 does it use weak/strong,

weak typing. variables are not typed and keep type information once
constructed. conversion between types is often automatic or can be
programmed to be so, hence operations on disparate types can often be
carried out.

 dynamic/static typization,

it is dynamically typed. objects carry and supply type information at
run time. types (as well as behavior) can (only) be defined at run time.
the S-evaluator has to start first, it then constructs class and
function definitions in the run-time environment. object type can be
changed, modified and augmented at run time, at least with old style
classes, (can you add or remove slots in the new style classes?).

 does it use lazy or ...(do not know what)
 evaluation,

uses lazy evaluation of expressions. expressions are constructed by the
S-evaluator, but not evaluated until needed.

 what sort of garbage collector it uses?

No garbage collector. uses reference counting to discard objects that
are no longer needed.


 Thanks.
 
 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help

-- 
Murad Nayal M.D. Ph.D.
Department of Biochemistry and Molecular Biophysics
College of Physicians and Surgeons of Columbia University
630 West 168th Street. New York, NY 10032
Tel: 212-305-6884   Fax: 212-305-6926

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Formal definitions of R-language.

2003-07-17 Thread Thomas Lumley
On Thu, 17 Jul 2003, M.Kondrin wrote:

 Douglas Trainor wrote:
 
  Tell the CS-guys to grab the source code and chew on the LALR
  context-free grammar stuff in the file gram.y as in:
 
 R-1.7.1/src/main/gram.y
 
  R Language Definition lives at:
 
 http://cran.r-project.org/doc/manuals/R-lang.pdf
 
 
 Thanks for your answers!

I don't think the grammar will actually answer their questions -- it
doesn't specify a lot of the things you (they) are interested in.

R doesn't really conform to purist classifications of languages (I tell
C++ programmers that they would be happier if they think of the old method
system as providing operator overloading rather objects). Luke Tierney
would probably be the best person to reply but here's a stab at what they
want:

R has dynamic typing, and static lexical scoping.  Functions are
first-class objects but assignments to change variables are allowed and
widely used.  It has lazy evaluation of arguments. It has a non-copying
garbage collector but does not have continuations or tail recursion
optimisation.  Operations that would naturally be written using dynamic
scope or macros are faked by constructing expressions and evaluating them
in other than the default environment.

There are two object systems.  Both provide polymorphism and (multiple)
inheritance but do not restrict access to the internal structure of
objects.

Documentation for some things (methods, namespaces, the garbage collector)
is at http://developer.r-project.org


-thomas

Thomas Lumley   Assoc. Professor, Biostatistics
[EMAIL PROTECTED]   University of Washington, Seattle

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Formal definitions of R-language.

2003-07-17 Thread Peter Dalgaard BSA
[Oops. Accidentally sent only to D.Trainor first time around, even
though it was intended mainly for M.Kondrin and the list]

Douglas Trainor [EMAIL PROTECTED] writes:

 Uwe Ligges wrote:
 
  M.Kondrin wrote:
 
  Hello!
  Some CS-guys (the type who knows what Church formalism is) keep
  asking me questions about formal definitions of R-language that I
  can not answer (or even understand). Is there some freely available
  papers which I can throw at them where it would be explained is R
  functional/OOP/procedural language, does it use weak/strong,
  dynamic/static typization, does it use lazy or ...(do not know
  what) evaluation, what sort of garbage collector it uses?
  Thanks.
 
 
  R ships with a draft version of the manual R Language Definition.
  Another source is Venables  Ripley (2000): S Programming, Springer.
 
 
 Tell the CS-guys to grab the source code and chew on the LALR
 context-free grammar stuff in the file gram.y as in:
 
 R-1.7.1/src/main/gram.y

Don't. You'll get laughed out... The grammar of the language is
essentially unrelated to the kind of categorizations CS people are
looking for.

Probably, Robert Gentleman or Luke Tierney are the guys best qualified
to answer the question, but I can give a try:

R is quite close to being Scheme plus syntactic sugar. Lexical
scoping and function closures comes directly from Scheme and the
internal structure of calls and functions (i.e. that they are
equivalent to lists so that you can do things like
 
  e - quote(2+2) ; lapply(e,deparse)

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.

R is not object oriented in the same sense as Java or C++. We don't
(generally) have methods that are semantically part of objects. However,
we do have class-based function dispatch and generic functions, so
that a function can do different things of different kind of objects,
and - with the S4 class system - also for combinations of objects.

Other distinctive features are that basic operations are vectorized,
and that (somewhat perversly to LISP programmers) the traditional
dotted-pair list lives quite deeply hidden from users, whereas the
thing called list in R is really a generic vector where each element
can be of different type. [This is not the only place where we have
some rather unfortunate clashes in terminology between the S language
(which is historically of APL descent) and the Scheme-like engine
underneath.]

Some implementation stuff is documented in sketches on
developer.r-project.org (do read the opening paragraph!) and the
intention is to have it documented in the R Language Definition,
although that is still rather incomplete (and as Thomas Lumley once
put it, it would be desirable if one could truthfully say that it is
a work in progress). Also of course, there is the paper by Ross and
Robert in JCGS.

-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Formal definitions of R-language.

2003-07-17 Thread Peter Dalgaard BSA
Murad Nayal [EMAIL PROTECTED] writes:

[Sensible stuff, except:]
  what sort of garbage collector it uses?
 
 No garbage collector. uses reference counting to discard objects that
 are no longer needed.

No, R uses garbage collection with a generational scheme which looks
more frequently at younger objects. The vector heap is handled with
standard malloc-style memory allocation techniques (we once had code
that would compact the heap during garbage collection, but it was
found to be logically inconsistent: if you called a C routine and it
called back into R and triggered a GC, it could happen that the C
pointers were no longer pointing to the vectors they originally did).

-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help