This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Define a function to send events | |
(defn event [k v] nil) | |
; Define the data structure used to model a component | |
(defstruct component-s :name :handlers :state) | |
; Create a component by creating an instance of the data structure | |
(defn make-component [name handlers] | |
(struct component-s name handlers {})) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(program | |
; Define a component. | |
(component "Comp1" | |
; Event handler for :init events | |
(on :init [v s] | |
; Trigger some events | |
(event :print nil) | |
(event :set-msg "Ho") | |
(event :print nil) | |
; Set this components state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro program [& components] | |
`(run-components ~@components)) | |
(defmacro component [name & handlers] | |
`(make-component ~name (conj {} ~@handlers))) | |
(defmacro on [handler args & body] | |
{handler `(fn ~args ~@body)}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(run-components | |
(make-component "Comp1" | |
{:init (fn [v s] | |
(event :set-msg "Ho") | |
(event :print nil) | |
{:msg "Hi"}) | |
:print (fn [v s] | |
(println (:msg s))) | |
:set-msg (fn [v s] | |
{:msg v})}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(run-components | |
(make-component "Comp1" | |
{:init (fn [v s] | |
(event :print nil) | |
(event :set-msg "Ho") | |
(event :print nil) | |
{:msg "Hi"}) | |
:print (fn [v s] | |
(println (:msg s))) | |
:set-msg (fn [v s] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun do-op a b op { | |
match op | |
with '+: a + b | |
with '-: a - b | |
with '*: a * b | |
with '/: a / b | |
with _: error | |
} | |
flow gen a b ops -> res { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@std.in; | |
a = [[int\]] <- 0; | |
op = [[char\]] <- ' '; | |
b = [[int\]] <- 0; | |
r = [[int\]] <- 0; | |
0 { | |
clock => [[int ms]] { | |
("\r" + ms/1000.0 + ":" + a + op + b + "=" + r) ->std.out; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <list> | |
#include <iostream> | |
// Replace with real mutex. | |
class Mutex | |
{ | |
public: | |
void lock () {} | |
void unlock () {} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T> void map (std::deque<T> list, void (*f) (T)) { | |
for (std::deque<T>::iterator iter = list.begin(); iter != list.end(); iter++) { | |
#ifdef PARALLEL_MAP | |
ThreadPool::getIdle()->run<T>(f, *iter); | |
#else | |
f(*iter); | |
#endif | |
} | |
} | |
template <class T, class A1> void map (std::deque<T> list, void (*f) (T, A1), A1 arg1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef unsigned int MessageID; | |
typedef unsigned int Conversation; | |
class Message | |
{ | |
public: | |
virtual ~Message () {} | |
virtual const MessageID& messageID () const=0; | |
virtual const char* senderName () const=0; | |
}; |
OlderNewer