-1

I had been using react-js and really like its concept so I want to know if there is a programming language/framework that sort of works like it. For instance, I want to define:

var A = something
var B = somefun(var A)

They could live in different objects, modules, files, etc. The important part is that I want to link B to the value of A so that eveI had been using react-js and really like its concept so I want to know if there is a programming language/framework that sort of works like it. For instance, I want to define: ry time that I check B, it is calculated again. I want to know if there is a framework/language with support for this kind of statements.

Thanks in advance.

2
  • 1
    Pretty much all functional languages will support reactive programming try looking for FRP (functional reactive programming)
    – jk.
    Commented Mar 27, 2019 at 16:58
  • I'd suggest you check out Clojure / Reagent. Immutability is fundamental to Clojure, so React (as wrapped for Clojure purposes by Reagent) is very natural in that language. Commented Mar 28, 2019 at 14:49

1 Answer 1

2

The easy solution in nearly every programming language is to make that dependent value B a function. Instead of accessing the variable, you would call the function:

var B = () => somefun(A)

// later:
doSomethingWith(B())

Some languages have systems that allow things to look like ordinary variables or properties but actually call a function on access, for example properties (JavaScript, C#, Python) or magic (Perl).

The issue with this is efficiency, and that the data flow is unidirectional. That's why there are many different approaches to implement reactive systems, e.g. pull-based vs push-based models, observer-based systems, or caching-based systems. More complex systems need a Reactor that propagates events through the network of data dependencies.

No commonly used language has first class support for reactive programming, though JavaScript and Scala have very mature libraries, Haskell gets rid of the “change” problem, and Excel spreadsheets offer a reactive system but aren't really a programming language.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.