Question

Is the 2htdp/universe teachpack a good (or bad, or not a) example of Functional Reactive Programming ?

It seems to fit the concept (a new state of the world build on each tick / input), but I never saw the FRP label associated with it.

Was it helpful?

Solution

The Racket programming language family comes with FrTime, a language that turns (most of) Racket into a FRP language. If you run this interaction at the prompt, for example,

> (current-time)
Tue Jul  2 09:31:06 EDT 2013

you constantly see the correct time. (Okay, this used to work with current-seconds; a bug report is in the works.) As far as I can tell, the frtime program views variables as streams of events and that idea is essential to FRP.

A universe program in contrast explicitly binds event handlers (and rendering functions) to certain OS hooks (e.g. mouse clicks). These handlers get the complete state and return the complete state plus requests for actions (e.g. message sending). In this sense, universe is not a FRP language.

If you were to separate languages into explicit vs implicit FRP languages, you might categorize the universe teachpack as an explicit FRP language.

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