开发者

What is the programming paradigm of R?

开发者 https://www.devze.com 2023-03-08 05:41 出处:网络
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 lan

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 sur开发者_开发知识库e which paradigm R is supposed to represent.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消