Question

What is the programming paradigm of R (R as in GNU S)?

I believe myself familiar with programming languages of different conceptual paradigms (have programmend in C++, Java, Prolog and some other languages) but although I already write my own small R scripts, I am not sure which paradigm R is supposed to represent.

Was it helpful?

Solution

R supports a mixture of object-oriented and functional programming paradigms.

On the functional side it:

  • has first class functions
  • has lazy evaluation of arguments
  • encourages pure, side-effect free functions

But

  • it does not implement tail call recursion
  • and it's easy to create non-pure functions

On the object oriented side:

  • it has three built in OO paradigms: S3 and S4, which are immutable and support generic function style OO, and reference classes (aka R5) which are mutable, and support the more common message-passing style OO.

  • S4 is heavily influenced by the OO-style of common lisp (CLOS) and dylan.

  • There are also a number of contributed packages that provide other types of OO: proto, mutatr, R.oo, OOP.

But

  • The built-in OO tools provide little in the way of syntactic sugar.

OTHER TIPS

According to Wikipedia (emphasis added),

R supports procedural programming with functions and object-oriented programming with generic functions. A generic function acts differently depending on the type of arguments it is passed. In other words the generic function recognizes the type of object and selects (dispatches) the function (method) specific to that type of object. For example, R has a generic print() function that can print almost every type of object in R with a simple "print(objectname)" syntax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top