danprince / restack

🥞 Prototype for a concatenative programming language
https://restack.surge.sh
6 stars 0 forks source link

CSP vs FRP #15

Open danprince opened 8 years ago

danprince commented 8 years ago

Implement either CSP or FRP as a first class citizen. FRP is going to be simpler at a language level, but stack/stream could provide a bit clashy. Alternatively CSP could be implemented with some new syntax, but then the interpreter would need to be implemented using continuations from day one, which will result in slower generated code.

danprince commented 8 years ago

CSP

import (chan take put) from "async"

chan -- put a new channel onto the stack
take -- block until a value becomes available then put onto the stack

2 put -- example of putting values into the channel

Pros

Cons

FRP

import (-> subscribe) from "reactive"
import (map fold) from "frp"
import (by-id) from "dom"

"inc" by-id "click" -> -- creates an event stream of clicks
(1) map -- returns a new event stream with mapped values
(+) fold -- fold accumulated values with +
(print) subscribe -- print out running total

Pros

Cons

danprince commented 8 years ago

Idea: implement FRP with "reactive" stacks.

import (rstack) from "reactive"

("change" print) -- stack subscription function
rstack -- converts the current stack to a reactive one

"inc" by-id "click" -> -- put the click event onto the reactive stack and print "change"

-- re-implementation of last example
( drop 1 + dup print ) rstack
"inc" by-id "click" ->

Bit messy. End up with a sort of global function that has to deal with all stack reactions.

import (rstack) from "reactive"
import (dispatch) from "flux"

(
  :type get
  (:inc 1 :dec -1) match
  + dup print
) rstack

"inc" by-id "click" (:type "inc") dispatch
"dec" by-id "click" (:type "dec) dispatch

Similar mess, but potentially could compose the "reacting" function out of smaller dedicated event handlers.