├── LICENSE ├── README.md ├── doc ├── demand-matcher.dot ├── demand-matcher.md └── demand-matcher.png ├── examples ├── ircd │ ├── .gitignore │ ├── Makefile │ ├── TODO.md │ ├── channel.rkt │ ├── config.rkt │ ├── main.rkt │ ├── message.rkt │ ├── protocol.rkt │ └── session.rkt ├── netstack │ ├── .gitignore │ ├── README.md │ ├── TODO.md │ ├── incremental-highlevel │ │ ├── Makefile │ │ ├── arp.rkt │ │ ├── checksum.rkt │ │ ├── configuration.rkt │ │ ├── cpingresp.c │ │ ├── demo-config.rkt │ │ ├── dump-bytes.rkt │ │ ├── ethernet.rkt │ │ ├── fetchurl.rkt │ │ ├── ip.rkt │ │ ├── main.rkt │ │ ├── pingresp.rkt │ │ ├── port-allocator.rkt │ │ ├── tcp.rkt │ │ └── udp.rkt │ └── monolithic-lowlevel │ │ ├── Makefile │ │ ├── arp.rkt │ │ ├── checksum.rkt │ │ ├── configuration.rkt │ │ ├── demo-config.rkt │ │ ├── dump-bytes.rkt │ │ ├── ethernet.rkt │ │ ├── fetchurl.rkt │ │ ├── ip.rkt │ │ ├── main.rkt │ │ ├── on-claim.rkt │ │ ├── port-allocator.rkt │ │ ├── tcp.rkt │ │ └── udp.rkt ├── operational-transformation │ ├── .gitignore │ ├── README.md │ ├── syndicate-multiserver.rkt │ └── syndicate-server.rkt ├── platformer │ ├── .gitignore │ ├── beautiful-grassland-wallpapers-1920x1080.jpg │ ├── hll-main.rkt │ ├── info.rkt │ ├── lll-main.rkt │ └── sounds │ │ ├── 270302__littlerobotsoundfactory__collect-point-02.wav │ │ ├── 270303__littlerobotsoundfactory__collect-point-01.wav │ │ ├── 270304__littlerobotsoundfactory__collect-point-00.wav │ │ ├── 270305__littlerobotsoundfactory__climb-rope-loop-00.wav │ │ ├── 270306__littlerobotsoundfactory__explosion-02.wav │ │ ├── 270307__littlerobotsoundfactory__explosion-01.wav │ │ ├── 270308__littlerobotsoundfactory__explosion-00.wav │ │ ├── 270309__littlerobotsoundfactory__craft-00.wav │ │ ├── 270310__littlerobotsoundfactory__explosion-04.wav │ │ ├── 270311__littlerobotsoundfactory__explosion-03.wav │ │ ├── 270315__littlerobotsoundfactory__menu-navigate-03.wav │ │ ├── 270316__littlerobotsoundfactory__open-00.wav │ │ ├── 270317__littlerobotsoundfactory__jump-01.wav │ │ ├── 270318__littlerobotsoundfactory__jump-02.wav │ │ ├── 270319__littlerobotsoundfactory__jingle-win-01.wav │ │ ├── 270320__littlerobotsoundfactory__jump-00.wav │ │ ├── 270321__littlerobotsoundfactory__menu-navigate-01.wav │ │ ├── 270322__littlerobotsoundfactory__menu-navigate-02.wav │ │ ├── 270323__littlerobotsoundfactory__jump-03.wav │ │ ├── 270324__littlerobotsoundfactory__menu-navigate-00.wav │ │ ├── 270325__littlerobotsoundfactory__hit-02.wav │ │ ├── 270326__littlerobotsoundfactory__hit-01.wav │ │ ├── 270327__littlerobotsoundfactory__hit-00.wav │ │ ├── 270328__littlerobotsoundfactory__hero-death-00.wav │ │ ├── 270329__littlerobotsoundfactory__jingle-lose-00.wav │ │ ├── 270330__littlerobotsoundfactory__jingle-achievement-01.wav │ │ ├── 270331__littlerobotsoundfactory__jingle-achievement-00.wav │ │ ├── 270332__littlerobotsoundfactory__hit-03.wav │ │ ├── 270333__littlerobotsoundfactory__jingle-win-00.wav │ │ ├── 270334__littlerobotsoundfactory__jingle-lose-01.wav │ │ ├── 270335__littlerobotsoundfactory__shoot-03.wav │ │ ├── 270336__littlerobotsoundfactory__shoot-02.wav │ │ ├── 270337__littlerobotsoundfactory__pickup-00.wav │ │ ├── 270338__littlerobotsoundfactory__open-01.wav │ │ ├── 270339__littlerobotsoundfactory__pickup-02.wav │ │ ├── 270340__littlerobotsoundfactory__pickup-01.wav │ │ ├── 270341__littlerobotsoundfactory__pickup-04.wav │ │ ├── 270342__littlerobotsoundfactory__pickup-03.wav │ │ ├── 270343__littlerobotsoundfactory__shoot-01.wav │ │ ├── 270344__littlerobotsoundfactory__shoot-00.wav │ │ └── _readme_and_license.txt └── webchat │ ├── NOTES.md │ ├── htdocs │ ├── Text-x-generic.svg │ ├── linkify-string.min.js │ ├── linkify.min.js │ ├── speechbubble-l.png │ ├── speechbubble-l.svg │ ├── speechbubble-r.png │ ├── speechbubble-r.svg │ ├── style.css │ ├── templates │ │ ├── contact-entry.html │ │ ├── conversation-index-entry.html │ │ ├── grant-entry.html │ │ ├── invitee-entry.html │ │ ├── nav-account.html │ │ ├── option-question.html │ │ ├── page-contacts.html │ │ ├── page-conversations.html │ │ ├── page-my-requests.html │ │ ├── page-new-chat.html │ │ ├── page-permissions.html │ │ ├── page-questions.html │ │ ├── permission-entry.html │ │ ├── permission-request-in-GENERIC.html │ │ ├── permission-request-in-p:follow.html │ │ ├── permission-request-out-GENERIC.html │ │ ├── permission-request-out-p:follow.html │ │ ├── post-entry.html │ │ ├── post-item-application-octet-stream.html │ │ ├── post-item-image.html │ │ ├── post-item-text-plain.html │ │ └── post-item.html │ └── webchat.syndicate.js │ └── server │ ├── .gitignore │ ├── TODO.md │ ├── account.rkt │ ├── api.rkt │ ├── config.rkt │ ├── contacts.rkt │ ├── conversation.rkt │ ├── duplicate.rkt │ ├── main.rkt │ ├── pages.rkt │ ├── protocol.rkt │ ├── qa.rkt │ ├── run │ ├── script-compiler.rkt │ ├── session-cookie.rkt │ ├── static-content.rkt │ ├── testdata.rkt │ ├── trust.rkt │ └── util.rkt ├── historical ├── README.md └── syndicate-monolithic │ ├── README.md │ ├── core.rkt │ ├── demand-matcher.rkt │ ├── drivers │ ├── tcp.rkt │ ├── timer.rkt │ ├── udp.rkt │ └── websocket.rkt │ ├── examples │ ├── .gitignore │ ├── Makefile │ ├── bank-account.rkt │ ├── box-and-client.rkt │ ├── chat-client.rkt │ ├── chat-no-quit-world-no-nesting.rkt │ ├── echo.rkt │ ├── example-lang.rkt │ ├── example-layer.rkt │ ├── example-meta-echo.rkt │ ├── example-meta-echo2.rkt │ ├── example-plain.rkt │ ├── example-quit-world.rkt │ ├── mini-echo.rkt │ ├── tcp-hello.rkt │ ├── udp-hello-plain.rkt │ ├── ws-hello-ssl.rkt │ └── ws-hello.rkt │ ├── ground.rkt │ ├── lang.rkt │ ├── lang │ └── reader.rkt │ ├── main.rkt │ ├── mux.rkt │ ├── scn.rkt │ └── trace │ └── stderr.rkt ├── hs ├── .gitignore ├── Setup.hs ├── src │ └── Syndicate │ │ └── Dataspace │ │ └── Trie │ │ ├── ESOP2016.hs │ │ ├── ESOP2016v2.hs │ │ ├── ESOP2016v3.hs │ │ └── Prefix.hs ├── syndicate.cabal └── test │ ├── Main.hs │ └── Syndicate │ └── Dataspace │ └── Trie │ └── Tests │ ├── ESOP2016.hs │ ├── ESOP2016v2.hs │ ├── ESOP2016v3.hs │ └── Prefix.hs ├── js ├── .gitignore ├── Makefile ├── README.md ├── bin │ └── syndicatec ├── compiler │ ├── README.md │ ├── compiler.js │ ├── demo-bad-this.js │ ├── demo-bankaccount.js │ ├── demo-during-criterion-snapshotting.js │ ├── demo-filesystem.js │ ├── demo-nested-during.js │ ├── demo-proper-interest-tracking.js │ ├── demo-synthetic-patch-2.js │ ├── es5.js │ ├── es5.ohm │ ├── inbrowser.js │ └── syndicate.ohm ├── dist │ └── README.md ├── examples │ ├── button │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── index.html │ │ └── index.js │ ├── chat │ │ ├── index.html │ │ ├── index.js │ │ └── style.css │ ├── dom-webworker │ │ ├── Makefile │ │ ├── index.html │ │ ├── index.js │ │ └── worker.js │ ├── dom │ │ ├── index.html │ │ └── index.js │ ├── eve │ │ └── crazy-mikes │ │ │ ├── index.html │ │ │ ├── index.js │ │ │ └── style.css │ ├── index.md │ ├── iot │ │ ├── img │ │ │ ├── flames.gif │ │ │ ├── remote.png │ │ │ ├── stove-coil-element-cold.jpg │ │ │ ├── stove-coil-element-hot.jpg │ │ │ └── tvscreen.gif │ │ ├── index.html │ │ ├── index.js │ │ ├── iot-example.png │ │ └── style.css │ ├── location │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── index.html │ │ ├── index.js │ │ └── style.css │ ├── mixin │ │ ├── Makefile │ │ ├── index.html │ │ └── index.js │ ├── motion │ │ ├── index.html │ │ ├── index.js │ │ ├── style.css │ │ └── tinycolor.js │ ├── smoketest-dsl │ │ ├── index.html │ │ └── index.js │ ├── smoketest │ │ ├── index.html │ │ └── index.js │ ├── svg │ │ ├── index.html │ │ └── index.js │ ├── table │ │ ├── index.html │ │ └── index.js │ ├── textfield-dsl │ │ ├── index.html │ │ ├── index.js │ │ └── style.css │ ├── textfield │ │ ├── index.html │ │ ├── index.js │ │ └── style.css │ ├── todo │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── css │ │ │ └── app.css │ │ ├── index.html │ │ ├── index.js │ │ ├── node_modules │ │ │ ├── todomvc-app-css │ │ │ │ └── index.css │ │ │ └── todomvc-common │ │ │ │ └── base.css │ │ └── todomvc-screenshot.png │ └── two-buyer-protocol │ │ ├── .gitignore │ │ ├── Makefile │ │ └── index.js ├── package.json ├── src │ ├── ack.js │ ├── actor.js │ ├── broker.js │ ├── codec.js │ ├── dataflow.js │ ├── dataspace.js │ ├── demand-matcher.js │ ├── ground.js │ ├── main.js │ ├── mapset.js │ ├── mux.js │ ├── patch.js │ ├── randomid.js │ ├── reflect.js │ ├── seal.js │ ├── special.js │ ├── struct.js │ ├── timer-driver.js │ ├── trie.js │ ├── ui.js │ ├── util.js │ ├── wake-detector-driver.js │ └── worker.js ├── test │ ├── test-dataflow.js │ ├── test-mux.js │ ├── test-patch.js │ ├── test-route.js │ ├── test-syndicate.js │ └── test-trie.js └── third-party │ └── jquery-2.2.0.min.js └── racket ├── .gitignore ├── FAQ.md ├── Makefile ├── README.md ├── doc ├── forward-chaining-hll.rkt.txt ├── forward-chaining-hll2.rkt.txt ├── forward-chaining-hll3.rkt.txt ├── forward-chaining-hll4.rkt.txt └── notes-on-hll.md ├── info.rkt ├── syndicate-gl ├── 2d.rkt ├── TODO.md ├── affine.rkt ├── examples │ ├── basic.rkt │ ├── clock-face.rkt │ └── many.rkt ├── info.rkt ├── scribblings │ └── syndicate-gl.scrbl └── texture.rkt ├── syndicate-gui-toolbox ├── examples │ └── 7-GUIS │ │ ├── cells-canvas.rkt │ │ ├── task-1.rkt │ │ ├── task-2.rkt │ │ ├── task-3.rkt │ │ ├── task-4.rkt │ │ ├── task-5.rkt │ │ ├── task-6.rkt │ │ └── task-7.rkt ├── info.rkt └── widgets.rkt ├── syndicate-ide ├── hsv.rkt ├── info.rkt └── main.rkt ├── syndicate ├── actor-lang.rkt ├── actor.rkt ├── big-bang.rkt ├── big-bang │ └── timestate.rkt ├── broker │ ├── protocol.rkt │ └── server.rkt ├── canonicalize.rkt ├── comprehensions.rkt ├── core-lang.rkt ├── core.rkt ├── dataflow.rkt ├── dataspace.rkt ├── demand-matcher.rkt ├── drivers │ ├── config.rkt │ ├── filesystem.rkt │ ├── gui.rkt │ ├── irc.rkt │ ├── line-reader.rkt │ ├── repl.rkt │ ├── smtp.rkt │ ├── tcp.rkt │ ├── tcp2.rkt │ ├── timer.rkt │ ├── timestate.rkt │ ├── udp.rkt │ ├── web.rkt │ └── websocket.rkt ├── examples │ ├── .gitignore │ ├── Makefile │ ├── actor │ │ ├── add1-simple.rkt │ │ ├── bank-account.rkt │ │ ├── big-bang.rkt │ │ ├── box-and-client.rkt │ │ ├── broadcast-messages.rkt │ │ ├── ceu-leds.rkt │ │ ├── chain.rkt │ │ ├── chat-bot.rkt │ │ ├── chat-client-tcp2.rkt │ │ ├── chat-client.rkt │ │ ├── chat-multiroom-topic-persist.rkt │ │ ├── chat-multiroom-topic.rkt │ │ ├── chat-multiroom.rkt │ │ ├── chat-no-quit-world-no-nesting.rkt │ │ ├── chat-no-quit-world.rkt │ │ ├── chat-simplified-internals.rkt │ │ ├── chat-simplified-internals2.rkt │ │ ├── chat-tcp2.rkt │ │ ├── chat.rkt │ │ ├── cleanup.rkt │ │ ├── double-click.rkt │ │ ├── echo.rkt │ │ ├── example-action-after-suspension.rkt │ │ ├── example-assertion-spike.rkt │ │ ├── example-bug-query-scope.rkt │ │ ├── example-bug-rising-edge-true.rkt │ │ ├── example-demand-matcher-glitch-bug.buggy.msd │ │ ├── example-demand-matcher-glitch-bug.buggy.png │ │ ├── example-demand-matcher-glitch-bug.fixed1.msd │ │ ├── example-demand-matcher-glitch-bug.fixed1.png │ │ ├── example-demand-matcher-glitch-bug.fixed2.msd │ │ ├── example-demand-matcher-glitch-bug.fixed2.png │ │ ├── example-demand-matcher-glitch-bug.rkt │ │ ├── example-demand-matcher-glitch-bug2.buggy.msd │ │ ├── example-demand-matcher-glitch-bug2.buggy.png │ │ ├── example-demand-matcher-glitch-bug2.rkt │ │ ├── example-during-criterion-snapshotting.rkt │ │ ├── example-filesystem.rkt │ │ ├── example-glitch.rkt │ │ ├── example-memoized.rkt │ │ ├── example-multiple-suspension-resumption.rkt │ │ ├── example-partial-retraction.rkt │ │ ├── example-responsibility-transfer-1.rkt │ │ ├── example-responsibility-transfer-2.rkt │ │ ├── example-supervise.rkt │ │ ├── example-synthetic-patch-2.rkt │ │ ├── example-synthetic-patch.rkt │ │ ├── example-termination-scripts-1.rkt │ │ ├── example-termination-scripts-2.rkt │ │ ├── f-to-c.rkt │ │ ├── f-to-c2.rkt │ │ ├── f-to-c3.rkt │ │ ├── f-to-c4.rkt │ │ ├── f-to-c5.rkt │ │ ├── fib-server.rkt │ │ ├── file-system-during.rkt │ │ ├── file-system-during2.rkt │ │ ├── file-system-lll.rkt │ │ ├── file-system-lll2.rkt │ │ ├── file-system-script │ │ ├── file-system.rkt │ │ ├── file-system2.rkt │ │ ├── firewall-demo.rkt │ │ ├── flink.rkt │ │ ├── flip-flop.rkt │ │ ├── forward-chaining-mini.rkt │ │ ├── fs-protocol.rkt │ │ ├── fs-shell.rkt │ │ ├── gui.rkt │ │ ├── internal-knowledge.rkt │ │ ├── irc-client.rkt │ │ ├── irc.rkt │ │ ├── lambda.rkt │ │ ├── let-event.rkt │ │ ├── lorem.txt │ │ ├── make.rkt │ │ ├── mini-echo.rkt │ │ ├── mutable-cell.rkt │ │ ├── mutex.rkt │ │ ├── parameters.rkt │ │ ├── query-set.rkt │ │ ├── queue-no-credit.rkt │ │ ├── queue-no-credit2.rkt │ │ ├── queue.rkt │ │ ├── realize.rkt │ │ ├── rpc-with-error.rkt │ │ ├── running-total.rkt │ │ ├── sandbox-os.rkt │ │ ├── show-field-scope-enforcement1.rkt │ │ ├── show-field-scope-enforcement4.rkt │ │ ├── simple-cross-layer.rkt │ │ ├── simple-dns.rkt │ │ ├── spreadsheet-script │ │ ├── spreadsheet.rkt │ │ ├── tcp-relay.rkt │ │ ├── tcp-relay2.rkt │ │ ├── timestate.rkt │ │ ├── two-buyer-protocol.rkt │ │ ├── udp-echo.rkt │ │ ├── vacuous-facet.rkt │ │ ├── web-demo.rkt │ │ └── web-sanity-check.rkt │ ├── all-pairs-shortest-paths │ │ ├── all-pairs-shortest-paths.rb │ │ ├── all-pairs-shortest-paths.rkt │ │ ├── all-pairs-shortest-paths2.rb │ │ ├── all-pairs-shortest-paths2.rkt │ │ └── all-pairs-shortest-paths3.rkt │ ├── bank-account-monolithic.rkt │ ├── bank-account.rkt │ ├── big-bang.rkt │ ├── box-and-client.rkt │ ├── chat-client.rkt │ ├── chat-no-quit-world-no-nesting.rkt │ ├── chat-no-quit-world.rkt │ ├── chat-simplified-internals.rkt │ ├── chat.rkt │ ├── durable-key-value-store.rkt │ ├── echo.rkt │ ├── example-lang.rkt │ ├── example-layer.rkt │ ├── example-meta-drop.rkt │ ├── example-meta-echo.rkt │ ├── example-meta-echo2.rkt │ ├── example-plain.rkt │ ├── example-quit-dataspace-with-assertion.rkt │ ├── example-quit-world.rkt │ ├── example-swap-int-and-claim.rkt │ ├── example-wildcard-assertion-1.rkt │ ├── example-wildcard-assertion-2.rkt │ ├── forward-chaining.rkt │ ├── key-value-store.rkt │ ├── mini-echo.rkt │ ├── tcp-hello.rkt │ ├── two-buyer-protocol-incremental.rkt │ ├── two-buyer-protocol-monolithic.rkt │ ├── udp-hello-plain.rkt │ ├── udp-multicast.rkt │ ├── ws-echo-client.rkt │ ├── ws-echo.rkt │ ├── ws-hello-ssl.rkt │ └── ws-hello.rkt ├── firewall.rkt ├── functional-queue.rkt ├── ground.rkt ├── hash-order.rkt ├── hierarchy.rkt ├── info.rkt ├── interactive-lang.rkt ├── interactive.rkt ├── lang.rkt ├── lang │ └── reader.rkt ├── little-actors │ └── core.rkt ├── main.rkt ├── monitor.rkt ├── monolithic.rkt ├── monolithic │ ├── core.rkt │ └── scn.rkt ├── mux.rkt ├── patch.rkt ├── pattern.rkt ├── persist.rkt ├── pretty.rkt ├── profile.rkt ├── protocol │ ├── advertise.rkt │ ├── instance.rkt │ └── standard-relay.rkt ├── random-test.rkt ├── relay.rkt ├── reload.rkt ├── scribblings │ ├── interactive.scrbl │ └── syndicate.scrbl ├── store.rkt ├── supervise.rkt ├── supervisor.rkt ├── support │ ├── bytes.rkt │ ├── hash.rkt │ └── struct.rkt ├── syntax-classes.rkt ├── test-lang.rkt ├── test.rkt ├── test │ └── test-dataspace.rkt ├── tests │ ├── bank-account.rkt │ ├── boop.rkt │ ├── create-new-facet-in-on-stop.rkt │ ├── facet-creation-during-stop-from-grandchild.rkt │ ├── maintain-knowledge-across-events.rkt │ ├── multi-level-message.rkt │ ├── multi-level-other-way.rkt │ ├── nested-spawn-exceptions.rkt │ ├── ping-pong.rkt │ ├── simple-multi-level.rkt │ ├── simple1.rkt │ ├── stop-when-react.rkt │ └── use-current-knowledge-with-new-facet.rkt ├── threaded.rkt ├── trace.rkt ├── trace │ ├── msd.rkt │ ├── render-msd.rkt │ ├── stderr.rkt │ └── util.rkt ├── treap.rkt ├── trie.rkt ├── tset.rkt ├── upside-down.rkt └── util.rkt └── typed ├── .gitignore ├── Makefile ├── core.rkt ├── examples ├── anonymous-facet.rkt ├── bank-account.rkt ├── book-club.rkt ├── cell.rkt ├── chat-tcp2.rkt ├── core │ ├── bank-account.rkt │ ├── book-club.rkt │ └── box-and-client.rkt ├── file-system.rkt ├── flink-support.rkt ├── flink.rkt ├── internal-knowledge.rkt ├── lorem.txt ├── observe-star.rkt ├── ping-pong.rkt ├── provides.rkt ├── realize.rkt ├── require-struct │ ├── client.rkt │ ├── client2.rkt │ ├── driver.rkt │ └── omit-accs │ │ ├── lib.rkt │ │ └── require-omit-accs.rkt ├── require:typed │ ├── client.rkt │ ├── lib.rkt │ └── opaque │ │ ├── client-arity.rkt │ │ ├── client.rkt │ │ └── lib.rkt ├── requires.rkt ├── simple-dataflow.rkt ├── simple-dataspace.rkt ├── simple-during-spawn.rkt ├── simple-during.rkt ├── simple-query-hash.rkt ├── simple-query-set.rkt ├── simple-query-value.rkt ├── simple-stop-facet.rkt ├── struct-out │ ├── client.rkt │ ├── struct-in.rkt │ ├── struct-out.rkt │ ├── typed-out.rkt │ └── untyped.rkt ├── two-buyer-protocol.rkt └── with-facets.rkt ├── info.rkt ├── leader-and-seller.pml ├── scribblings └── typed-syndicate.scrbl ├── syndicate ├── 2d.rkt ├── compile-spin.rkt ├── core-expressions.rkt ├── core-types.rkt ├── core │ └── lang │ │ └── reader.rkt ├── drivers │ ├── tcp.rkt │ └── timestate.rkt ├── either.rkt ├── first-facet-lang-attempt.rkt ├── for-loops.rkt ├── hash.rkt ├── lang │ └── reader.rkt ├── list.rkt ├── ltl.rkt ├── maybe.rkt ├── prim.rkt ├── proto.rkt ├── replay-trail.sh ├── roles.rkt ├── roles │ └── lang │ │ └── reader.rkt ├── run-spin.sh ├── sequence.rkt ├── set.rkt ├── spin-prelude.pml ├── sugar.rkt ├── supervise.rkt ├── syntax-serializer.rkt └── test-utils.rkt └── tests ├── assert-star.rkt ├── basic-bad-assertion.rkt ├── bind-big-pattern.rkt ├── comm-ty-composition.rkt ├── constructor-naming-conventions.rkt ├── constructor-some-default-tys.rkt ├── define-dataflow.rkt ├── discard-pattern-tys.rkt ├── effect-polymorhpism.rkt ├── endpoint-effects-branch.rkt ├── expressions.rkt ├── floating-define.rkt ├── for-loop-regression.rkt ├── for-loops.rkt ├── hashes.rkt ├── implicit-root-facet.rkt ├── inference.rkt ├── lift-facet-names.rkt ├── list.rkt ├── overly-broad-interests.rkt ├── pattern-annotations.rkt ├── phantom-rho.rkt ├── primitives.rkt ├── regression-count-new-words.rkt ├── regression-define-with-effects.rkt ├── removing-annotations.rkt ├── require-struct-some-default-tys.rkt ├── require-struct.rkt ├── require-typed.rkt ├── sequences.rkt ├── sets.rkt ├── spawn-cell-bug.rkt ├── spawn-with-name.rkt ├── spawn.rkt ├── spin ├── A-and-M-not-necessary.rkt ├── basic-assertion-communication.rkt ├── basic-assertion.rkt ├── basic-deadlock-freedom.rkt ├── basic-io.rkt ├── cyclic-role-graph-regression.rkt ├── deadlock-free-syntax-bug.rkt ├── duplicate-facet-names-behavior-lost-regression.rkt ├── duplicate-facet-names-regression.rkt ├── during-spawn-stop-when.rkt ├── io-subtype-regression.rkt ├── message-subtyping-regression.rkt ├── no-behavior-regression.rkt ├── smarthome-io-bug.rkt ├── spec-message-supertype-regression.rkt ├── super-to-partial-subtype-regression.rkt ├── super-to-subtype-regression.rkt ├── uninterested-retraction.rkt ├── use-type-of-expression.rkt ├── var-assert-basic.rkt ├── verify-actors-none-error-message.rkt └── webchat-performance-regression.rkt ├── stop-when.rkt ├── struct-provider.rkt ├── this-facet.rkt ├── typed-gui-input-bug.rkt ├── untyped-lib.rkt └── var-assert.rkt /doc/demand-matcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/doc/demand-matcher.png -------------------------------------------------------------------------------- /examples/ircd/.gitignore: -------------------------------------------------------------------------------- 1 | scratch/ 2 | compiled/ 3 | -------------------------------------------------------------------------------- /examples/ircd/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | 3 | run: 4 | raco make main.rkt && racket main.rkt 5 | 6 | clean: 7 | rm -rf compiled 8 | -------------------------------------------------------------------------------- /examples/ircd/TODO.md: -------------------------------------------------------------------------------- 1 | Try changing the motd and saving the file. It'll reload. The log 2 | messages suggest that the server is dropping extant connection - as 3 | expected - but it immediately comes back momentarily before going away 4 | properly. The session is able to reboot due to the glitching in 5 | assertion of the listen port *more quickly* than the latency of 6 | teardown of the previous connection; so the new session-listener 7 | responds to the assertions from the old connection before the old 8 | connection has a chance to die. Of course, it *does* die (since commit 9 | 11de40c), but having that zombie reborn new session is annoying. 10 | 11 | - This is thorny. You'd think that having a session wait for its 12 | line-reader to go would be enough, but the multiple nested 13 | during/spawns creating the sessions mean that no matter how long 14 | the old session instance sticks around, a new session will appear 15 | before we're ready! ... maybe there's no way *at all* to 16 | disambiguate old/new instances without, say, a unique 17 | listener-socket identifier?? 18 | -------------------------------------------------------------------------------- /examples/ircd/channel.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate 2 | 3 | (require "protocol.rkt") 4 | (require "message.rkt") 5 | 6 | (require/activate syndicate/reload) 7 | 8 | (spawn #:name 'channel-factory 9 | (stop-when-reloaded) 10 | (during/spawn (ircd-channel-member $Ch _) 11 | #:name `(ircd-channel ,Ch) 12 | (field [topic #f]) 13 | (assert (ircd-channel-topic Ch (topic))) 14 | 15 | (on (message (ircd-action $who (irc-message _ "MODE" (list Ch "b") _))) 16 | (send! (ircd-event who (irc-message server-prefix 368 (list (lookup-nick who) Ch) 17 | "End of Channel Ban List")))) 18 | 19 | (on (message (ircd-action $who (irc-message _ "MODE" (list Ch) _))) 20 | (send! (ircd-event who (irc-message server-prefix 324 21 | (list (lookup-nick who) Ch "+") #f)))) 22 | 23 | (on (message (ircd-action _ (irc-message _ "TOPIC" (list Ch) $new-topic))) 24 | (topic new-topic)))) 25 | -------------------------------------------------------------------------------- /examples/ircd/config.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate 2 | 3 | (require/activate syndicate/reload) 4 | (require/activate syndicate/supervise) 5 | (require/activate syndicate/drivers/config) 6 | 7 | (require "protocol.rkt") 8 | 9 | (spawn #:name 'config 10 | (stop-when-reloaded) 11 | 12 | (assert (ircd-motd (list "Hello, world!"))) 13 | 14 | (assert (ircd-listener 6667))) 15 | -------------------------------------------------------------------------------- /examples/ircd/main.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate 2 | 3 | (require/activate syndicate/reload) 4 | 5 | (spawn-reloader "config.rkt") 6 | (spawn-reloader "session.rkt") 7 | (spawn-reloader "channel.rkt") 8 | -------------------------------------------------------------------------------- /examples/ircd/protocol.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate 2 | 3 | (provide (struct-out ircd-listener) 4 | (struct-out ircd-motd) 5 | 6 | (struct-out ircd-connection-info) 7 | (struct-out ircd-channel-member) 8 | (struct-out ircd-channel-topic) 9 | 10 | (struct-out ircd-action) 11 | (struct-out ircd-event) 12 | 13 | lookup-nick) 14 | 15 | ;; A Connection is a TcpAddress 16 | 17 | (struct ircd-listener (port) #:prefab) ;; assertion 18 | (struct ircd-motd (lines) #:prefab) ;; assertion 19 | 20 | (struct ircd-connection-info (conn nick user) #:prefab) ;;assertion 21 | (struct ircd-channel-member (channel conn) #:prefab) ;; assertion 22 | (struct ircd-channel-topic (channel topic) #:prefab) ;; assertion 23 | 24 | (struct ircd-action (conn message) #:prefab) ;; message 25 | (struct ircd-event (conn message) #:prefab) ;; message 26 | 27 | ;;--------------------------------------------------------------------------- 28 | 29 | (define (lookup-nick conn) 30 | (immediate-query [query-value #f (ircd-connection-info conn $N _) N])) 31 | -------------------------------------------------------------------------------- /examples/netstack/.gitignore: -------------------------------------------------------------------------------- 1 | compiled/ 2 | -------------------------------------------------------------------------------- /examples/netstack/TODO.md: -------------------------------------------------------------------------------- 1 | Ideas on TCP unit testing: 2 | 3 | 4 | Check behaviour around TCP zero-window probing. Is the correct 5 | behaviour already a consequence of the way `send-outbound` works? 6 | 7 | Do something smarter with TCP timers and RTT estimation than the 8 | nothing that's already being done. 9 | 10 | TCP options negotiation. 11 | - SACK 12 | - Window scaling 13 | 14 | Check that we handle the situations in figs. 9, 10, 11, pp.33- of RFC 793. 15 | 16 | Bugs: 17 | - RST kills a connection even if its sequence number is bogus. Check 18 | to make sure it's in the window. (See 19 | http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/41848.pdf 20 | and RFC 5961) 21 | 22 | Conform better to the rules for reset generation and processing 23 | from pp.36- of RFC 793. In particular, do not blindly accept RSTs 24 | without checking sequence numbers against windows etc. 25 | -------------------------------------------------------------------------------- /examples/netstack/incremental-highlevel/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | 3 | run: 4 | raco make main.rkt && racket main.rkt 5 | 6 | clean: 7 | find . -name compiled -type d | xargs rm -rf 8 | rm -f cpingresp 9 | 10 | cpingresp: cpingresp.c 11 | $(CC) -o $@ $< 12 | sudo setcap cap_net_raw+p+i+e $@ 13 | -------------------------------------------------------------------------------- /examples/netstack/incremental-highlevel/configuration.rkt: -------------------------------------------------------------------------------- 1 | #lang racket/base 2 | 3 | (provide (struct-out ethernet-interface) 4 | (struct-out host-route) 5 | (struct-out gateway-route) 6 | (struct-out net-route) 7 | 8 | (struct-out route-up)) 9 | 10 | (struct ethernet-interface (name hwaddr) #:prefab) 11 | 12 | ;; A Route is one of 13 | ;; - (host-route IpAddrBytes NetmaskNat InterfaceName), an own-IP route 14 | ;; - (gateway-route NetAddrBytes NetmaskNat IpAddrBytes InterfaceName), a gateway for a subnet 15 | ;; - (net-route NetAddrBytes NetmaskNat InterfaceName), an ethernet route for a subnet 16 | ;; NetmaskNat in a net-route is a default route. 17 | (struct host-route (ip-addr netmask interface-name) #:prefab) 18 | (struct gateway-route (network-addr netmask gateway-addr interface-name) #:prefab) 19 | (struct net-route (network-addr netmask link) #:prefab) 20 | 21 | (struct route-up (route) #:prefab) ;; assertion: the given Route is running 22 | -------------------------------------------------------------------------------- /examples/netstack/incremental-highlevel/demo-config.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate 2 | ;; Demonstration stack configuration for various hosts. 3 | 4 | (require racket/match) 5 | (require (only-in mzlib/os gethostname)) 6 | (require (only-in racket/string string-split)) 7 | (require "configuration.rkt") 8 | 9 | (spawn 10 | (match (gethostname) 11 | ["stockholm.ccs.neu.edu" 12 | (assert (host-route (bytes 129 10 115 94) 24 "eth0")) 13 | (assert (gateway-route (bytes 0 0 0 0) 0 (bytes 129 10 115 1) "eth0"))] 14 | [other ;; assume a private network 15 | (define interface 16 | (match (car (string-split other ".")) 17 | ["skip" "en0"] 18 | ["leap" "wlp4s0"] ;; wtf 19 | [_ "wlan0"])) 20 | (assert (gateway-route (bytes 0 0 0 0) 0 (bytes 192 168 1 1) interface)) 21 | (assert (host-route (bytes 192 168 1 222) 24 interface))])) 22 | -------------------------------------------------------------------------------- /examples/netstack/monolithic-lowlevel/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | 3 | run: 4 | raco make main.rkt && racket main.rkt 5 | 6 | clean: 7 | find . -name compiled -type d | xargs rm -rf 8 | -------------------------------------------------------------------------------- /examples/netstack/monolithic-lowlevel/configuration.rkt: -------------------------------------------------------------------------------- 1 | #lang racket/base 2 | 3 | (provide (struct-out ethernet-interface) 4 | (struct-out host-route) 5 | (struct-out gateway-route) 6 | (struct-out net-route) 7 | 8 | (struct-out route-up)) 9 | 10 | (struct ethernet-interface (name hwaddr) #:prefab) 11 | 12 | ;; A Route is one of 13 | ;; - (host-route IpAddrBytes NetmaskNat InterfaceName), an own-IP route 14 | ;; - (gateway-route NetAddrBytes NetmaskNat IpAddrBytes InterfaceName), a gateway for a subnet 15 | ;; - (net-route NetAddrBytes NetmaskNat InterfaceName), an ethernet route for a subnet 16 | ;; NetmaskNat in a net-route is a default route. 17 | (struct host-route (ip-addr netmask interface-name) #:prefab) 18 | (struct gateway-route (network-addr netmask gateway-addr interface-name) #:prefab) 19 | (struct net-route (network-addr netmask link) #:prefab) 20 | 21 | (struct route-up (route) #:prefab) ;; assertion: the given Route is running 22 | -------------------------------------------------------------------------------- /examples/netstack/monolithic-lowlevel/demo-config.rkt: -------------------------------------------------------------------------------- 1 | #lang racket/base 2 | ;; Demonstration stack configuration for various hosts. 3 | 4 | (require racket/match) 5 | (require syndicate/monolithic) 6 | (require (only-in mzlib/os gethostname)) 7 | (require (only-in racket/string string-split)) 8 | (require "configuration.rkt") 9 | 10 | (provide spawn-demo-config) 11 | 12 | (define (spawn-demo-config) 13 | (actor (lambda (e s) #f) 14 | (void) 15 | (match (gethostname) 16 | ["stockholm.ccs.neu.edu" 17 | (scn/union (assertion (host-route (bytes 129 10 115 94) 24 "eth0")) 18 | (assertion (gateway-route (bytes 0 0 0 0) 0 (bytes 129 10 115 1) "eth0")))] 19 | [other ;; assume a private network 20 | (define interface 21 | (match (car (string-split other ".")) 22 | ["skip" "en0"] 23 | ["leap" "wlp4s0"] ;; wtf 24 | [_ "wlan0"])) 25 | (scn/union (assertion (gateway-route (bytes 0 0 0 0) 0 (bytes 192 168 1 1) interface)) 26 | (assertion (host-route (bytes 192 168 1 222) 24 interface)))]))) 27 | -------------------------------------------------------------------------------- /examples/operational-transformation/.gitignore: -------------------------------------------------------------------------------- 1 | compiled/ 2 | -------------------------------------------------------------------------------- /examples/operational-transformation/README.md: -------------------------------------------------------------------------------- 1 | # Operational Transformation 2 | 3 | The program `syndicate-server.rkt` is a port of 4 | [`server.rkt`](https://github.com/tonyg/racket-operational-transformation/blob/master/operational-transformation-demo/server.rkt) 5 | to Syndicate. 6 | 7 | It accepts the same command-line arguments, and works with unmodified 8 | [clients](https://github.com/tonyg/racket-operational-transformation/blob/master/operational-transformation-demo/client.rkt); 9 | see the 10 | [README](https://github.com/tonyg/racket-operational-transformation/blob/master/README.md) 11 | for more information. 12 | -------------------------------------------------------------------------------- /examples/platformer/.gitignore: -------------------------------------------------------------------------------- 1 | compiled/ 2 | -------------------------------------------------------------------------------- /examples/platformer/beautiful-grassland-wallpapers-1920x1080.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/beautiful-grassland-wallpapers-1920x1080.jpg -------------------------------------------------------------------------------- /examples/platformer/info.rkt: -------------------------------------------------------------------------------- 1 | #lang setup/infotab 2 | (define deps '("syndicate" 3 | "base" 4 | "htdp-lib" 5 | )) 6 | -------------------------------------------------------------------------------- /examples/platformer/sounds/270302__littlerobotsoundfactory__collect-point-02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270302__littlerobotsoundfactory__collect-point-02.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270303__littlerobotsoundfactory__collect-point-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270303__littlerobotsoundfactory__collect-point-01.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270304__littlerobotsoundfactory__collect-point-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270304__littlerobotsoundfactory__collect-point-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270305__littlerobotsoundfactory__climb-rope-loop-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270305__littlerobotsoundfactory__climb-rope-loop-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270306__littlerobotsoundfactory__explosion-02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270306__littlerobotsoundfactory__explosion-02.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270307__littlerobotsoundfactory__explosion-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270307__littlerobotsoundfactory__explosion-01.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270308__littlerobotsoundfactory__explosion-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270308__littlerobotsoundfactory__explosion-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270309__littlerobotsoundfactory__craft-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270309__littlerobotsoundfactory__craft-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270310__littlerobotsoundfactory__explosion-04.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270310__littlerobotsoundfactory__explosion-04.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270311__littlerobotsoundfactory__explosion-03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270311__littlerobotsoundfactory__explosion-03.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270315__littlerobotsoundfactory__menu-navigate-03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270315__littlerobotsoundfactory__menu-navigate-03.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270316__littlerobotsoundfactory__open-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270316__littlerobotsoundfactory__open-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270317__littlerobotsoundfactory__jump-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270317__littlerobotsoundfactory__jump-01.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270318__littlerobotsoundfactory__jump-02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270318__littlerobotsoundfactory__jump-02.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270319__littlerobotsoundfactory__jingle-win-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270319__littlerobotsoundfactory__jingle-win-01.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270320__littlerobotsoundfactory__jump-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270320__littlerobotsoundfactory__jump-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270321__littlerobotsoundfactory__menu-navigate-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270321__littlerobotsoundfactory__menu-navigate-01.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270322__littlerobotsoundfactory__menu-navigate-02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270322__littlerobotsoundfactory__menu-navigate-02.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270323__littlerobotsoundfactory__jump-03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270323__littlerobotsoundfactory__jump-03.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270324__littlerobotsoundfactory__menu-navigate-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270324__littlerobotsoundfactory__menu-navigate-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270325__littlerobotsoundfactory__hit-02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270325__littlerobotsoundfactory__hit-02.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270326__littlerobotsoundfactory__hit-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270326__littlerobotsoundfactory__hit-01.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270327__littlerobotsoundfactory__hit-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270327__littlerobotsoundfactory__hit-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270328__littlerobotsoundfactory__hero-death-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270328__littlerobotsoundfactory__hero-death-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270329__littlerobotsoundfactory__jingle-lose-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270329__littlerobotsoundfactory__jingle-lose-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270330__littlerobotsoundfactory__jingle-achievement-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270330__littlerobotsoundfactory__jingle-achievement-01.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270331__littlerobotsoundfactory__jingle-achievement-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270331__littlerobotsoundfactory__jingle-achievement-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270332__littlerobotsoundfactory__hit-03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270332__littlerobotsoundfactory__hit-03.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270333__littlerobotsoundfactory__jingle-win-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270333__littlerobotsoundfactory__jingle-win-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270334__littlerobotsoundfactory__jingle-lose-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270334__littlerobotsoundfactory__jingle-lose-01.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270335__littlerobotsoundfactory__shoot-03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270335__littlerobotsoundfactory__shoot-03.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270336__littlerobotsoundfactory__shoot-02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270336__littlerobotsoundfactory__shoot-02.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270337__littlerobotsoundfactory__pickup-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270337__littlerobotsoundfactory__pickup-00.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270338__littlerobotsoundfactory__open-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270338__littlerobotsoundfactory__open-01.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270339__littlerobotsoundfactory__pickup-02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270339__littlerobotsoundfactory__pickup-02.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270340__littlerobotsoundfactory__pickup-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270340__littlerobotsoundfactory__pickup-01.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270341__littlerobotsoundfactory__pickup-04.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270341__littlerobotsoundfactory__pickup-04.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270342__littlerobotsoundfactory__pickup-03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270342__littlerobotsoundfactory__pickup-03.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270343__littlerobotsoundfactory__shoot-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270343__littlerobotsoundfactory__shoot-01.wav -------------------------------------------------------------------------------- /examples/platformer/sounds/270344__littlerobotsoundfactory__shoot-00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/platformer/sounds/270344__littlerobotsoundfactory__shoot-00.wav -------------------------------------------------------------------------------- /examples/webchat/htdocs/linkify-string.min.js: -------------------------------------------------------------------------------- 1 | "use strict";!function(t,r){var n=function(t){function r(t){return t.replace(/&/g,"&").replace(//g,">")}function n(t){return t.replace(/"/g,""")}function e(t){if(!t)return"";var r=[];for(var e in t){var i=t[e]+"";r.push(e+'="'+n(i)+'"')}return r.join(" ")}function i(t){var i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];i=new u(i);for(var a=o(t),f=[],l=0;l\n");else if(s.isLink&&i.check(s)){var c=i.resolve(s),p=c.formatted,g=c.formattedHref,v=c.tagName,h=c.className,k=c.target,y=c.attributes,m="<"+v+' href="'+n(g)+'"';h&&(m+=' class="'+n(h)+'"'),k&&(m+=' target="'+n(k)+'"'),y&&(m+=" "+e(y)),m+=">"+r(p)+"",f.push(m)}else f.push(r(s.toString()))}return f.join("")}var o=t.tokenize,a=t.options,u=a.Options;return String.prototype.linkify||(String.prototype.linkify=function(t){return i(this,t)}),i}(r);t.linkifyStr=n}(window,linkify); -------------------------------------------------------------------------------- /examples/webchat/htdocs/speechbubble-l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/webchat/htdocs/speechbubble-l.png -------------------------------------------------------------------------------- /examples/webchat/htdocs/speechbubble-r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/examples/webchat/htdocs/speechbubble-r.png -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/conversation-index-entry.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
{{title}}{{^title}}Untitled{{/title}}
4 | {{#members}} 5 | 6 | {{/members}} 7 |
8 |
9 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/grant-entry.html: -------------------------------------------------------------------------------- 1 |
  • {{issuer}} {{grantee}} {{permission}} {{isDelegable}} 2 |
  • 3 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/invitee-entry.html: -------------------------------------------------------------------------------- 1 |
    2 |
    3 | {{#isInvited}}{{/isInvited}} 4 | {{^isInvited}}{{/isInvited}} 5 | {{email}} 6 |
    7 |
    8 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/option-question.html: -------------------------------------------------------------------------------- 1 |
    2 |
    3 |

    {{title}}

    4 | {{&blurb}} 5 |
    6 | {{#options}} 7 | 8 | {{/options}} 9 |
    10 |
    11 |
    12 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/page-contacts.html: -------------------------------------------------------------------------------- 1 |

    Add a new contact

    2 |
    3 | 4 | 5 | 6 |
    7 | 8 |

    Contact List

    9 |
    10 |
    11 |
    12 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/page-my-requests.html: -------------------------------------------------------------------------------- 1 |

    Requests I have made

    2 |

    You have no outstanding requests waiting for responses from others.

    3 | 4 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/page-permissions.html: -------------------------------------------------------------------------------- 1 |

    Permissions I enjoy

    2 | 3 | 4 |

    Permissions I have granted to others

    5 | 6 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/page-questions.html: -------------------------------------------------------------------------------- 1 |

    Questions

    2 |
    3 |

    There are no questions waiting for you to answer.

    4 | 8 |
    9 |
    10 |
    11 |
    12 |
    13 |

    14 | 15 | 16 |

    17 | {{#showRequestsFromOthers}} 18 |
    19 |

    All requests from others

    20 |
      21 |
      22 | {{/showRequestsFromOthers}} 23 |
      24 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/permission-entry.html: -------------------------------------------------------------------------------- 1 |
    • {{issuer}} {{permission}} {{isDelegable}} 2 | {{#isRelinquishable}}{{/isRelinquishable}}
    • 3 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/permission-request-in-GENERIC.html: -------------------------------------------------------------------------------- 1 |
    • {{issuer}} {{grantee}} {{permissionJSON}} 2 | Grant 3 | Deny
    • 4 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/permission-request-in-p:follow.html: -------------------------------------------------------------------------------- 1 |
    • Request from {{grantee}} to follow {{permission.fields.0}} 2 | Grant 3 | Deny
    • 4 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/permission-request-out-GENERIC.html: -------------------------------------------------------------------------------- 1 |
    • q {{issuer}} {{permissionJSON}} Cancel
    • 2 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/permission-request-out-p:follow.html: -------------------------------------------------------------------------------- 1 |
    • Request to follow {{issuer}} Cancel
    • 2 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/post-entry.html: -------------------------------------------------------------------------------- 1 |
      2 |
      3 | {{^fromMe}}{{/fromMe}} 4 |
      5 | 6 |
      7 |
      8 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/post-item-application-octet-stream.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
      {{item.type}}
      9 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/post-item-image.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/post-item-text-plain.html: -------------------------------------------------------------------------------- 1 |

      {{item.data}}

      2 | -------------------------------------------------------------------------------- /examples/webchat/htdocs/templates/post-item.html: -------------------------------------------------------------------------------- 1 |
      2 | {{#postInfo.isDraft}}{{/postInfo.isDraft}} 3 |
      4 |
      5 | -------------------------------------------------------------------------------- /examples/webchat/server/.gitignore: -------------------------------------------------------------------------------- 1 | testing.rktd 2 | compiled/main_rkt.* 3 | -------------------------------------------------------------------------------- /examples/webchat/server/account.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate 2 | 3 | (require racket/set) 4 | 5 | (require/activate syndicate/reload) 6 | (require/activate syndicate/supervise) 7 | 8 | (require "protocol.rkt") 9 | (require "duplicate.rkt") 10 | 11 | (spawn #:name 'account-manager 12 | (stop-when-reloaded) 13 | (define/query-set accounts (account $e) e) 14 | (on (asserted (session $email _)) 15 | (when (not (set-member? (accounts) email)) 16 | (send! (create-resource (account email)))))) 17 | 18 | (spawn #:name 'account-factory 19 | (stop-when-reloaded) 20 | (on (message (create-resource ($ a (account $email)))) 21 | (spawn #:name (list 'account email) 22 | (on-start (log-info "Account ~s created." email)) 23 | (on-stop (log-info "Account ~s deleted." email)) 24 | (assert a) 25 | (assert (grant email email email (p:follow email) #t)) 26 | (stop-when-duplicate a) 27 | (stop-when (message (delete-resource a)))))) 28 | -------------------------------------------------------------------------------- /examples/webchat/server/duplicate.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate 2 | 3 | (provide stop-when-duplicate) 4 | 5 | (require syndicate/protocol/instance) 6 | (require "util.rkt") 7 | 8 | (define (stop-when-duplicate spec) 9 | (define id (random-hex-string 16)) 10 | (assert (instance id spec)) 11 | (on (asserted (instance $id2 spec)) 12 | (when (string&1 | tai64n | tai64nlocal 6 | -------------------------------------------------------------------------------- /examples/webchat/server/script-compiler.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate 2 | 3 | (require racket/file) 4 | (require racket/port) 5 | (require racket/system) 6 | 7 | (require/activate syndicate/reload) 8 | (require/activate syndicate/drivers/filesystem) 9 | (require/activate syndicate/drivers/web) 10 | 11 | (spawn #:name 'script-compiler 12 | (stop-when-reloaded) 13 | (define source-filename "../htdocs/webchat.syndicate.js") 14 | (define target-filename "webchat.js") 15 | (during/spawn (file-content source-filename file->bytes $bs) 16 | #:name (list 'compiled source-filename) 17 | (define compiled (with-output-to-bytes 18 | (lambda () (system* "../../../js/bin/syndicatec" source-filename)))) 19 | (log-info "Finished compiling ~s" target-filename) 20 | (on (web-request-get (id req) _ (,target-filename ())) 21 | (web-respond/bytes! id 22 | #:header (web-response-header 23 | #:headers (list (cons 'content-type 24 | "application/javascript"))) 25 | compiled)))) 26 | -------------------------------------------------------------------------------- /examples/webchat/server/testdata.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate 2 | 3 | (require "protocol.rkt") 4 | 5 | (send! (create-resource (account "tonyg@ccs.neu.edu"))) 6 | (send! (create-resource (account "me@here"))) 7 | (send! (create-resource (account "also@here"))) 8 | 9 | (define (follow! A B) 10 | (send! (create-resource (grant A A B (p:follow A) #f))) 11 | (send! (create-resource (grant B B A (p:follow B) #f)))) 12 | 13 | (follow! "tonyg@ccs.neu.edu" "me@here") 14 | (follow! "also@here" "me@here") 15 | (follow! "tonyg@ccs.neu.edu" "also@here") 16 | 17 | (define (make-conversation! cid title creator . other-members) 18 | (send! (create-resource (conversation cid title creator ""))) 19 | (for [(who (in-list (cons creator other-members)))] 20 | (send! (create-resource (in-conversation cid who))))) 21 | 22 | (make-conversation! "test" "Test Conversation" "tonyg@ccs.neu.edu" "me@here") 23 | (make-conversation! "grouptest" "Group Conversation" "also@here" "me@here" "tonyg@ccs.neu.edu") 24 | -------------------------------------------------------------------------------- /examples/webchat/server/util.rkt: -------------------------------------------------------------------------------- 1 | #lang racket/base 2 | 3 | (provide random-hex-string) 4 | 5 | (require (only-in file/sha1 bytes->hex-string)) 6 | (require (only-in racket/random crypto-random-bytes)) 7 | 8 | (define (random-hex-string half-length) 9 | (bytes->hex-string (crypto-random-bytes half-length))) 10 | -------------------------------------------------------------------------------- /historical/README.md: -------------------------------------------------------------------------------- 1 | # Historical implementations of Syndicate and its predecessors 2 | 3 | - `syndicate-monolithic` is an implementation of the "monolithic 4 | state change notification" dialect of Syndicate for Racket. 5 | -------------------------------------------------------------------------------- /historical/syndicate-monolithic/README.md: -------------------------------------------------------------------------------- 1 | # syndicate-monolithic 2 | 3 | This is an implementation of the monolithic semantics, without any use 4 | of patches. 5 | -------------------------------------------------------------------------------- /historical/syndicate-monolithic/examples/.gitignore: -------------------------------------------------------------------------------- 1 | private-key.pem 2 | server-cert.pem 3 | -------------------------------------------------------------------------------- /historical/syndicate-monolithic/examples/Makefile: -------------------------------------------------------------------------------- 1 | keys: private-key.pem server-cert.pem 2 | 3 | private-key.pem: 4 | openssl genrsa -des3 -passout pass:a -out $@ 1024 5 | openssl rsa -passin pass:a -in $@ -out $@ 6 | 7 | server-cert.pem: private-key.pem 8 | openssl req -new -x509 -nodes -sha1 -days 365 \ 9 | -subj /CN=example.racket-rfc6455.leastfixedpoint.com \ 10 | -passin pass:a \ 11 | -key private-key.pem > $@ 12 | 13 | clean-keys: 14 | rm -f private-key.pem server-cert.pem 15 | -------------------------------------------------------------------------------- /historical/syndicate-monolithic/examples/bank-account.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate-monolithic 2 | ;; Hello-worldish "bank account" example. 3 | 4 | (struct account (balance) #:prefab) 5 | (struct deposit (amount) #:prefab) 6 | 7 | (define (manager e balance) 8 | (match e 9 | [(message (deposit amount)) 10 | (transition (+ balance amount) 11 | (scn (assertion (account (+ balance amount)))))] 12 | [_ #f])) 13 | 14 | (define (observer e _) 15 | (when (scn? e) 16 | (for [(balance (project-assertions (scn-trie e) (account (?!))))] 17 | (printf "Balance changed to ~a\n" balance))) 18 | #f) 19 | 20 | (define (updater e _) 21 | (if (and (scn? e) (trie-non-empty? (scn-trie e))) 22 | (quit (list (message (deposit +100)) 23 | (message (deposit -30)))) 24 | #f)) 25 | 26 | (spawn manager 0 (scn/union (assertion (observe (deposit ?))) (assertion (account 0)))) 27 | (spawn observer (void) (scn (assertion (observe (account ?))))) 28 | (spawn updater (void) (scn (assertion (observe (observe (deposit ?)))))) 29 | -------------------------------------------------------------------------------- /historical/syndicate-monolithic/examples/box-and-client.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate-monolithic 2 | ;; Simple mutable box and count-to-infinity box client. 3 | 4 | (struct set-box (new-value) #:transparent) 5 | (struct box-state (value) #:transparent) 6 | 7 | (spawn (lambda (e current-value) 8 | (match e 9 | [(message (set-box new-value)) 10 | (log-info "box: taking on new-value ~v" new-value) 11 | (transition new-value (scn/union (subscription (set-box ?)) 12 | (assertion (box-state new-value))))] 13 | [_ #f])) 14 | 0 15 | (scn/union (subscription (set-box ?)) 16 | (assertion (box-state 0)))) 17 | 18 | (spawn (lambda (e s) 19 | (match e 20 | [(scn assertions) 21 | (transition s (for/list [(v (project-assertions assertions (box-state (?!))))] 22 | (log-info "client: learned that box's value is now ~v" v) 23 | (message (set-box (+ v 1)))))] 24 | [_ #f])) 25 | (void) 26 | (scn (subscription (box-state ?)))) 27 | -------------------------------------------------------------------------------- /historical/syndicate-monolithic/examples/example-layer.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate-monolithic 2 | ;; Check that nested-world assertions are properly retracted. 3 | ;; Should print two "Got SCN:" tries - one nonempty, and one empty. 4 | 5 | #;(spawn (lambda (e s) 6 | (match e 7 | [(message 'die) (quit)] 8 | [_ #f])) 9 | (void) 10 | (scn/union 11 | (subscription 'die) 12 | (subscription (observe 'die)))) 13 | 14 | (spawn-dataspace 15 | (spawn (lambda (e s) 16 | (match e 17 | [(message (at-meta 'die)) (quit)] 18 | [_ #f])) 19 | (void) 20 | (scn/union 21 | (subscription 'die #:meta-level 1) 22 | (subscription (observe 'die) #:meta-level 1)))) 23 | 24 | (spawn (lambda (e s) 25 | (match e 26 | [(scn g) 27 | (printf "Got SCN:\n") 28 | (pretty-print-trie g) 29 | (transition s (if (trie-non-empty? g) 30 | (message 'die) 31 | '()))] 32 | [_ #f])) 33 | (void) 34 | (scn (subscription (observe 'die)))) 35 | -------------------------------------------------------------------------------- /historical/syndicate-monolithic/examples/example-meta-echo2.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate-monolithic 2 | ;; The actor should receive a single event adding the (at-meta x) assertion. 3 | 4 | (require syndicate/pretty) 5 | 6 | (spawn-dataspace 7 | (spawn (lambda (e counter) 8 | (and e 9 | (let ((new-counter (+ counter 1))) 10 | (printf "Received event ~a:\n~a\n" new-counter (syndicate-pretty-print->string e)) 11 | (transition (+ counter 1) '())))) 12 | 0 13 | (list (scn/union (assertion (at-meta 'x)) 14 | (subscription 'x #:meta-level 1))))) 15 | -------------------------------------------------------------------------------- /historical/syndicate-monolithic/examples/mini-echo.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate-monolithic 2 | 3 | (struct echo-req (body) #:prefab) 4 | (struct echo-resp (body) #:prefab) 5 | 6 | (spawn (lambda (e count) 7 | (match e 8 | [(message (echo-req body)) 9 | (transition (+ count 1) 10 | (message (echo-resp body)))] 11 | [_ #f])) 12 | 0 13 | (scn (subscription (echo-req ?)))) 14 | 15 | (spawn (lambda (e s) 16 | (match e 17 | [(message (echo-resp body)) 18 | (printf "Received: ~v\n" body) 19 | #f] 20 | [_ #f])) 21 | (void) 22 | (list (scn (subscription (echo-resp ?))) 23 | (message (echo-req 0)) 24 | (message (echo-req 1)) 25 | (message (echo-req 2)))) 26 | -------------------------------------------------------------------------------- /historical/syndicate-monolithic/examples/udp-hello-plain.rkt: -------------------------------------------------------------------------------- 1 | #lang syndicate-monolithic 2 | 3 | (require "../drivers/udp.rkt") 4 | 5 | (spawn-udp-driver) 6 | 7 | (spawn (lambda (e s) 8 | (match e 9 | [(message (udp-packet src dst #"quit\n")) 10 | (log-info "Got quit request") 11 | (quit (message (udp-packet dst src #"Goodbye!\n")))] 12 | [(message (udp-packet src dst body)) 13 | (log-info "Got packet from ~v: ~v" src body) 14 | (define reply (string->bytes/utf-8 (format "You said: ~a" body))) 15 | (transition s (message (udp-packet dst src reply)))] 16 | [_ #f])) 17 | (void) 18 | (scn (subscription (udp-packet ? (udp-listener 5999) ?)))) 19 | -------------------------------------------------------------------------------- /historical/syndicate-monolithic/lang/reader.rkt: -------------------------------------------------------------------------------- 1 | #lang s-exp syntax/module-reader 2 | syndicate-monolithic/lang 3 | -------------------------------------------------------------------------------- /historical/syndicate-monolithic/main.rkt: -------------------------------------------------------------------------------- 1 | #lang racket/base 2 | 3 | (require "core.rkt") 4 | (require "ground.rkt") 5 | 6 | (provide (all-from-out "core.rkt") 7 | (all-from-out "ground.rkt")) 8 | -------------------------------------------------------------------------------- /hs/.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | -------------------------------------------------------------------------------- /hs/Setup.hs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env runhaskell 2 | import Distribution.Simple 3 | main = defaultMain 4 | -------------------------------------------------------------------------------- /hs/test/Main.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleInstances #-} 2 | module Main where 3 | 4 | import Test.Framework 5 | import Test.Framework.Providers.HUnit 6 | import Test.Framework.Providers.QuickCheck2 7 | 8 | import Syndicate.Dataspace.Trie.Tests.ESOP2016 as ESOP2016 9 | import Syndicate.Dataspace.Trie.Tests.ESOP2016v2 as ESOP2016v2 10 | import Syndicate.Dataspace.Trie.Tests.ESOP2016v3 as ESOP2016v3 11 | import Syndicate.Dataspace.Trie.Tests.Prefix as Prefix 12 | 13 | testOpts = (mempty :: TestOptions) 14 | { topt_maximum_generated_tests = Just 1000 15 | , topt_maximum_unsuitable_generated_tests = Just 10000 16 | } 17 | runnerOpts = (mempty :: RunnerOptions) { ropt_test_options = Just testOpts } 18 | runTests tests = defaultMainWithOpts tests runnerOpts 19 | 20 | main = runTests 21 | [ testGroup "ESOP2016" $ hUnitTestToTests ESOP2016.hUnitSuite 22 | , testGroup "ESOP2016v2" $ hUnitTestToTests ESOP2016v2.hUnitSuite 23 | , testGroup "ESOP2016v3" $ hUnitTestToTests ESOP2016v3.hUnitSuite 24 | , testGroup "Prefix" [ testGroup "HUnit tests" $ hUnitTestToTests Prefix.hUnitSuite 25 | , testGroup "QuickCheck tests" Prefix.quickCheckSuite 26 | ] 27 | ] 28 | -------------------------------------------------------------------------------- /js/.gitignore: -------------------------------------------------------------------------------- 1 | scratch/ 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /js/bin/syndicatec: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // -*- javascript -*- 3 | 4 | var fs = require('fs'); 5 | var compiler = require('../compiler/compiler.js'); 6 | 7 | function compileAndPrint(inputSource) { 8 | var translatedSource = compiler.compileSyndicateSource(inputSource); 9 | if (translatedSource) { 10 | console.log(translatedSource); 11 | } else { 12 | process.exit(1); 13 | } 14 | } 15 | 16 | if (process.argv.length < 3 || process.argv[2] === '-') { 17 | var inputSource = ''; 18 | process.stdin.resume(); 19 | process.stdin.setEncoding('utf8'); 20 | process.stdin.on('data', function(buf) { inputSource += buf; }); 21 | process.stdin.on('end', function() { compileAndPrint(inputSource); }); 22 | } else { 23 | var inputSource = fs.readFileSync(process.argv[2]).toString(); 24 | compileAndPrint(inputSource); 25 | } 26 | -------------------------------------------------------------------------------- /js/compiler/README.md: -------------------------------------------------------------------------------- 1 | # Syndicate/js compiler 2 | 3 | Translates ES5 + Syndicate extensions to plain ES5 using 4 | [Ohm](https://github.com/cdglabs/ohm#readme). 5 | -------------------------------------------------------------------------------- /js/compiler/demo-bankaccount.js: -------------------------------------------------------------------------------- 1 | // bin/syndicatec compiler/demo-bankaccount.js | node 2 | 3 | var Syndicate = require('./src/main.js'); 4 | 5 | assertion type account(balance); 6 | message type deposit(amount); 7 | 8 | ground dataspace { 9 | spawn { 10 | field this.balance = 0; 11 | assert account(this.balance); 12 | dataflow { 13 | console.log("Balance inside account is", this.balance); 14 | } 15 | on message deposit($amount) { 16 | this.balance += amount; 17 | } 18 | } 19 | 20 | spawn { 21 | on asserted account($balance) { 22 | console.log("Balance is now", balance); 23 | } 24 | } 25 | 26 | spawn { 27 | on start { 28 | console.log("Waiting for account."); 29 | } 30 | stop on asserted Syndicate.observe(deposit(_)) { 31 | console.log("Account became ready."); 32 | :: deposit(+100); 33 | :: deposit(-30); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /js/compiler/demo-during-criterion-snapshotting.js: -------------------------------------------------------------------------------- 1 | // Illustrates a (now fixed) bug where mutation altering a 2 | // subscription caused the `retracted` half of a during instance to be 3 | // lost. 4 | // 5 | // Symptomatic output: 6 | // x= 123 v= 999 7 | // x= 124 v= 999 8 | // 9 | // Correct output: 10 | // x= 123 v= 999 11 | // finally for x= 124 v= 999 12 | // x= 124 v= 999 13 | // 14 | // Should eventually be turned into some kind of test case. 15 | 16 | var Syndicate = require('./src/main.js'); 17 | var Dataspace = Syndicate.Dataspace; 18 | 19 | assertion type foo(x, y); 20 | 21 | ground dataspace { 22 | spawn { 23 | field this.x = 123; 24 | 25 | assert foo(this.x, 999); 26 | 27 | during foo(this.x, $v) { 28 | on start { 29 | console.log('x=', this.x, 'v=', v); 30 | if (this.x === 123) { 31 | this.x = 124; 32 | } 33 | } 34 | on stop { 35 | console.log('finally for x=', this.x, 'v=', v); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /js/dist/README.md: -------------------------------------------------------------------------------- 1 | Directory for build products, checked in to the repo for ease-of-use. 2 | -------------------------------------------------------------------------------- /js/examples/button/.gitignore: -------------------------------------------------------------------------------- 1 | *.expanded.js 2 | -------------------------------------------------------------------------------- /js/examples/button/Makefile: -------------------------------------------------------------------------------- 1 | all: index.expanded.js 2 | 3 | %.expanded.js: %.js 4 | ../../bin/syndicatec $< > $@ || (rm -f $@; false) 5 | 6 | clean: 7 | rm -f *.expanded.js 8 | -------------------------------------------------------------------------------- /js/examples/button/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Syndicate: Button Example 5 | 6 | 7 | 8 | 9 | 10 | 11 |

      Button Example

      12 | 13 |

      14 | Source code: index.js 15 |

      16 |

      17 | Expanded source code: index.expanded.js 18 |

      19 | 20 | 21 | -------------------------------------------------------------------------------- /js/examples/button/index.js: -------------------------------------------------------------------------------- 1 | ground dataspace { 2 | Syndicate.UI.spawnUIDriver(); 3 | 4 | spawn { 5 | var ui = new Syndicate.UI.Anchor(); 6 | field this.counter = 0; 7 | assert ui.html('#button-label', '' + this.counter); 8 | on message Syndicate.UI.globalEvent('#counter', 'click', _) { 9 | this.counter++; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /js/examples/dom-webworker/Makefile: -------------------------------------------------------------------------------- 1 | all: index.expanded.js worker.expanded.js 2 | 3 | %.expanded.js: %.js 4 | ../../bin/syndicatec $< > $@ || (rm -f $@; false) 5 | 6 | clean: 7 | rm -f *.expanded.js 8 | -------------------------------------------------------------------------------- /js/examples/dom-webworker/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Syndicate: DOM WebWorker Example 5 | 6 | 7 | 8 | 9 | 10 |

      DOM WebWorker example

      11 |
      12 |
      13 |
      
      14 |   
      15 | 
      16 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/dom-webworker/index.js:
      --------------------------------------------------------------------------------
       1 | document.addEventListener('DOMContentLoaded', function () {
       2 |   ground dataspace G {
       3 |     Syndicate.UI.spawnUIDriver();
       4 | 
       5 |     spawn {
       6 |       var ui = new Syndicate.UI.Anchor();
       7 |       during Syndicate.observe('bump_count') { // wait for the worker to boot and start listening
       8 |         assert ui.html('#clicker-holder',
       9 |                        '');
      10 |       }
      11 |       on message Syndicate.UI.globalEvent('#clicker-holder > button', 'click', _) {
      12 |         :: 'bump_count';
      13 |       }
      14 |     }
      15 | 
      16 |     Syndicate.Dataspace.spawn(new Syndicate.Worker('worker.expanded.js'));
      17 |   }
      18 | 
      19 |   G.dataspace.setOnStateChange(function (mux, patch) {
      20 |     document.getElementById('spy-holder').innerText = Syndicate.prettyTrie(mux.routingTable);
      21 |   });
      22 | });
      23 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/dom-webworker/worker.js:
      --------------------------------------------------------------------------------
       1 | importScripts("../../dist/syndicate.js");
       2 | 
       3 | var G = new Syndicate.WorkerGround(function () {
       4 |   spawn {
       5 |     var ui = new Syndicate.UI.Anchor();
       6 |     field this.counter = 0;
       7 | 
       8 |     assert ui.html('#counter-holder', '

      The current count is: '+this.counter+'

      ') 9 | metalevel 1; 10 | 11 | on message 'bump_count' 12 | metalevel 1 13 | { 14 | this.counter++; 15 | } 16 | } 17 | }); 18 | 19 | G.startStepping(); 20 | -------------------------------------------------------------------------------- /js/examples/dom/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Syndicate: DOM Example 5 | 6 | 7 | 8 | 9 | 10 |

      DOM example

      11 |
      12 |
      13 |
      
      14 |   
      15 | 
      16 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/iot/img/flames.gif:
      --------------------------------------------------------------------------------
      https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/js/examples/iot/img/flames.gif
      
      
      --------------------------------------------------------------------------------
      /js/examples/iot/img/remote.png:
      --------------------------------------------------------------------------------
      https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/js/examples/iot/img/remote.png
      
      
      --------------------------------------------------------------------------------
      /js/examples/iot/img/stove-coil-element-cold.jpg:
      --------------------------------------------------------------------------------
      https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/js/examples/iot/img/stove-coil-element-cold.jpg
      
      
      --------------------------------------------------------------------------------
      /js/examples/iot/img/stove-coil-element-hot.jpg:
      --------------------------------------------------------------------------------
      https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/js/examples/iot/img/stove-coil-element-hot.jpg
      
      
      --------------------------------------------------------------------------------
      /js/examples/iot/img/tvscreen.gif:
      --------------------------------------------------------------------------------
      https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/js/examples/iot/img/tvscreen.gif
      
      
      --------------------------------------------------------------------------------
      /js/examples/iot/iot-example.png:
      --------------------------------------------------------------------------------
      https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/js/examples/iot/iot-example.png
      
      
      --------------------------------------------------------------------------------
      /js/examples/iot/style.css:
      --------------------------------------------------------------------------------
       1 | template {
       2 |     display: none;
       3 | }
       4 | 
       5 | div.flamecontainer {
       6 |     position: relative;
       7 |     width: 0;
       8 |     height: 0;
       9 | }
      10 | 
      11 | img.flames {
      12 |     display: none;
      13 |     position: absolute;
      14 |     bottom: -20px;
      15 |     left: 25px;
      16 |     width: 356px;
      17 | }
      18 | 
      19 | #tv-container {
      20 |     background: url('img/tvscreen.gif');
      21 |     background-size: 100%;
      22 |     background-repeat: no-repeat;
      23 |     width: 400px;
      24 |     height: 300px;
      25 | }
      26 | 
      27 | #tv-container .alerts {
      28 |     color: white;
      29 |     margin: 3em;
      30 |     max-width: 11em;
      31 | }
      32 | 
      33 | .power-meter-display {
      34 |     font-size: 24pt;
      35 |     background-color: black;
      36 |     color: red;
      37 |     padding: 0.2em;
      38 |     margin: 0.2em;
      39 |     display: inline-block;
      40 | }
      41 | 
      42 | h2 {
      43 |     background: lightgrey;
      44 | }
      45 | 
      46 | h3 {
      47 |     border-bottom: solid grey 1px;
      48 | }
      49 | 
      50 | body > section {
      51 |     display: flex;
      52 | }
      53 | 
      54 | body > section > section {
      55 |     margin: 1em;
      56 | }
      
      
      --------------------------------------------------------------------------------
      /js/examples/location/.gitignore:
      --------------------------------------------------------------------------------
      1 | *.expanded.js
      2 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/location/Makefile:
      --------------------------------------------------------------------------------
      1 | all: index.expanded.js
      2 | 
      3 | %.expanded.js: %.js
      4 | 	../../bin/syndicatec $< > $@ || (rm -f $@; false)
      5 | 
      6 | clean:
      7 | 	rm -f *.expanded.js
      8 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/location/style.css:
      --------------------------------------------------------------------------------
       1 | template {
       2 |     display: none;
       3 | }
       4 | 
       5 | #map {
       6 |     width: 100%;
       7 |     height: 75vh;
       8 | }
       9 | 
      10 | .row {
      11 |     display: flex;
      12 | }
      13 | 
      14 | .row fieldset {
      15 |     flex: 1;
      16 |     border: none;
      17 | }
      18 | 
      19 | .row fieldset label {
      20 |     display: inline-block;
      21 | }
      22 | 
      23 | .row fieldset input {
      24 |     display: inline-block;
      25 |     width: 100%;
      26 | }
      27 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/mixin/Makefile:
      --------------------------------------------------------------------------------
      1 | all: index.expanded.js
      2 | 
      3 | %.expanded.js: %.js
      4 | 	../../bin/syndicatec $< > $@ || (rm -f $@; false)
      5 | 
      6 | clean:
      7 | 	rm -f *.expanded.js
      8 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/mixin/index.html:
      --------------------------------------------------------------------------------
       1 | 
       2 | 
       3 |   
       4 |     Syndicate: Mixin
       5 |     
       6 |     
       7 |     
       8 |     
      28 |   
      29 |   
      30 |     
      31 |

      Mixin example

      32 |

      Source code: index.js

      33 |

      Drag shapes. Click for rectangles. Shift-click to delete a rectangle.

      34 |
      35 |
      36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /js/examples/motion/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Syndicate: Motion 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /js/examples/motion/style.css: -------------------------------------------------------------------------------- 1 | template { 2 | display: none; 3 | } 4 | 5 | svg { 6 | border: solid black 1px; 7 | } -------------------------------------------------------------------------------- /js/examples/smoketest-dsl/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Syndicate: Smoketest with DSL 5 | 6 | 7 | 8 | 9 | 10 | 11 |

      Smoketest

      12 | 13 | 14 | -------------------------------------------------------------------------------- /js/examples/smoketest-dsl/index.js: -------------------------------------------------------------------------------- 1 | assertion type beep(counter); 2 | 3 | ground dataspace { 4 | console.log('starting ground boot'); 5 | 6 | spawn { 7 | stop on asserted Syndicate.observe(beep(_)) { 8 | field this.counter = 0; 9 | react { 10 | on start { 11 | :: beep(this.counter++); 12 | } 13 | on message beep(_) { 14 | :: beep(this.counter++); 15 | } 16 | stop on (this.counter > 10); 17 | } 18 | } 19 | } 20 | 21 | spawn { 22 | on message beep($counter) { 23 | console.log("beep!", counter); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /js/examples/smoketest/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Syndicate: Smoketest 5 | 6 | 7 | 8 | 9 | 10 |

      Smoketest

      11 | 12 | 13 | -------------------------------------------------------------------------------- /js/examples/smoketest/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var beep = Syndicate.Struct.makeConstructor('beep', ['counter']); 4 | 5 | var G; 6 | document.addEventListener('DOMContentLoaded', function () { 7 | var Dataspace = Syndicate.Dataspace; 8 | var sub = Syndicate.sub; 9 | var __ = Syndicate.__; 10 | var _$ = Syndicate._$; 11 | 12 | G = new Syndicate.Ground(function () { 13 | console.log('starting ground boot'); 14 | 15 | Dataspace.spawn({ 16 | counter: 0, 17 | boot: function () {}, 18 | handleEvent: function (e) {}, 19 | step: function () { 20 | Dataspace.send(beep(this.counter++)); 21 | return this.counter <= 10; 22 | } 23 | }); 24 | 25 | Dataspace.spawn({ 26 | boot: function () { return sub(beep.pattern); }, 27 | handleEvent: function (e) { 28 | if (e.type === 'message') { 29 | console.log("beep!", e.message[0]); 30 | } 31 | } 32 | }); 33 | }); 34 | G.startStepping(); 35 | }); 36 | -------------------------------------------------------------------------------- /js/examples/svg/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Syndicate: SVG 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |

      SVG example

      13 |

      After the example in this Elm post.

      14 |

      Source code: index.js

      15 |
      16 | 17 | 18 | -------------------------------------------------------------------------------- /js/examples/svg/index.js: -------------------------------------------------------------------------------- 1 | ground dataspace G { 2 | Syndicate.UI.spawnUIDriver(); 3 | Syndicate.Timer.spawnTimerDriver(); 4 | 5 | spawn { 6 | var ui = new Syndicate.UI.Anchor(); 7 | field this.angle; 8 | field this.handX; 9 | field this.handY; 10 | 11 | assert ui.html('#clock', 12 | ''+ 13 | ''+ 14 | ''+ 15 | '') 16 | when (typeof this.angle === 'number'); 17 | 18 | on message Syndicate.Timer.periodicTick(1000) { 19 | this.angle = ((((Date.now() / 1000) % 60) / 60) - 0.25) * 2 * Math.PI; 20 | this.handX = 50 + 40 * Math.cos(this.angle); 21 | this.handY = 50 + 40 * Math.sin(this.angle); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /js/examples/table/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Syndicate: Table Example 5 | 6 | 7 | 8 | 9 | 10 | 11 |

      Table Example

      12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
      IDFirst NameLast NameAddressAge
      23 |

      24 | Click on column headings to sort data rows. 25 |

      26 |

      27 | Source code: index.js 28 |

      29 | 30 | 31 | -------------------------------------------------------------------------------- /js/examples/textfield-dsl/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Syndicate: Textfield Example (DSL variation) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |

      Textfield Example (DSL variation)

      13 |

      14 | After Hesam 15 | Samimi's paper. 16 |

      17 |

      Field contents:

      18 |

      Search

      19 | 20 |
      
      21 |   
      22 | 
      23 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/textfield-dsl/style.css:
      --------------------------------------------------------------------------------
       1 | #fieldContents {
       2 |     font-family: monospace;
       3 | }
       4 | 
       5 | .cursor {
       6 |     border-left: solid red 1px;
       7 |     border-right: solid red 1px;
       8 | }
       9 | 
      10 | .highlight {
      11 |     background-color: yellow;
      12 | }
      13 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/textfield/index.html:
      --------------------------------------------------------------------------------
       1 | 
       2 | 
       3 |   
       4 |     Syndicate: Textfield Example
       5 |     
       6 |     
       7 |     
       8 |     
       9 |   
      10 |   
      11 |     

      Textfield Example

      12 |

      13 | After Hesam 14 | Samimi's paper. 15 |

      16 |

      Field contents:

      17 |

      Search

      18 | 19 |
      
      20 |   
      21 | 
      22 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/textfield/style.css:
      --------------------------------------------------------------------------------
       1 | #fieldContents {
       2 |     font-family: monospace;
       3 | }
       4 | 
       5 | .cursor {
       6 |     border-left: solid red 1px;
       7 |     border-right: solid red 1px;
       8 | }
       9 | 
      10 | .highlight {
      11 |     background-color: yellow;
      12 | }
      13 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/todo/.gitignore:
      --------------------------------------------------------------------------------
      1 | *.expanded.js
      2 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/todo/Makefile:
      --------------------------------------------------------------------------------
      1 | all: index.expanded.js
      2 | 
      3 | %.expanded.js: %.js
      4 | 	../../bin/syndicatec $< > $@ || (rm -f $@; false)
      5 | 
      6 | clean:
      7 | 	rm -f *.expanded.js
      8 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/todo/css/app.css:
      --------------------------------------------------------------------------------
      1 | template {
      2 |     display: none !important;
      3 | }
      4 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/todo/todomvc-screenshot.png:
      --------------------------------------------------------------------------------
      https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/js/examples/todo/todomvc-screenshot.png
      
      
      --------------------------------------------------------------------------------
      /js/examples/two-buyer-protocol/.gitignore:
      --------------------------------------------------------------------------------
      1 | index.expanded.js
      2 | index.md
      3 | 
      
      
      --------------------------------------------------------------------------------
      /js/examples/two-buyer-protocol/Makefile:
      --------------------------------------------------------------------------------
       1 | TARGETS=index.expanded.js index.md
       2 | 
       3 | all: $(TARGETS)
       4 | 
       5 | %.expanded.js: %.js
       6 | 	../../bin/syndicatec $< > $@ || (rm -f $@; false)
       7 | 
       8 | %.md: %.js
       9 | 	sed -E -e 's:^:    :g' -e 's:^    /// ?::g' -e 's:^    $$::g' < $< > $@
      10 | 
      11 | clean:
      12 | 	rm -f $(TARGETS)
      13 | 
      
      
      --------------------------------------------------------------------------------
      /js/src/codec.js:
      --------------------------------------------------------------------------------
       1 | "use strict";
       2 | // Wire protocol representation of events and actions
       3 | 
       4 | var Trie = require('./trie.js');
       5 | var Patch = require('./patch.js');
       6 | var Struct = require('./struct.js');
       7 | 
       8 | function _encode(e) {
       9 |   switch (e.type) {
      10 |     case "stateChange":
      11 |       return ["patch", e.patch.toJSON()];
      12 |     case "message":
      13 |       return ["message", e.message];
      14 |   }
      15 | }
      16 | 
      17 | function _decode(what) {
      18 |   return function (j) {
      19 |     switch (j[0]) {
      20 |       case "patch":
      21 |         return Syndicate.stateChange(Patch.fromJSON(j[1]));
      22 |       case "message":
      23 |         return Syndicate.message(j[1]);
      24 |       default:
      25 |         throw new Error("Invalid JSON-encoded " + what + ": " + JSON.stringify(j));
      26 |     }
      27 |   };
      28 | }
      29 | 
      30 | ///////////////////////////////////////////////////////////////////////////
      31 | 
      32 | module.exports.encodeEvent = _encode;
      33 | module.exports.decodeEvent = _decode("event");
      34 | module.exports.encodeAction = _encode;
      35 | module.exports.decodeAction = _decode("action");
      36 | 
      
      
      --------------------------------------------------------------------------------
      /js/src/mapset.js:
      --------------------------------------------------------------------------------
       1 | "use strict";
       2 | // Utilities for Maps of Sets
       3 | 
       4 | var Immutable = require('immutable');
       5 | 
       6 | function add(ms, key, val) {
       7 |   return ms.set(key, (ms.get(key) || Immutable.Set()).add(val));
       8 | }
       9 | 
      10 | function remove(ms, key, val) {
      11 |   var oldSet = ms.get(key);
      12 |   if (oldSet) {
      13 |     var newSet = oldSet.remove(val);
      14 |     if (newSet.isEmpty()) {
      15 |       ms = ms.remove(key);
      16 |     } else {
      17 |       ms = ms.set(key, newSet);
      18 |     }
      19 |   }
      20 |   return ms;
      21 | }
      22 | 
      23 | ///////////////////////////////////////////////////////////////////////////
      24 | 
      25 | module.exports.add = add;
      26 | module.exports.remove = remove;
      27 | 
      
      
      --------------------------------------------------------------------------------
      /js/src/reflect.js:
      --------------------------------------------------------------------------------
       1 | "use strict";
       2 | 
       3 | // Reflection on function formal parameter lists.
       4 | // This module is based on Angular's "injector" code,
       5 | // https://github.com/angular/angular.js/blob/master/src/auto/injector.js,
       6 | // MIT licensed, and hence:
       7 | // Copyright (c) 2010-2014 Google, Inc. http://angularjs.org
       8 | // Copyright (c) 2014 Tony Garnock-Jones
       9 | 
      10 | var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
      11 | var FN_ARG_SPLIT = /,/;
      12 | var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
      13 | 
      14 | function formalParameters(fn) {
      15 |     var result = [];
      16 | 
      17 |     var fnText = fn.toString().replace(STRIP_COMMENTS, '');
      18 |     var argDecl = fnText.match(FN_ARGS);
      19 |     var args = argDecl[1].split(FN_ARG_SPLIT);
      20 |     for (var i = 0; i < args.length; i++) {
      21 | 	var trimmed = args[i].trim();
      22 | 	if (trimmed) { result.push(trimmed); }
      23 |     }
      24 | 
      25 |     return result;
      26 | }
      27 | 
      28 | module.exports.formalParameters = formalParameters;
      29 | 
      
      
      --------------------------------------------------------------------------------
      /js/src/seal.js:
      --------------------------------------------------------------------------------
       1 | var Immutable = require('immutable');
       2 | 
       3 | function Seal(contents) {
       4 |   this.sealContents = contents;
       5 |   Object.freeze(this);
       6 | }
       7 | 
       8 | Seal.prototype.equals = function (other) {
       9 |   if (!(other instanceof Seal)) return false;
      10 |   return Immutable.is(this.sealContents, other.sealContents);
      11 | };
      12 | 
      13 | function seal(contents) {
      14 |   return new Seal(contents);
      15 | }
      16 | 
      17 | module.exports.Seal = Seal;
      18 | module.exports.seal = seal;
      19 | 
      
      
      --------------------------------------------------------------------------------
      /js/src/special.js:
      --------------------------------------------------------------------------------
      1 | "use strict";
      2 | // $Special: Builder of singleton "atoms".
      3 | 
      4 | function $Special(name) {
      5 |   this.name = name;
      6 | }
      7 | 
      8 | module.exports = $Special;
      9 | 
      
      
      --------------------------------------------------------------------------------
      /js/src/util.js:
      --------------------------------------------------------------------------------
       1 | "use strict";
       2 | 
       3 | var Reflect = require("./reflect.js");
       4 | 
       5 | module.exports.extend = function (what, _with) {
       6 |   for (var prop in _with) {
       7 |     if (_with.hasOwnProperty(prop)) {
       8 |       what[prop] = _with[prop];
       9 |     }
      10 |   }
      11 |   return what;
      12 | };
      13 | 
      14 | module.exports.kwApply = function (f, thisArg, args) {
      15 |   var formals = Reflect.formalParameters(f);
      16 |   var actuals = []
      17 |   for (var i = 0; i < formals.length; i++) {
      18 |     var formal = formals[i];
      19 |     if (!(formal in args)) {
      20 |       throw new Error("Function parameter '"+formal+"' not present in args");
      21 |     }
      22 |     actuals.push(args[formal]);
      23 |   }
      24 |   return f.apply(thisArg, actuals);
      25 | };
      26 | 
      
      
      --------------------------------------------------------------------------------
      /racket/.gitignore:
      --------------------------------------------------------------------------------
      1 | compiled/
      2 | scratch/
      3 | 
      
      
      --------------------------------------------------------------------------------
      /racket/Makefile:
      --------------------------------------------------------------------------------
       1 | PACKAGENAME=syndicate
       2 | COLLECTS=syndicate syndicate-gl syndicate-ide
       3 | 
       4 | all: setup
       5 | 
       6 | clean:
       7 | 	find . -name compiled -type d | xargs rm -rf
       8 | 
       9 | setup:
      10 | 	raco setup $(COLLECTS)
      11 | 
      12 | link:
      13 | 	raco pkg install --link -n $(PACKAGENAME) $$(pwd)
      14 | 
      15 | unlink:
      16 | 	raco pkg remove $(PACKAGENAME)
      17 | 
      
      
      --------------------------------------------------------------------------------
      /racket/doc/forward-chaining-hll3.rkt.txt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/hll ;; -*- racket -*-
       2 | 
       3 | (actor (forever (assert `(parent john douglas))))
       4 | (actor (forever (assert `(parent bob john))))
       5 | (actor (forever (assert `(parent ebbon bob))))
       6 | 
       7 | (actor (forever (on (asserted `(parent ,$A ,$C))
       8 |                     (actor (until (retracted `(parent ,A ,C))
       9 |                                   (assert `(ancestor ,A ,C)))))))
      10 | 
      11 | (actor (forever (on (asserted `(parent ,$A ,$C))
      12 |                     (actor (until (retracted `(parent ,A ,C))
      13 |                              (on (asserted `(ancestor ,C ,$B))
      14 |                                  (actor (until (or (retracted `(parent ,A ,C))
      15 |                                                    (retracted `(ancestor ,C ,B)))
      16 |                                           (assert `(ancestor ,A ,B))))))))))
      17 | 
      
      
      --------------------------------------------------------------------------------
      /racket/doc/forward-chaining-hll4.rkt.txt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/hll ;; -*- racket -*-
       2 | 
       3 | (actor (forever (assert `(parent john douglas))))
       4 | (actor (forever (assert `(parent bob john))))
       5 | (actor (forever (assert `(parent ebbon bob))))
       6 | 
       7 | (actor (forever (on (asserted `(parent ,$A ,$C))
       8 |                     (until (retracted `(parent ,A ,C))
       9 |                       (assert `(ancestor ,A ,C))
      10 |                       (on (asserted `(ancestor ,C ,$B))
      11 |                           (until (retracted `(ancestor ,C ,B))
      12 |                             (assert `(ancestor ,A ,B))))))))
      13 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate-gl/TODO.md:
      --------------------------------------------------------------------------------
      1 |  - Some way of adjusting target frame rate based on whether we're
      2 |    achieving the goal or not; e.g. fall back from 60Hz to 24Hz
      3 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate-gl/info.rkt:
      --------------------------------------------------------------------------------
      1 | #lang setup/infotab
      2 | (define scribblings '(("scribblings/syndicate-gl.scrbl" ())))
      3 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate-gui-toolbox/examples/7-GUIS/task-1.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (require "../../widgets.rkt")
       4 | (require (only-in racket/format ~a))
       5 | 
       6 | ;; a mouse-click counter
       7 | 
       8 | (define frame (spawn-frame #:label "Counter"))
       9 | (define pane  (spawn-horizontal-pane #:parent frame))
      10 | (define view  (spawn-text-field #:parent pane #:label "" #:init-value "0" #:enabled #f #:min-width 100))
      11 | (define _but  (spawn-button #:parent pane #:label "Count"))
      12 | 
      13 | (spawn
      14 |  (field [counter 0])
      15 |  (on (message (button-press _but))
      16 |      (counter (add1 (counter)))
      17 |      (send! (set-text-field view (~a (counter)))))
      18 |  (on-start
      19 |   (send! (show frame #t))))
      20 | 
      21 | (module+ main
      22 |   (void))
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate-gui-toolbox/info.rkt:
      --------------------------------------------------------------------------------
      1 | #lang setup/infotab
      2 | 
      3 | (define compile-omit-paths
      4 |   '("examples"))
      5 | 
      6 | (define test-omit-paths
      7 |   '(;; depends on Matthias's 7GUI project which is not on the package server
      8 |     "examples"))
      9 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate-ide/hsv.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | 
       3 | (provide fmod
       4 |          hsv->color
       5 |          color-by-hash)
       6 | 
       7 | (require 2htdp/image)
       8 | 
       9 | (define (fmod a b)
      10 |   (- a (* b (truncate (/ a b)))))
      11 | 
      12 | (define (hsv->color h s v)
      13 |   (define h* (fmod (/ h 60.0) 6))
      14 |   (define chroma (* v s))
      15 |   (define x (* chroma (- 1 (abs (- (fmod h* 2) 1)))))
      16 |   (define-values (r g b)
      17 |     (cond
      18 |      [(< h* 1) (values chroma x 0)]
      19 |      [(< h* 2) (values x chroma 0)]
      20 |      [(< h* 3) (values 0 chroma x)]
      21 |      [(< h* 4) (values 0 x chroma)]
      22 |      [(< h* 5) (values x 0 chroma)]
      23 |      [else     (values chroma 0 x)]))
      24 |   (define m (- v chroma))
      25 |   (define (scale x) (inexact->exact (truncate (* 255 (+ x m)))))
      26 |   (make-color (scale r) (scale g) (scale b)))
      27 | 
      28 | (define (color-by-hash v)
      29 |   (hsv->color (* 360.0 (/ (bitwise-and (equal-hash-code v) 16777215) 16777216.0)) 1 1))
      30 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate-ide/info.rkt:
      --------------------------------------------------------------------------------
      1 | #lang setup/infotab
      2 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/actor-lang.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | 
       3 | (require (except-in "core-lang.rkt"
       4 |                     dataspace
       5 |                     assert
       6 |                     ))
       7 | (require "actor.rkt")
       8 | (require "hierarchy.rkt")
       9 | (provide (except-out (all-from-out "core-lang.rkt") actor)
      10 |          (all-from-out "actor.rkt")
      11 |          (all-from-out "hierarchy.rkt"))
      12 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/big-bang/timestate.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Big-bang specific timestate implementation with compatible protocol.
       3 | 
       4 | (provide (struct-out later-than)
       5 |          stop-when-timeout
       6 |          sleep)
       7 | 
       8 | (require syndicate/big-bang)
       9 | (require (only-in syndicate/drivers/timestate
      10 |                   later-than later-than? struct:later-than later-than-msecs))
      11 | 
      12 | (define-syntax-rule (stop-when-timeout relative-msecs body ...)
      13 |   (let ((deadline (+ (current-inexact-milliseconds) relative-msecs)))
      14 |     (stop-when (asserted (later-than deadline)) body ...)))
      15 | 
      16 | (define (sleep sec)
      17 |   (let ((deadline (+ (current-inexact-milliseconds) (* sec 1000.0))))
      18 |     (until (asserted (later-than deadline)))))
      19 | 
      20 | (spawn #:name 'big-bang-timestate-driver
      21 |        (during (observe (later-than $deadline))
      22 |          (field [ready? #f])
      23 |          (assert #:when (ready?) (later-than deadline))
      24 |          (on (message (inbound (tick-event)))
      25 |              (ready? (>= (current-inexact-milliseconds) deadline)))))
      26 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/drivers/line-reader.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (provide (struct-out tcp-channel-line))
       4 | 
       5 | (require "tcp.rkt")
       6 | (require "../support/bytes.rkt")
       7 | 
       8 | (struct tcp-channel-line (source destination bytes) #:prefab)
       9 | 
      10 | (spawn #:name 'line-reader-factory
      11 |        (during/spawn (observe (tcp-channel-line $src $dst _))
      12 |          #:name `(line-reader ,src ,dst)
      13 |          (field [buffer #""])
      14 |          (on (message (tcp-channel src dst $bs))
      15 |              (buffer (bytes-append (buffer) bs)))
      16 |          (begin/dataflow
      17 |            (define newline-pos (bytes-index (buffer) (char->integer #\newline)))
      18 |            (when newline-pos
      19 |              (define line (subbytes (buffer) 0 newline-pos))
      20 |              (buffer (subbytes (buffer) (+ newline-pos 1)))
      21 |              (send! (tcp-channel-line src dst line))))))
      22 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/drivers/timestate.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (provide (struct-out later-than)
       4 |          on-timeout
       5 |          stop-when-timeout
       6 |          sleep)
       7 | 
       8 | (require/activate syndicate/drivers/timer)
       9 | 
      10 | (struct later-than (msecs) #:prefab)
      11 | 
      12 | (spawn #:name 'drivers/timestate
      13 |        (during (observe (later-than $msecs))
      14 |          (define timer-id (gensym 'timestate))
      15 |          (on-start (send! (set-timer timer-id msecs 'absolute)))
      16 |          (on (message (timer-expired timer-id _))
      17 |              (react (assert (later-than msecs))))))
      18 | 
      19 | (define-syntax-rule (on-timeout relative-msecs body ...)
      20 |   (let ((timer-id (gensym 'timeout)))
      21 |     (on-start (send! (set-timer timer-id relative-msecs 'relative)))
      22 |     (on (message (timer-expired timer-id _)) body ...)))
      23 | 
      24 | (define-syntax-rule (stop-when-timeout relative-msecs body ...)
      25 |   (on-timeout relative-msecs (stop-current-facet body ...)))
      26 | 
      27 | (define (sleep sec)
      28 |   (define timer-id (gensym 'sleep))
      29 |   (until (message (timer-expired timer-id _))
      30 |     (on-start (send! (set-timer timer-id (* sec 1000.0) 'relative)))))
      31 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/.gitignore:
      --------------------------------------------------------------------------------
      1 | private-key.pem
      2 | server-cert.pem
      3 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/Makefile:
      --------------------------------------------------------------------------------
       1 | keys: private-key.pem server-cert.pem
       2 | 
       3 | private-key.pem:
       4 | 	openssl genrsa -des3 -passout pass:a -out $@ 1024
       5 | 	openssl rsa -passin pass:a -in $@ -out $@
       6 | 
       7 | server-cert.pem: private-key.pem
       8 | 	openssl req -new -x509 -nodes -sha1 -days 365 \
       9 | 		-subj /CN=example.racket-rfc6455.leastfixedpoint.com \
      10 | 		-passin pass:a \
      11 | 		-key private-key.pem > $@
      12 | 
      13 | clean-keys:
      14 | 	rm -f private-key.pem server-cert.pem
      15 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/add1-simple.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Trivial example program to demonstrate tracing
       3 | 
       4 | (assertion-struct one-plus (n m))
       5 | 
       6 | (spawn #:name 'add1-server
       7 |        (during/spawn (observe (one-plus $n _))
       8 |          #:name (list 'solving 'one-plus n)
       9 |          (assert (one-plus n (+ n 1)))))
      10 | 
      11 | (spawn #:name 'client-process
      12 |        (stop-when (asserted (one-plus 3 $value))
      13 |          (printf "1 + 3 = ~a\n" value)))
      14 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/bank-account.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Hello-worldish "bank account" example.
       3 | 
       4 | (struct account (balance) #:prefab)
       5 | (struct deposit (amount) #:prefab)
       6 | 
       7 | (spawn (field [balance 0])
       8 |        (assert (account (balance)))
       9 |        (on (message (deposit $amount))
      10 |            (balance (+ (balance) amount))))
      11 | 
      12 | (spawn (on (asserted (account $balance))
      13 |            (printf "Balance changed to ~a\n" balance)))
      14 | 
      15 | (spawn* (until (asserted (observe (deposit _))))
      16 |         (send! (deposit +100))
      17 |         (send! (deposit -30)))
      18 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/box-and-client.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Simple mutable box and count-to-infinity box client.
       3 | 
       4 | (message-struct set-box (new-value))
       5 | (assertion-struct box-state (value))
       6 | 
       7 | (spawn (field [current-value 0])
       8 |        (assert (box-state (current-value)))
       9 |        (stop-when-true (= (current-value) 10)
      10 |                        (log-info "box: terminating"))
      11 |        (on (message (set-box $new-value))
      12 |            (log-info "box: taking on new-value ~v" new-value)
      13 |            (current-value new-value)))
      14 | 
      15 | (spawn (stop-when (retracted (observe (set-box _)))
      16 |                   (log-info "client: box has gone"))
      17 |        (on (asserted (box-state $v))
      18 |            (log-info "client: learned that box's value is now ~v" v)
      19 |            (send! (set-box (+ v 1)))))
      20 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/broadcast-messages.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Demonstrate sending a message to multiple receivers.
       3 | 
       4 | (struct envelope (destination message) #:prefab)
       5 | 
       6 | (spawn (on (message (envelope 'alice $message))
       7 |            (log-info "Alice received ~v" message)))
       8 | 
       9 | (spawn (on (message (envelope 'bob $message))
      10 |            (log-info "Bob received ~v" message)))
      11 | 
      12 | (spawn*
      13 |  (log-info "Waiting for Alice and Bob.")
      14 |  (until (asserted (observe (envelope 'alice _))))
      15 |  (until (asserted (observe (envelope 'bob _))))
      16 | 
      17 |  (log-info "Sending a few messages...")
      18 |  (send! (envelope 'alice "For Alice's eyes only"))
      19 |  (send! (envelope 'bob "Dear Bob, how are you? Kind regards, etc."))
      20 |  (send! (envelope ? "Important announcement!"))
      21 | 
      22 |  (log-info "Sent all the messages."))
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/ceu-leds.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; After [1], figure 1.
       3 | ;;
       4 | ;; [1] F. Sant’Anna, N. Rodriguez, R. Ierusalimschy, O. Landsiedel,
       5 | ;; and P. Tsigas, “Safe system-level concurrency on
       6 | ;; resource-constrained nodes,” Proc. 11th ACM Conf. Embed. Networked
       7 | ;; Sens. Syst. - SenSys ’13, vol. 13, pp. 1–14, 2013.
       8 | 
       9 | (require/activate syndicate/drivers/timestate)
      10 | 
      11 | (define (led-on) (printf "LED ON\n"))
      12 | (define (led-off) (printf "led off\n"))
      13 | 
      14 | ;;---------------------------------------------------------------------------
      15 | 
      16 | (spawn (on-stop (led-off))
      17 |        (on-start (let loop ()
      18 |                    (led-on)
      19 |                    (sleep 2)
      20 |                    (led-off)
      21 |                    (sleep 1)
      22 |                    (loop)))
      23 |        (stop-when-timeout 10000)) ;; in the paper, it's 1 minute = 60000 milliseconds
      24 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/chain.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (require/activate syndicate/drivers/timestate)
       4 | 
       5 | (define (chain-step n)
       6 |   (printf "chain-step ~v\n" n)
       7 |   (spawn* (sleep 1)
       8 |           (if (< n 5)
       9 |               (chain-step (+ n 1))
      10 |               (printf "done.\n"))))
      11 | 
      12 | (chain-step 0)
      13 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/chat-client-tcp2.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (require/activate syndicate/drivers/tcp2)
       4 | (require (only-in racket/port read-bytes-line-evt))
       5 | 
       6 | (spawn (define id 'chat)
       7 |        (assert (tcp-connection id (tcp-address "localhost" 5999)))
       8 |        (stop-when (retracted (tcp-accepted id)))
       9 |        (on (message (tcp-in id $bs))
      10 |            (write-bytes bs)
      11 |            (flush-output))
      12 | 
      13 |        (define stdin-evt (read-bytes-line-evt (current-input-port) 'any))
      14 |        (stop-when (message (inbound (external-event stdin-evt (list (? eof-object? _))))))
      15 |        (on (message (inbound (external-event stdin-evt (list (? bytes? $line)))))
      16 |            (send! (tcp-out id line))
      17 |            ;; chat-tcp2 uses the line-reader, so need line separators.
      18 |            (send! (tcp-out id #"\n"))))
      19 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/chat-client.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (require syndicate/protocol/advertise)
       4 | (require/activate syndicate/drivers/tcp)
       5 | (require (only-in racket/port read-bytes-line-evt))
       6 | 
       7 | (define local-handle (tcp-handle 'chat))
       8 | (define remote-handle (tcp-address "localhost" 5999))
       9 | (define stdin-evt (read-bytes-line-evt (current-input-port) 'any))
      10 | 
      11 | (spawn (stop-when (message (inbound (external-event stdin-evt (list (? eof-object? _))))))
      12 |        (stop-when (retracted (advertise (tcp-channel remote-handle local-handle _))))
      13 |        (assert (advertise (tcp-channel local-handle remote-handle _)))
      14 | 
      15 |        (on (message (inbound (external-event stdin-evt (list (? bytes? $line)))))
      16 |            (send! (tcp-channel local-handle remote-handle line)))
      17 | 
      18 |        (on (message (tcp-channel remote-handle local-handle $bs))
      19 |            (write-bytes bs)
      20 |            (flush-output)))
      21 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/chat-tcp2.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; A version of chat-simplified-internals2.rkt that has the simplified TCP
       3 | ;; driver split out into syndicate/drivers/tcp2.
       4 | 
       5 | (require/activate syndicate/drivers/tcp2)
       6 | (require racket/format)
       7 | 
       8 | (message-struct speak (who what))
       9 | (assertion-struct present (who))
      10 | 
      11 | (spawn #:name 'chat-server
      12 |  (during/spawn (tcp-connection $id (tcp-listener 5999))
      13 |    (assert (tcp-accepted id))
      14 |    (let ((me (gensym 'user)))
      15 |      (assert (present me))
      16 |      (on (message (tcp-in-line id $bs))
      17 |          (send! (speak me (bytes->string/utf-8 bs)))))
      18 |    (during (present $user)
      19 |      (on-start (send! (tcp-out id (string->bytes/utf-8 (~a user " arrived\n")))))
      20 |      (on-stop  (send! (tcp-out id (string->bytes/utf-8 (~a user " left\n")))))
      21 |      (on (message (speak user $text))
      22 |          (send! (tcp-out id (string->bytes/utf-8 (~a user " says '" text "'\n"))))))))
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/cleanup.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (require/activate syndicate/drivers/timestate)
       4 | 
       5 | (define (foo)
       6 |   (printf "Sleeping foo\n")
       7 |   (sleep 2)
       8 |   (printf "Done foo\n"))
       9 | 
      10 | (define (bar)
      11 |   (printf "Sleeping bar\n")
      12 |   (sleep 1)
      13 |   (printf "Done bar\n"))
      14 | 
      15 | (define (cleanup-after . script-thunks)
      16 |   (react (on-stop (printf "Cleaning up\n"))
      17 |          (for [(script-thunk script-thunks)]
      18 |            (on-start (script-thunk)))))
      19 | 
      20 | (spawn (on-start (printf "Starting process\n"))
      21 |        (on-stop (printf "Stopping process\n"))
      22 |        (on-start (cleanup-after foo bar)))
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/echo.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (require syndicate/protocol/advertise)
       4 | (require/activate syndicate/drivers/tcp)
       5 | 
       6 | (define server-id (tcp-listener 5999))
       7 | (spawn (assert (advertise (observe (tcp-channel _ server-id _))))
       8 |        (during/spawn (advertise (tcp-channel $c server-id _))
       9 |                      (on-start (printf "Accepted connection from ~v\n" c))
      10 |                      (assert (advertise (tcp-channel server-id c _)))
      11 |                      (on (message (tcp-channel c server-id $bs))
      12 |                          (send! (tcp-channel server-id c bs)))
      13 |                      (on-stop (printf "Closed connection ~v\n" c))))
      14 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/example-bug-query-scope.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Demonstrates a (fixed) bug in define/query-value scoping.
       3 | ;;
       4 | ;; Buggy output:
       5 | ;;
       6 | ;; w is #f
       7 | ;; Process #f (0) died with exception:
       8 | ;; application: not a procedure;
       9 | ;;  expected a procedure that can be applied to arguments
      10 | ;;   given: '(val 123)
      11 | ;;   arguments...:
      12 | ;;    '(val 123)
      13 | ;;   context...:
      14 | ;;
      15 | ;; Expected output:
      16 | ;;
      17 | ;; w is #f
      18 | ;; w is '(val 123)
      19 | ;;
      20 | ;; Diagnosis:
      21 | ;;
      22 | ;; The field being defined, w, was being shadowed by the w binding in
      23 | ;; the query pattern. Adding `(let ((F field-name)) ...)` in the
      24 | ;; query-value* macro (and friends) avoids the issue.
      25 | 
      26 | (spawn (define/query-value w #f ($ w (list 'val _)) w)
      27 |        (begin/dataflow
      28 |          (log-info "w is ~v" (w))))
      29 | 
      30 | (spawn (assert (list 'val 123)))
      31 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/example-bug-rising-edge-true.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Demonstrates a bug: rising-edge of a predicate that starts off true
       3 | ;; yields a crash.
       4 | ;;
       5 | ;; Fixed by commit 1fdd62d: Now both processes print their message and
       6 | ;; terminate normally, as expected.
       7 | 
       8 | (spawn (field [f #t])
       9 |        (stop-when (rising-edge (f))
      10 |                   (printf "Stopping (via field).\n")))
      11 | 
      12 | (spawn (stop-when (rising-edge #t)
      13 |                   (printf "Stopping (direct).\n")))
      14 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/example-demand-matcher-glitch-bug.buggy.png:
      --------------------------------------------------------------------------------
      https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/racket/syndicate/examples/actor/example-demand-matcher-glitch-bug.buggy.png
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/example-demand-matcher-glitch-bug.fixed1.png:
      --------------------------------------------------------------------------------
      https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/racket/syndicate/examples/actor/example-demand-matcher-glitch-bug.fixed1.png
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/example-demand-matcher-glitch-bug.fixed2.png:
      --------------------------------------------------------------------------------
      https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/racket/syndicate/examples/actor/example-demand-matcher-glitch-bug.fixed2.png
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/example-demand-matcher-glitch-bug2.buggy.png:
      --------------------------------------------------------------------------------
      https://raw.githubusercontent.com/tonyg/syndicate/785dd79644dfc6f7941078dbb8c7f2aa76e07831/racket/syndicate/examples/actor/example-demand-matcher-glitch-bug2.buggy.png
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/example-demand-matcher-glitch-bug2.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/actor
       2 | ;; Example showing the consequences of not honouring the requirement
       3 | ;; of the current LLL demand-matcher that supply tasks must *reliably*
       4 | ;; terminate when their demand is not present. In this case, demand
       5 | ;; changes too quickly: it exists for long enough to start the task,
       6 | ;; but is withdrawn before the task itself has a chance to detect it.
       7 | ;; Because the task (as currently implemented) does not use the "learn
       8 | ;; negative knowledge" pattern to detect the *absence* of some
       9 | ;; assertion, it does not terminate as it is supposed to.
      10 | ;;
      11 | ;; Demonstrates that the fix in commit 2a0197b isn't in general
      12 | ;; sufficient.
      13 | 
      14 | (require syndicate/protocol/advertise)
      15 | (require/activate syndicate/drivers/tcp)
      16 | 
      17 | (define X (advertise (observe (tcp-channel ? (tcp-listener 6000) ?))))
      18 | 
      19 | (spawn* #:name 'strobe
      20 |         (assert! X)
      21 |         (printf "Asserted ~v\n" X)
      22 |         ;; (begin (send! 'dummy)
      23 |         ;;        (retract! X)
      24 |         ;;        (printf "Retracted ~v\n" X))
      25 |         (printf "Terminating.\n"))
      26 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/example-during-criterion-snapshotting.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Illustrates a (now fixed) bug where mutation altering a
       3 | ;; subscription caused the `retracted` half of a during instance to be
       4 | ;; lost.
       5 | ;;
       6 | ;; Symptomatic output:
       7 | ;; x=123 v=999
       8 | ;; x=124 v=999
       9 | ;;
      10 | ;; Correct output:
      11 | ;; x=123 v=999
      12 | ;; x=124 v=999
      13 | ;; finally for x0=123 x=124 v=999
      14 | ;;
      15 | ;; Should eventually be turned into some kind of test case.
      16 | 
      17 | (struct foo (x y) #:prefab)
      18 | 
      19 | (spawn (field [x 123])
      20 |        (assert (foo (x) 999))
      21 |        (during (foo (x) $v)
      22 |                (define x0 (x))
      23 |                (log-info "x=~a v=~a" (x) v)
      24 |                (when (= (x) 123) (x 124))
      25 |                (on-stop
      26 |                 (log-info "finally for x0=~a x=~a v=~a" x0 (x) v))))
      27 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/example-multiple-suspension-resumption.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Shows that the checks enforcing single-use suspension-resumption are working.
       3 | 
       4 | (spawn #:name 'shouldnt-work
       5 |        (field [k #f])
       6 |        (on-start
       7 |         (flush!)
       8 |         (log-info "Result from suspension: ~v"
       9 |                   (react/suspend (actual-k)
      10 |                                  (on-start (k actual-k)
      11 |                                            ((k) 'first-result))))
      12 |         (flush!)
      13 |         ((k) 'second-result)))
      14 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/example-supervise.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Shows the difference between a supervised exit and a supervised crash.
       3 | 
       4 | (require/activate syndicate/supervise)
       5 | (require/activate syndicate/drivers/timestate)
       6 | 
       7 | (supervise
       8 |  #:name 'ward-supervisor
       9 |  (spawn #:name 'ward
      10 |         (on-start (log-info "Starting ward"))
      11 |         (on-stop (log-info "Stopping ward"))
      12 |         (on (message 'crash)
      13 |             (log-info "Crashing")
      14 |             (error 'ward "Eep!"))
      15 |         (stop-when (message 'quit)
      16 |                    (log-info "Bye!"))))
      17 | 
      18 | (define (monitor-interest-in thing)
      19 |   (spawn #:name (list 'monitor-interest-in thing)
      20 |          (during (observe thing)
      21 |            (on-start (log-info "Interest in ~v appeared" thing))
      22 |            (on-stop (log-info "Interest in ~v disappeared" thing)))))
      23 | 
      24 | (monitor-interest-in 'crash)
      25 | (monitor-interest-in 'quit)
      26 | 
      27 | (spawn* #:name 'main
      28 |         (sleep 1)
      29 |         (send! 'crash)
      30 |         (sleep 1)
      31 |         (send! 'quit)
      32 |         (sleep 1))
      33 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/example-synthetic-patch-2.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Illustrates a (fixed) bug where an endpoint whose interest moves
       3 | ;; with time, where that interest eventually overlaps with existing
       4 | ;; interest, fails to be notified of an otherwise-known assertion.
       5 | ;;
       6 | ;; Symptomatic output:
       7 | ;;
       8 | ;; Outer value 4 = 4
       9 | ;; Value 0 = 0
      10 | ;; Value 1 = 1
      11 | ;; Value 2 = 2
      12 | ;; Value 3 = 3
      13 | ;;
      14 | ;; Correct output:
      15 | ;;
      16 | ;; Outer value 4 = 4
      17 | ;; Value 0 = 0
      18 | ;; Value 1 = 1
      19 | ;; Value 2 = 2
      20 | ;; Value 3 = 3
      21 | ;; Value 4 = 4
      22 | ;; Value 5 = 5
      23 | 
      24 | (spawn (field [of-interest 0])
      25 | 
      26 |        (during 'ready
      27 |          (on (asserted (list (of-interest) $v))
      28 |              (printf "Value ~a = ~a\n" (of-interest) v)
      29 |              (of-interest (+ (of-interest) 1))))
      30 | 
      31 |        (on (asserted (list 4 $v))
      32 |            (printf "Outer value ~a = ~a\n" 4 v)))
      33 | 
      34 | (spawn (assert (list 0 0))
      35 |        (assert (list 1 1))
      36 |        (assert (list 2 2))
      37 |        (assert (list 3 3))
      38 |        (assert (list 4 4))
      39 |        (assert (list 5 5))
      40 |        (on-start (flush!)
      41 |                  (assert! 'ready)))
      42 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/example-synthetic-patch.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Illustrates a (now fixed) bug where creating a facet interested in something
       3 | ;; already known didn't properly trigger the assertion-handler.
       4 | ;;
       5 | ;; Symptomatic output:
       6 | ;;
       7 | ;; +outer "first"
       8 | ;; +show
       9 | ;; -show
      10 | ;; -outer "first"
      11 | ;; +outer "second"
      12 | ;;
      13 | ;; Correct output:
      14 | ;;
      15 | ;; +outer "first"
      16 | ;; +show
      17 | ;; +outer "second"
      18 | ;; -show
      19 | ;; -outer "first"
      20 | ;; +show
      21 | ;;
      22 | ;; Should eventually be turned into some kind of test case.
      23 | 
      24 | (struct outer (v) #:prefab)
      25 | (struct show () #:prefab)
      26 | 
      27 | (spawn (field [v "first"])
      28 |        (assert (outer (v)))
      29 |        (assert (show))
      30 |        (on (message 2)
      31 |            (v "second")))
      32 | 
      33 | (spawn (on-start (send! 1))
      34 |        (during (outer $v)
      35 |                (on-start (log-info "+outer ~v" v))
      36 |                (on-stop (log-info "-outer ~v" v))
      37 |                (during (show)
      38 |                        (on-start (log-info "+show"))
      39 |                        (on-stop (log-info "-show"))))
      40 |        (on (message 1)
      41 |            (send! 2)))
      42 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/f-to-c2.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; After the Fahrenheit-to-Celsius converter example in "Fabrik - A
       3 | ;; Visual Programming Environment", Ingalls, Wallace, Chow, Ludolph
       4 | ;; and Doyle, OOPSLA 1988.
       5 | 
       6 | (struct temperature (unit value) #:prefab)
       7 | (struct set-temperature (unit value) #:prefab)
       8 | 
       9 | (spawn (field [temp 0])
      10 |        (assert (temperature 'C (temp)))
      11 |        (on (message (set-temperature 'C $new-temp))
      12 |            (temp new-temp))
      13 |        (on (asserted (temperature 'F $other-temp))
      14 |            (temp (* (- other-temp 32) 5/9))))
      15 | 
      16 | (spawn (field [temp 32])
      17 |        (assert (temperature 'F (temp)))
      18 |        (on (message (set-temperature 'F $new-temp))
      19 |            (temp new-temp))
      20 |        (on (asserted (temperature 'C $other-temp))
      21 |            (temp (+ (* other-temp 9/5) 32))))
      22 | 
      23 | (spawn (on (asserted (temperature $unit $value))
      24 |            (printf "Temperature in ~a is ~a\n" unit (exact->inexact value))))
      25 | 
      26 | (spawn (on (asserted (observe (set-temperature _ _)))
      27 |            ;; (send! (set-temperature 'C 20))
      28 |            (send! (set-temperature 'F 90))
      29 |            ))
      30 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/file-system-during.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Toy file system, based on the example in the ESOP2016 submission.
       3 | ;; syndicate/actor implementation, using "during" instead of "on asserted/until retracted".
       4 | 
       5 | (require/activate "fs-shell.rkt")
       6 | (require/activate "fs-protocol.rkt")
       7 | 
       8 | (spawn (field [files (hash)])
       9 |        (during (observe (file $name _))
      10 |                (on-start (printf "At least one reader exists for ~v\n" name))
      11 |                (on-stop (printf "No remaining readers exist for ~v\n" name))
      12 |                (field [content (hash-ref (files) name #f)])
      13 |                (assert (file name (content)))
      14 |                (on (message (save (file name $new-content))) (content new-content))
      15 |                (on (message (delete name)) (content #f)))
      16 |        (on (message (save (file $name $content))) (files (hash-set (files) name content)))
      17 |        (on (message (delete $name)) (files (hash-remove (files) name))))
      18 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/file-system-during2.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Toy file system, based on the example in the ESOP2016 submission.
       3 | ;; syndicate/actor implementation, using "during" instead of "on asserted/until retracted".
       4 | 
       5 | (require/activate "fs-shell.rkt")
       6 | (require/activate "fs-protocol.rkt")
       7 | 
       8 | (spawn (field [files (hash)])
       9 |        (during (observe (file $name _))
      10 |                (on-start (printf "At least one reader exists for ~v\n" name))
      11 |                (assert (file name (hash-ref (files) name #f)))
      12 |                (on-stop (printf "No remaining readers exist for ~v\n" name)))
      13 |        (on (message (save (file $name $content))) (files (hash-set (files) name content)))
      14 |        (on (message (delete $name)) (files (hash-remove (files) name))))
      15 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/file-system-script:
      --------------------------------------------------------------------------------
       1 | write a hello
       2 | write b world
       3 | open a
       4 | open a
       5 | write a goodbye
       6 | open b
       7 | delete a
       8 | close a
       9 | write a another text
      10 | open a
      11 | close b
      12 | delete b
      13 | delete a
      14 | close a
      15 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/file-system.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Toy file system, based on the example in the ESOP2016 submission.
       3 | ;; syndicate/actor implementation.
       4 | 
       5 | (require/activate "fs-shell.rkt")
       6 | (require/activate "fs-protocol.rkt")
       7 | 
       8 | (spawn (field [files (hash)])
       9 |        (on (asserted (observe (file $name _)))
      10 |            (printf "At least one reader exists for ~v\n" name)
      11 |            (until (retracted (observe (file name _)))
      12 |                   (field [content (hash-ref (files) name #f)])
      13 |                   (assert (file name (content)))
      14 |                   (on (message (save (file name $new-content))) (content new-content))
      15 |                   (on (message (delete name)) (content #f)))
      16 |            (printf "No remaining readers exist for ~v\n" name))
      17 |        (on (message (save (file $name $content))) (files (hash-set (files) name content)))
      18 |        (on (message (delete $name)) (files (hash-remove (files) name))))
      19 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/flip-flop.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (require/activate syndicate/drivers/timestate)
       4 | 
       5 | (assertion-struct active ())
       6 | (message-struct toggle ())
       7 | (message-struct stdout-message (body))
       8 | 
       9 | (spawn #:name 'printer
      10 |        (on (message (stdout-message $body))
      11 |            (displayln body)))
      12 | 
      13 | (spawn* #:name 'flip-flop
      14 |         (define (active-state)
      15 |           (react (assert (active))
      16 |                  (stop-when (message (toggle))
      17 |                     (inactive-state))))
      18 |         (define (inactive-state)
      19 |           (react (stop-when (message (toggle))
      20 |                     (active-state))))
      21 |         (inactive-state))
      22 | 
      23 | (spawn #:name 'monitor-flip-flop
      24 |        (on (asserted (active)) (send! (stdout-message "Flip-flop is active")))
      25 |        (on (retracted (active)) (send! (stdout-message "Flip-flop is inactive"))))
      26 | 
      27 | (spawn #:name 'periodic-toggle
      28 |        (field [next-toggle-time (current-inexact-milliseconds)])
      29 |        (on (asserted (later-than (next-toggle-time)))
      30 |            (send! (toggle))
      31 |            (next-toggle-time (+ (next-toggle-time) 1000))))
      32 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/forward-chaining-mini.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Minimal syndicate/actor variation on examples/forward-chaining.rkt.
       3 | 
       4 | (spawn (assert `(parent john douglas)))
       5 | (spawn (assert `(parent bob john)))
       6 | (spawn (assert `(parent ebbon bob)))
       7 | 
       8 | ;; This looks like an implication:
       9 | ;; (parent A C) ⇒ ((ancestor A C) ∧ ((ancestor C B) ⇒ (ancestor A B)))
      10 | ;;
      11 | (spawn (during `(parent ,$A ,$C)
      12 |                (assert `(ancestor ,A ,C))
      13 |                (during `(ancestor ,C ,$B)
      14 |                        (assert `(ancestor ,A ,B)))))
      15 | 
      16 | (spawn (on (asserted `(ancestor ,$A ,$B))
      17 |            (log-info "~a is an ancestor of ~a" A B)))
      18 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/fs-protocol.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; File System Demo protocol
       3 | 
       4 | (provide (struct-out file)
       5 |          (struct-out save)
       6 |          (struct-out delete))
       7 | 
       8 | (struct file (name content) #:prefab)
       9 | (struct save (file) #:prefab)
      10 | (struct delete (name) #:prefab)
      11 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/irc.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (require/activate syndicate/drivers/irc)
       4 | 
       5 | (define NICK "syndicatebot")
       6 | (define CHAN "##syndicatelang")
       7 | (define C (irc-connection "irc.freenode.net" 6667 NICK))
       8 | 
       9 | (spawn #:name 'irc-connection-example
      10 | 
      11 |        (on (message (irc-inbound C $who NICK $body))
      12 |            (log-info "~a said to me: ~a" who body)
      13 |            (send! (irc-outbound C who (format "You said: '~a'" body))))
      14 | 
      15 |        (on (asserted (irc-presence C NICK CHAN))
      16 |            (send! (irc-outbound C CHAN "Hello, everybody!")))
      17 | 
      18 |        (during (irc-presence C $who CHAN)
      19 |          (on-start (log-info "~a joins ~a" who CHAN))
      20 |          (on-stop (log-info "~a leaves ~a" who CHAN)))
      21 | 
      22 |        (on (message (irc-inbound C $who CHAN $body))
      23 |            (log-info "~a says: ~a" who body)
      24 |            (when (not (equal? who NICK))
      25 |              (send! (irc-outbound C CHAN (format "Hey, ~a said '~a'" who body))))))
      26 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/let-event.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Demonstrate let-event.
       3 | ;; Should print "Complete.".
       4 | 
       5 | (spawn* (let-event [(message 'one)
       6 |                     (message 'two)
       7 |                     (message 'three)]
       8 |                    (send! 'complete)))
       9 | 
      10 | (spawn (on-start (send! 'one)
      11 |                  (flush!) ;; needed to give the other actor time to
      12 |                           ;; become responsive to the next message (!)
      13 |                  (send! 'two)
      14 |                  (flush!)
      15 |                  (send! 'three))
      16 |        (stop-when (message 'complete)
      17 |          (printf "Complete.\n")))
      18 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/mini-echo.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (struct echo-req (body) #:prefab)
       4 | (struct echo-resp (body) #:prefab)
       5 | 
       6 | (spawn (field [count 0])
       7 |        (on (message (echo-req $body))
       8 |            (send! (echo-resp body))
       9 |            (count (+ (count) 1))))
      10 | 
      11 | (spawn (on (message (echo-resp $body))
      12 |            (printf "Received: ~v\n" body)))
      13 | 
      14 | (spawn* (until (asserted (observe (echo-req _))))
      15 |         (until (asserted (observe (echo-resp _))))
      16 |         (send! (echo-req 0))
      17 |         (send! (echo-req 1))
      18 |         (send! (echo-req 2)))
      19 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/realize.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | ;; Expected Output:
       4 | #|
       5 | received message bad
       6 | realized good
       7 | |#
       8 | 
       9 | (message-struct ping (v))
      10 | 
      11 | (spawn
      12 |  (on (realize (ping $v))
      13 |      (printf "realized ~a\n" v))
      14 |  (on (message (ping $v))
      15 |      (printf "received message ~a\n" v)
      16 |      (realize! (ping 'good))))
      17 | 
      18 | (spawn*
      19 |  (send! (ping 'bad)))
      20 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/running-total.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Terminal I/O demo program.
       3 | 
       4 | (require (only-in racket/port read-bytes-line-evt))
       5 | 
       6 | (define e (read-bytes-line-evt (current-input-port) 'any))
       7 | 
       8 | (spawn (field [total 0])
       9 |        (begin/dataflow (printf "The total is ~a.\n" (total)))
      10 |        (on-stop (printf "Goodbye!\n"))
      11 |        (on (message (inbound (external-event e (list $input))))
      12 |            (cond
      13 |              [(eof-object? input) (stop-current-facet)]
      14 |              [(string->number (bytes->string/utf-8 input)) => (lambda (n) (total (+ (total) n)))]
      15 |              [else (void)])))
      16 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/show-field-scope-enforcement1.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Demonstrates that fields may not be passed between actors.
       3 | 
       4 | (spawn #:name 'reading-actor
       5 |        (on (message `(read-from ,$this-field))
       6 |            (log-info "Trying to read from ~a" this-field)
       7 |            (log-info "Read: ~a" (this-field))
       8 |            (send! `(read-successfully ,this-field))))
       9 | 
      10 | (spawn #:name 'requesting-actor
      11 |        (field [a 123])
      12 |        (on-start (send! `(read-from ,a)))
      13 |        (stop-when (message `(read-successfully ,a)))
      14 |        (on-stop (log-info "Done.")))
      15 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/show-field-scope-enforcement4.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Demonstrates that fields at actor scope are visible to facets.
       3 | 
       4 | (spawn* (field [x 123])
       5 |         (react
       6 |          (on (message `(read-from ,$this-field))
       7 |              (log-info "Trying to read from ~a" this-field)
       8 |              (log-info "Read: ~a" (this-field))
       9 |              (send! `(read-successfully ,this-field))))
      10 |         (react
      11 |          (on-start
      12 |           (log-info "x in second facet: ~v (should be 123)" (x))
      13 |           (send! `(read-from ,x))
      14 |           (until (message `(read-successfully ,x)))
      15 |           (log-info "Done."))))
      16 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/simple-cross-layer.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (assertion-struct greeting (text))
       4 | 
       5 | (spawn #:name "A" (assert (greeting "Hi from outer space!")))
       6 | (spawn #:name "B" (on (asserted (greeting $t))
       7 |                       (printf "Outer dataspace: ~a\n" t)))
       8 | 
       9 | (dataspace #:name "C"
      10 |   (spawn #:name "D" (assert (outbound (greeting "Hi from inner!"))))
      11 |   (spawn #:name "E" (on (asserted (inbound (greeting $t)))
      12 |                         (printf "Inner dataspace: ~a\n" t))))
      13 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/spreadsheet-script:
      --------------------------------------------------------------------------------
       1 | Name "World"
       2 | Greeting (format "Hello, ~a!" Name)
       3 | 
       4 | A 1
       5 | B 2
       6 | C 3
       7 | Sum (+ A B C)
       8 | 
       9 | Name "Syndicate"
      10 | A 10
      11 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/tcp-relay2.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Simple TCP relay
       3 | 
       4 | (require/activate syndicate/drivers/tcp2)
       5 | 
       6 | (spawn (during (tcp-connection $id (tcp-listener 5000))
       7 |          (assert (tcp-accepted id))
       8 | 
       9 |          (define root-facet-id (current-facet-id))
      10 |          (define outbound-id (gensym 'outbound-id))
      11 | 
      12 |          (assert (tcp-connection outbound-id (tcp-address "localhost" 5999)))
      13 |          (during (tcp-accepted outbound-id)
      14 |            (on-stop (stop-facet root-facet-id))
      15 |            (on (message (tcp-in id $bs))
      16 |                (send! (tcp-out outbound-id bs)))
      17 |            (on (message (tcp-in outbound-id $bs))
      18 |                (send! (tcp-out id bs))))))
      19 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/timestate.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (require/activate syndicate/drivers/timestate)
       4 | 
       5 | (spawn #:name 'demo-timeout
       6 |        (on-start (printf "Starting demo-timeout\n"))
       7 |        (on-stop (printf "Stopping demo-timeout\n"))
       8 |        (stop-when-timeout 3000 (printf "Three second timeout fired\n")))
       9 | 
      10 | (spawn #:name 'demo-later-than
      11 |        (on-start (printf "Starting demo-later-than\n"))
      12 |        (on-stop (printf "Stopping demo-later-than\n"))
      13 |        (field [deadline (+ (current-inexact-milliseconds) 5000)])
      14 |        (stop-when (asserted (later-than (deadline)))
      15 |                   (printf "Deadline expired\n")))
      16 | 
      17 | (spawn #:name 'demo-updating-later-than
      18 |        (field [deadline (current-inexact-milliseconds)])
      19 |        (field [counter 0])
      20 |        (on #:when (< (counter) 10) (asserted (later-than (deadline)))
      21 |            (printf "Tick ~v\n" (counter))
      22 |            (counter (+ (counter) 1))
      23 |            (deadline (+ (deadline) 1000))))
      24 | 
      25 | (spawn* #:name 'demo-sleep
      26 |         (for [(counter (in-range 10))]
      27 |           (printf "Sleeping tick ~v\n" counter)
      28 |           (sleep 1.0)))
      29 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/udp-echo.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (require/activate syndicate/drivers/udp)
       4 | (require syndicate/protocol/advertise)
       5 | 
       6 | (spawn (on (message (udp-packet $peer (udp-listener 5999) $body))
       7 |            (printf "Received from ~a: ~v\n" peer body)
       8 |            (send! (udp-packet (udp-listener 5999) peer body)))
       9 |        (on (asserted (advertise (udp-packet _ (udp-listener 5999) _)))
      10 |            (printf "Socket is ready and will forward datagrams.\n")))
      11 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/actor/vacuous-facet.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | ;; Demonstrates that facets with no endpoints don't outlive their `add-facet!` call.
       3 | 
       4 | ;; This actor will have two facets briefly, before dropping to one:
       5 | (spawn (on-start (react (on-start (printf "Hi 1!\n"))
       6 |                         (on-stop (printf "Bye 1!\n"))))
       7 |        (assert 'x))
       8 | 
       9 | ;; This actor will have one facet briefly, before dropping to zero and terminating:
      10 | (spawn (on-start (printf "Hi 2!\n"))
      11 |        (on-stop (printf "Bye 2!\n")))
      12 | 
      13 | ;; This actor will spawn a couple of nested facets, and when the inner
      14 | ;; one terminates, the outer one will also be terminated:
      15 | (spawn (on-start
      16 |         (printf "3 outer\n")
      17 |         (react (on-start (printf "3 inner\n")
      18 |                          (send! 'terminate-three))
      19 |                (on (message 'terminate-three)
      20 |                    (printf "triggering 3 inner stop\n")
      21 |                    (stop-current-facet))
      22 |                (on-stop (printf "3 inner stop\n"))))
      23 |        (on-stop
      24 |         (printf "3 outer stop\n")))
      25 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/bank-account-monolithic.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/monolithic
       2 | ;; Hello-worldish "bank account" example.
       3 | 
       4 | (struct account (balance) #:prefab)
       5 | (struct deposit (amount) #:prefab)
       6 | 
       7 | (define (manager e balance)
       8 |   (match-event e
       9 |     [(message (deposit amount))
      10 |      (transition (+ balance amount)
      11 |                  (scn (assertion (account (+ balance amount)))))]))
      12 | 
      13 | (define (observer e _)
      14 |   (when (scn? e) (for [(balance (project-assertions (scn-trie e) (account (?!))))]
      15 |                    (printf "Balance changed to ~a\n" balance))))
      16 | 
      17 | (define (updater e _)
      18 |   (when (and (scn? e) (trie-non-empty? (scn-trie e)))
      19 |     (quit (list (message (deposit +100))
      20 |                 (message (deposit -30))))))
      21 | 
      22 | (actor manager 0 (scn/union (assertion (observe (deposit ?))) (assertion (account 0))))
      23 | (actor observer (void) (scn (assertion (observe (account ?)))))
      24 | (actor updater (void) (scn (assertion (observe (observe (deposit ?))))))
      25 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/bank-account.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/core
       2 | ;; Hello-worldish "bank account" example.
       3 | 
       4 | (struct account (balance) #:prefab)
       5 | (struct deposit (amount) #:prefab)
       6 | 
       7 | (define (manager e balance)
       8 |   (match-event e
       9 |     [(message (deposit amount))
      10 |      (transition (+ balance amount) (patch-seq (retract (account balance))
      11 |                                                (assert (account (+ balance amount)))))]))
      12 | 
      13 | (define (observer e _)
      14 |   (when (patch? e) (for [(balance (project-assertions (patch-added e) (account (?!))))]
      15 |                      (printf "Balance changed to ~a\n" balance))))
      16 | 
      17 | (define (updater e _)
      18 |   (when (patch/added? e)
      19 |     (quit (list (message (deposit +100))
      20 |                 (message (deposit -30))))))
      21 | 
      22 | (actor manager 0 (patch-seq (assert (observe (deposit ?))) (assert (account 0))))
      23 | (actor observer (void) (assert (observe (account ?))))
      24 | (actor updater (void) (assert (observe (observe (deposit ?)))))
      25 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/box-and-client.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/core
       2 | ;; Simple mutable box and count-to-infinity box client.
       3 | 
       4 | (struct set-box (new-value) #:transparent)
       5 | (struct box-state (value) #:transparent)
       6 | 
       7 | (actor (lambda (e current-value)
       8 |          (match-event e
       9 |            [(message (set-box new-value))
      10 |             (log-info "box: taking on new-value ~v" new-value)
      11 |             (transition new-value (patch-seq (retract (box-state current-value))
      12 |                                              (assert (box-state new-value))))]))
      13 |        0
      14 |        (patch-seq (sub (set-box ?))
      15 |                   (assert (box-state 0))))
      16 | 
      17 | (actor (lambda (e s)
      18 |          (match-event e
      19 |            [(patch added removed)
      20 |             (transition s (for-trie/list ([(box-state $v) added])
      21 |                             (log-info "client: learned that box's value is now ~v" v)
      22 |                             (message (set-box (+ v 1)))))]))
      23 |        (void)
      24 |        (patch-seq (sub (box-state ?))))
      25 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/example-layer.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/core
       2 | ;; Check that nested-world assertions are properly retracted.
       3 | ;; Should print two "Got SCN:" patches - one adding, and one removing (observe 'die).
       4 | 
       5 | #;(actor (lambda (e s)
       6 |          (match e
       7 |            [(message 'die) (quit)]
       8 |            [_ #f]))
       9 |        (void)
      10 |        (patch-seq (sub 'die)
      11 |                   (sub (observe 'die))))
      12 | 
      13 | (dataspace-actor
      14 |  (actor (lambda (e s)
      15 |           (match e
      16 |             [(message (inbound 'die)) (quit)]
      17 |             [_ #f]))
      18 |         (void)
      19 |         (patch-seq (sub (inbound 'die))
      20 |                    (sub (inbound (observe 'die))))))
      21 | 
      22 | (actor (lambda (e s)
      23 |          (match e
      24 |            [(? patch? p)
      25 |             (printf "Got SCN:\n")
      26 |             (pretty-print-patch p)
      27 |             (transition s (if (patch/added? p)
      28 |                               (message 'die)
      29 |                               '()))]
      30 |            [_ #f]))
      31 |        (void)
      32 |        (sub (observe 'die)))
      33 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/example-meta-drop.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/core
       2 | ;; Analogous to nc-incremental-meta-drop.rkt in the Redex model.
       3 | ;; Demonstrates (hopefully) correct processing of meta-interests when dropping a patch.
       4 | 
       5 | (dataspace-actor
       6 |  (actor (lambda (e u)
       7 |           (match u
       8 |             [0 (transition 1 '())]
       9 |             [1 (transition 2 (retract (outbound 'a)))]
      10 |             [_ #f]))
      11 |         0
      12 |         (patch-seq (assert (outbound 'a))
      13 |                    (assert (observe (inbound 'a))))))
      14 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/example-meta-echo2.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/core
       2 | ;; The actor should receive a single event adding an (inbound 'x) assertion.
       3 | 
       4 | (require syndicate/pretty)
       5 | 
       6 | (dataspace-actor
       7 |  (actor (lambda (e counter)
       8 |           (and e
       9 |                (let ((new-counter (+ counter 1)))
      10 |                  (printf "Received event ~a:\n~a\n" new-counter (syndicate-pretty-print->string e))
      11 |                  (transition (+ counter 1) '()))))
      12 |         0
      13 |         (list (patch-seq (sub (inbound 'x))
      14 |                          (assert (outbound 'x))))))
      15 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/example-quit-dataspace-with-assertion.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/core
       2 | ;; run-ground-vm is being modified to return the set of assertions
       3 | ;; remaining at the end of its execution. This example demonstrates a
       4 | ;; non-empty such set.
       5 | 
       6 | (actor (lambda (e u)
       7 |          (when (zero? u)
       8 |            (transition (+ u 1) (list (assert (outbound 'ok))
       9 |                                      (quit-dataspace)))))
      10 |        0
      11 |        '())
      12 | 
      13 | (module+ main
      14 |   (require rackunit)
      15 |   (require syndicate/trie)
      16 |   (require syndicate/tset)
      17 |   (define previous-ground-dataspace (current-ground-dataspace))
      18 |   (current-ground-dataspace (lambda boot-actions
      19 |                               (let ((result (apply previous-ground-dataspace boot-actions)))
      20 |                                 (check-equal? result
      21 |                                               (pattern->trie (datum-tset 'root) 'ok))))))
      22 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/example-swap-int-and-claim.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/core
       2 | ;; Analogous to nc-incremental-swap-int-and-claim.rkt in the Redex model.
       3 | ;; Demonstrates (hopefully) correct processing of feedback at interest switches.
       4 | 
       5 | (require rackunit)
       6 | 
       7 | (actor (lambda (e u)
       8 |          (if (< (length u) 3)
       9 |              (transition
      10 |               (append u (list e))
      11 |               (if (null? u)
      12 |                   (patch-seq (assert 'a) (unsub 'a))
      13 |                   '()))
      14 |              (begin0 #f (check-equal? u (list #f #f #f)))))
      15 |        '()
      16 |        (sub 'a))
      17 | 
      18 | (actor (lambda (e u)
      19 |          (if (< (length u) 3)
      20 |              (transition
      21 |               (append u (list e))
      22 |               (if (null? u)
      23 |                   (patch-seq (retract 'b) (sub 'b))
      24 |                   '()))
      25 |              (begin0 #f (check-equal? u (list #f #f #f)))))
      26 |        '()
      27 |        (assert 'b))
      28 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/example-wildcard-assertion-1.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/core
       2 | ;; Demonstrate wildcard assertions.
       3 | ;; One actor asserts everything except inbound/outbound assertions (which break
       4 | ;; the ground VM). It therefore *subscribes* to everything too.
       5 | 
       6 | (require syndicate/pretty)
       7 | 
       8 | (actor (lambda (e s)
       9 |          (printf "Subscriber - Aggregate\n")
      10 |          (syndicate-pretty-print s)
      11 |          (printf "Subscriber - Patch\n")
      12 |          (syndicate-pretty-print e)
      13 |          (newline)
      14 |          (if (patch? e)
      15 |              (transition (update-interests s e) '())
      16 |              #f))
      17 |        trie-empty
      18 |        (patch-seq (assert ?)
      19 |                   (retract (outbound ?))
      20 |                   (retract (observe (inbound ?)))
      21 |                   (retract (inbound ?)) ;; not actually required for the purposes of this demo
      22 |                   ))
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/mini-echo.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/core
       2 | 
       3 | (struct echo-req (body) #:prefab)
       4 | (struct echo-resp (body) #:prefab)
       5 | 
       6 | (actor (lambda (e count)
       7 |          (match e
       8 |            [(message (echo-req body))
       9 |             (transition (+ count 1)
      10 |                         (message (echo-resp body)))]
      11 |            [_ #f]))
      12 |        0
      13 |        (sub (echo-req ?)))
      14 | 
      15 | (actor (lambda (e s)
      16 |          (match e
      17 |            [(message (echo-resp body))
      18 |             (printf "Received: ~v\n" body)
      19 |             #f]
      20 |            [_ #f]))
      21 |        (void)
      22 |        (list (sub (echo-resp ?))
      23 |              (message (echo-req 0))
      24 |              (message (echo-req 1))
      25 |              (message (echo-req 2))))
      26 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/examples/udp-hello-plain.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/core
       2 | 
       3 | (require/activate syndicate/drivers/udp)
       4 | 
       5 | (actor (lambda (e s)
       6 |          (match e
       7 |            [(message (udp-packet src dst #"quit\n"))
       8 |             (log-info "Got quit request")
       9 |             (quit (message (udp-packet dst src #"Goodbye!\n")))]
      10 |            [(message (udp-packet src dst body))
      11 |             (log-info "Got packet from ~v: ~v" src body)
      12 |             (define reply (string->bytes/utf-8 (format "You said: ~a" body)))
      13 |             (transition s (message (udp-packet dst src reply)))]
      14 |            [_ #f]))
      15 |        (void)
      16 |        (sub (udp-packet ? (udp-listener 5999) ?)))
      17 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/hash-order.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | 
       3 | (provide hash-order)
       4 | 
       5 | (require data/order)
       6 | (require racket/contract)
       7 | 
       8 | (define hash-order
       9 |   (order 'hash-order
      10 |          any/c
      11 |          eq?
      12 |          (lambda (a b)
      13 |            (define a-code (eq-hash-code a))
      14 |            (define b-code (eq-hash-code b))
      15 |            (or (< a-code b-code)
      16 |                (and (= a-code b-code)
      17 |                     (eq? (datum-order a b) '<))))))
      18 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/info.rkt:
      --------------------------------------------------------------------------------
       1 | #lang setup/infotab
       2 | (define scribblings '(("scribblings/syndicate.scrbl" ())))
       3 | (define racket-launcher-names '("syndicate-broker" "syndicate-render-msd"))
       4 | (define racket-launcher-libraries '("broker/server.rkt" "trace/render-msd.rkt"))
       5 | (define test-include-paths '("syndicate/tests"))
       6 | (define test-omit-paths
       7 |   '(;; Sam: example-plain is interactive, I think
       8 |     "examples/example-plain.rkt"
       9 |     ;; Sam: for whatever reason I get a failure to load libcrypto for f-to-c
      10 |     "examples/actor/f-to-c.rkt"
      11 |     ;; Sam: this test displays to stderr which the package server does not like
      12 |     "tests/nested-spawn-exceptions.rkt"
      13 |     ))
      14 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/interactive.rkt:
      --------------------------------------------------------------------------------
      1 | #lang racket/base
      2 | 
      3 | (module reader syntax/module-reader
      4 |   syndicate/interactive-lang)
      5 | 
      6 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/lang.rkt:
      --------------------------------------------------------------------------------
      1 | #lang racket/base
      2 | 
      3 | (require "actor-lang.rkt")
      4 | (provide (all-from-out "actor-lang.rkt"))
      5 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/lang/reader.rkt:
      --------------------------------------------------------------------------------
      1 | #lang s-exp syntax/module-reader
      2 | syndicate/lang
      3 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/main.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | 
       3 | (require "core.rkt")
       4 | (require "dataspace.rkt")
       5 | (require "protocol/standard-relay.rkt")
       6 | (require "ground.rkt")
       7 | (require "comprehensions.rkt")
       8 | 
       9 | (provide (all-from-out "core.rkt")
      10 |          (all-from-out "dataspace.rkt")
      11 |          (all-from-out "protocol/standard-relay.rkt")
      12 |          (all-from-out "comprehensions.rkt")
      13 | 	 (all-from-out "ground.rkt"))
      14 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/monolithic.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | 
       3 | (module reader syntax/module-reader
       4 |   syndicate/monolithic)
       5 | 
       6 | (require (except-in "core-lang.rkt"
       7 |                     event?
       8 |                     action?
       9 |                     clean-transition
      10 |                     actor
      11 |                     actor/stateless))
      12 | (require "monolithic/scn.rkt")
      13 | (require "monolithic/core.rkt")
      14 | (provide (all-from-out "core-lang.rkt")
      15 |          (all-from-out "monolithic/scn.rkt")
      16 |          (all-from-out "monolithic/core.rkt"))
      17 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/monolithic/scn.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | ;; State Change Notifications, and assorted protocol constructors
       3 | 
       4 | (provide (struct-out scn))
       5 | 
       6 | (require racket/set)
       7 | (require racket/match)
       8 | (require "../trie.rkt")
       9 | (require "../pretty.rkt")
      10 | 
      11 | ;; State Change Notifications
      12 | (struct scn (trie) #:transparent
      13 |   #:methods gen:syndicate-pretty-printable
      14 |   [(define (syndicate-pretty-print d [p (current-output-port)])
      15 |      (pretty-print-trie (scn-trie d) p))])
      16 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/profile.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | 
       3 | (provide profile-dataspace!
       4 |          profile-lambda)
       5 | 
       6 | (require syndicate/core-lang)
       7 | (require profile)
       8 | 
       9 | (define profile-lambda
      10 |   (make-keyword-procedure
      11 |    (lambda (profile-ks profile-vs procedure)
      12 |      (make-keyword-procedure
      13 |       (lambda (invocation-ks invocation-vs . invocation-positionals)
      14 |         (keyword-apply profile-thunk
      15 |                        profile-ks
      16 |                        profile-vs
      17 |                        (list (lambda ()
      18 |                                (keyword-apply procedure
      19 |                                               invocation-ks
      20 |                                               invocation-vs
      21 |                                               invocation-positionals)))))))))
      22 | 
      23 | (define profile-dataspace!
      24 |   (make-keyword-procedure
      25 |    (lambda (ks vs . positionals)
      26 |      (current-ground-dataspace
      27 |       (keyword-apply profile-lambda ks vs (current-ground-dataspace) positionals)))))
      28 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/protocol/advertise.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | ;; Advertisement assertions.
       3 | 
       4 | (provide (struct-out advertise)
       5 |          advertisement
       6 |          pub
       7 |          unpub)
       8 | 
       9 | (require racket/match)
      10 | (require "../core.rkt")
      11 | (require "../trie.rkt")
      12 | (require "standard-relay.rkt")
      13 | 
      14 | (struct advertise (claim) #:prefab)
      15 | 
      16 | (define (drop-advertisement a)
      17 |   (match a
      18 |     [(advertise (inbound x)) (outbound (advertise x))]
      19 |     [_ a]))
      20 | 
      21 | ;; Monolithic SCN
      22 | (define (advertisement pattern)
      23 |   (pattern->trie ' (drop-advertisement (advertise pattern))))
      24 | 
      25 | ;; Incremental SCNs
      26 | (define (pub pattern) (assert (drop-advertisement (advertise pattern))))
      27 | (define (unpub pattern) (retract (drop-advertisement (advertise pattern))))
      28 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/protocol/instance.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | ;; "Instance" protocol for discriminating among
       3 | ;; otherwise-indistinguishable entities.
       4 | 
       5 | (provide (struct-out instance))
       6 | 
       7 | ;; (instance Any Any), assertion or message
       8 | ;;
       9 | ;; In cases where `spec` can have multiple instantiations, serves to
      10 | ;; distinguish between them. Each `id` should be unique within its
      11 | ;; scope.
      12 | ;;
      13 | (struct instance (id spec) #:prefab)
      14 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/support/bytes.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | 
       3 | (provide bytes-index)
       4 | 
       5 | ;; This should probably be in the standard library.
       6 | (define (bytes-index bs b)
       7 |   (define len (bytes-length bs))
       8 |   (let loop ((i 0))
       9 |     (cond [(= i len) #f]
      10 |           [(eqv? (bytes-ref bs i) b) i]
      11 |           [else (loop (+ i 1))])))
      12 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/support/hash.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | ;; Hash-table utilities that are not (yet) part of Racket
       3 | 
       4 | (provide hash-set/remove
       5 |          hashset-member?
       6 |          hashset-add
       7 |          hashset-remove)
       8 | 
       9 | (require racket/set)
      10 | 
      11 | (define (hash-set/remove ht key val [default-val #f] #:compare [compare equal?])
      12 |   (if (compare val default-val)
      13 |       (hash-remove ht key)
      14 |       (hash-set ht key val)))
      15 | 
      16 | (define (hashset-member? ht key val)
      17 |   (define s (hash-ref ht key #f))
      18 |   (and s (set-member? s val)))
      19 | 
      20 | (define (hashset-add ht key val #:set [set set])
      21 |   (hash-set ht key (set-add (hash-ref ht key set) val)))
      22 | 
      23 | (define (hashset-remove ht k v)
      24 |   (define old (hash-ref ht k #f))
      25 |   (if old
      26 |       (let ((new (set-remove old v)))
      27 |         (if (set-empty? new)
      28 |             (hash-remove ht k)
      29 |             (hash-set ht k new)))
      30 |       ht))
      31 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/syntax-classes.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | ;; Common syntax classes.
       3 | 
       4 | (provide (for-syntax assertions
       5 |                      name))
       6 | 
       7 | (require (for-syntax racket/base))
       8 | (require (for-syntax syntax/parse))
       9 | (require (for-syntax syntax/srcloc))
      10 | 
      11 | (require "trie.rkt")
      12 | 
      13 | (begin-for-syntax
      14 |   (define-splicing-syntax-class assertions
      15 |     (pattern (~seq #:assertions P0) #:attr P #'(pattern->trie ' P0))
      16 |     (pattern (~seq #:assertions* P)) ;; P should be an expression yielding a trie
      17 |     (pattern (~seq) #:attr P #'trie-empty))
      18 | 
      19 |   (define-splicing-syntax-class name
      20 |     (pattern (~seq #:name N))
      21 |     (pattern (~seq) #:attr N #'#f)))
      22 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/test-lang.rkt:
      --------------------------------------------------------------------------------
      1 | #lang racket/base
      2 | 
      3 | (require "test.rkt")
      4 | (require "actor-lang.rkt")
      5 | 
      6 | (provide (except-out (all-from-out "test.rkt") test-module-begin)
      7 |          (except-out (all-from-out "actor-lang.rkt") #%module-begin)
      8 |          (rename-out [test-module-begin #%module-begin]))
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/bank-account.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/test
       2 | 
       3 | (spawn (field [balance 0])
       4 |        (assert (list "account" (balance)))
       5 |        (on (message (list "deposit" $amount))
       6 |            (balance (+ (balance) amount))))
       7 | 
       8 | (spawn (on (asserted (list "account" $balance))
       9 |            (printf "Balance changed to ~a\n" balance))
      10 |        (stop-when (asserted (list "account" 70))
      11 |                   (printf "bye\n"))
      12 |        (on-stop (printf "good.\n")))
      13 | 
      14 | (spawn (stop-when (asserted (observe (list "deposit" _)))
      15 |                   (send! (list "deposit" +100))
      16 |                   (send! (list "deposit" -30))))
      17 | 
      18 | (trace (assertion-added '("account" 0))
      19 |        (and (assertion-added '("account" 100))
      20 |             (assertion-removed '("account" 0)))
      21 |        (and (assertion-added '("account" 70))
      22 |             (assertion-removed '("account" 100))))
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/boop.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (dataspace
       4 | 
       5 |  (spawn (on (message "hello")
       6 |             (printf "got hello\n")))
       7 |  
       8 |  (spawn (assert "I am here")
       9 |         (on-start (printf "hello\n")
      10 |                   (send! "hello"))))
      11 | 
      12 | #;(dataspace
      13 |  (send! 5))
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/create-new-facet-in-on-stop.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/test
       2 | 
       3 | ;; The facet in the on-stop should immediately die and its assertion should never be visible.
       4 | ;; Pretty sure the little implementation gets that wrong.
       5 | ;; the trace does not have a way of saying there should never be a "here" assertion
       6 | 
       7 | (spawn
       8 |  (on-stop (react (assert (outbound "here"))))
       9 |  (stop-when (message "stop")))
      10 | 
      11 | (spawn (on-start (send! "stop")))
      12 | 
      13 | (trace (message "stop"))
      14 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/facet-creation-during-stop-from-grandchild.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/test
       2 | 
       3 | ;; currently FAILS
       4 | 
       5 | ;; dubious behavior by little implementation;
       6 | ;; create new facets from more nested facets
       7 | 
       8 | ;; The facet in the on-stop should immediately die and its assertion should never be visible.
       9 | ;; Pretty sure the little implementation gets that wrong.
      10 | ;; the trace does not have a way of saying there should never be an "inner" assertion
      11 | 
      12 | (spawn (on-start
      13 |         (react (on-stop
      14 |                 (react (assert (outbound "inner"))))))
      15 |        (stop-when (message "stop")
      16 |                   (react (assert (outbound "outer")))))
      17 | 
      18 | (spawn (on-start (send! "stop")))
      19 | 
      20 | (trace (message "stop"))
      21 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/maintain-knowledge-across-events.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/test
       2 | 
       3 | (spawn (on (asserted "outer")
       4 |            (react (on (message "bam")
       5 |                       (react (on (asserted "outer")
       6 |                                  (send! "icu")
       7 |                                  (printf "icu\n")))))))
       8 | 
       9 | (spawn (assert "outer")
      10 |        (on (asserted (observe "bam"))
      11 |            (send! "bam")))
      12 | 
      13 | (trace (message "icu"))
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/multi-level-message.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/test
       2 | 
       3 | ;; currently failing, seemingly due to a bug in the big implementation; see
       4 | ;; https://github.com/tonyg/syndicate/issues/20
       5 | 
       6 | (dataspace
       7 |  (spawn (on (message "hello")
       8 |             (printf "got hello\n")))
       9 |  
      10 |  (spawn (assert 12)
      11 |         (on-start (printf "hello\n")
      12 |                   (send! (outbound "hello")))))
      13 | 
      14 | (trace (message "hello"))
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/multi-level-other-way.rkt:
      --------------------------------------------------------------------------------
      1 | #lang syndicate/test
      2 | 
      3 | (dataspace (spawn (on (asserted (inbound "gday"))
      4 |                       (send! (outbound "good things")))))
      5 | 
      6 | (spawn (assert "gday"))
      7 | 
      8 | (trace (message "good things"))
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/nested-spawn-exceptions.rkt:
      --------------------------------------------------------------------------------
      1 | #lang syndicate/test
      2 | 
      3 | (spawn (on (message "go")
      4 |            (spawn (on-start (/ 1 0)))
      5 |            (send! "lovely happiness")))
      6 | 
      7 | (spawn (on-start (send! "go")))
      8 | 
      9 | (trace (message "lovely happiness"))
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/ping-pong.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/test
       2 | 
       3 | (spawn (on (message "ping")
       4 |            (printf "ping\n")
       5 |            (send! "pong")))
       6 | 
       7 | (spawn (on (message "pong")
       8 |            (printf "pong\n")
       9 |            (send! "ping"))
      10 |        (on-start (send! "ping")))
      11 | 
      12 | (trace (message "ping")
      13 |        (message "pong")
      14 |        (message "ping")
      15 |        (message "pong")
      16 |        (message "ping")
      17 |        (message "pong")
      18 |        (message "ping")
      19 |        (message "pong"))
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/simple-multi-level.rkt:
      --------------------------------------------------------------------------------
      1 | #lang syndicate/test
      2 | 
      3 | (spawn (on (asserted "hello")
      4 |            (printf "goodbye\n")))
      5 | 
      6 | (dataspace (spawn (assert (outbound "hello"))))
      7 | 
      8 | (trace (assertion-added "hello"))
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/simple1.rkt:
      --------------------------------------------------------------------------------
      1 | #lang syndicate/test
      2 | 
      3 | (spawn (on (asserted 5)
      4 |            (printf "wat\n")))
      5 | 
      6 | (spawn (assert 5))
      7 | 
      8 | (trace (assertion-added (observe 5))
      9 |        (assertion-added 5))
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/stop-when-react.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/test
       2 | 
       3 | ;; test that terminating facets can create new facets (at the parent level)
       4 | 
       5 | (spawn (stop-when (message "stop")
       6 |                   (react (on (message "poodle")
       7 |                              (send! "success")
       8 |                              (printf "woohoo\n")))))
       9 | 
      10 | (spawn (on-start (send! "stop"))
      11 |        (on (asserted (observe "poodle"))
      12 |            (send! "poodle")))
      13 | 
      14 | (trace (message "success"))
      15 | 
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/tests/use-current-knowledge-with-new-facet.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate/test
       2 | 
       3 | (spawn (on (asserted "hello")
       4 |            (react (on (asserted "hello")
       5 |                       (printf "do I run?\n")
       6 |                       (send! "yes indeed")))))
       7 | 
       8 | (spawn (assert "hello"))
       9 | 
      10 | (trace (message "yes indeed"))
      
      
      --------------------------------------------------------------------------------
      /racket/syndicate/util.rkt:
      --------------------------------------------------------------------------------
       1 | #lang syndicate
       2 | 
       3 | (provide capture-spawn-actions)
       4 | 
       5 | (require "store.rkt"
       6 |          (submod "actor.rkt" implementation-details))
       7 | 
       8 | (define (capture-spawn-actions loc thunk)
       9 |   (call-with-syndicate-effects
      10 |    (lambda ()
      11 |      (with-store [(current-pending-actions '())
      12 |                   (current-pending-patch patch-empty)
      13 |                   (current-action-transformer values)]
      14 |        (call-with-values thunk
      15 |                          (lambda results
      16 |                            (ensure-spawn-actions! loc (cons results (current-pending-actions)))))))))
      17 | 
      18 | (define (ensure-spawn-actions! loc acts)
      19 |   (check-spawn-actions! acts
      20 |                         (lambda (act) (raise-argument-error loc
      21 |                                                             "actor creation action"
      22 |                                                             act))))
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/.gitignore:
      --------------------------------------------------------------------------------
      1 | *.pml
      2 | *.trail
      3 | *.rktd
      4 | *.tmp
      
      
      --------------------------------------------------------------------------------
      /racket/typed/Makefile:
      --------------------------------------------------------------------------------
       1 | pan : pan.c
       2 | 	gcc -o pan pan.c
       3 | 
       4 | pan.c : leader-and-seller.pml
       5 | 	spin -a leader-and-seller.pml
       6 | 
       7 | # -a to analyze, -f for (weak) fairness
       8 | # -n to elide report of unreached states
       9 | # -N spec-name to verify a particular specification
      10 | check: pan
      11 | 	./pan -a -f -n
      12 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/anonymous-facet.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate
      2 | 
      3 | (define (behavior)
      4 |   (start-facet
      5 |       (assert (tuple 5 6))))
      6 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/file-system.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define-constructor (file name content)
       4 |   #:type-constructor FileT
       5 |   #:with File (FileT String String))
       6 | 
       7 | (define-type-alias FileDemand
       8 |   (Observe (FileT String ★/t)))
       9 | 
      10 | (define-constructor (save name content)
      11 |   #:type-constructor SaveT
      12 |   #:with Save (SaveT String String))
      13 | 
      14 | (define-constructor (delete name)
      15 |   #:type-constructor DeleteT
      16 |   #:with Delete (DeleteT String))
      17 | 
      18 | ;; unique role
      19 | (define-type-alias Server
      20 |   (Role (server)
      21 |         (Reacts (Know FileDemand)
      22 |                 (Role (_)
      23 |                       (Shares File)))
      24 |         (Reacts (Message Save))
      25 |         (Reacts (Message Delete))))
      26 | 
      27 | (define-type-alias Reader
      28 |   (Role (reader)
      29 |         (Shares FileDemand)))
      30 | 
      31 | (define-type-alias Writer
      32 |   (Role (writer)
      33 |         (Sends Save)
      34 |         (Sends Delete)))
      35 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/observe-star.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | ;; Expected Output:
       3 | ;; got: new
       4 | 
       5 | (define-constructor* (something : SomethingT new blue)
       6 |   #:with Something (SomethingT String Int))
       7 | 
       8 | (define-type-alias τc
       9 |   (U Something
      10 |      (Observe★ SomethingT)))
      11 | 
      12 | (run-ground-dataspace
      13 |  τc
      14 |  (spawn
      15 |   (start-facet _
      16 |     (assert (something "new" 42))))
      17 |  (spawn
      18 |   (start-facet _
      19 |     (on (asserted (something $x 42))
      20 |         (printf "got: ~a\n" x))))
      21 |  )
      22 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/ping-pong.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | ;; Expected Output
       4 | ;; pong: 8339
       5 | 
       6 | (message-struct ping : Ping (v))
       7 | (message-struct pong : Pong (v))
       8 | 
       9 | (define-type-alias ds-type
      10 |   (U (Message (Ping Int))
      11 |      (Message (Pong Int))
      12 |      (Observe (Ping ★/t))
      13 |      (Observe (Pong ★/t))
      14 |      (Observe (Observe (Ping ★/t)))))
      15 | 
      16 | (run-ground-dataspace ds-type
      17 |   (spawn ds-type
      18 |     (lift+define-role ponger
      19 |     (start-facet echo
      20 |       (on (message (ping $v))
      21 |           (send! (pong v))))))
      22 |   (spawn ds-type
      23 |     (lift+define-role pinger
      24 |     (start-facet serve
      25 |       (on (asserted (observe (ping _)))
      26 |           (send! (ping 8339)))
      27 |       (on (message (pong $x))
      28 |           (printf "pong: ~v\n" x))))))
      29 | 
      30 | (module+ test
      31 |   (verify-actors (And (Eventually (M (Ping Int)))
      32 |                       (Eventually (M (Pong Int)))
      33 |                       (Always (Implies (M (Ping Int))
      34 |                                        (Eventually (M (Pong Int))))))
      35 |                  pinger
      36 |                  ponger))
      37 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/provides.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate
      2 | 
      3 | (provide a-fun)
      4 | 
      5 | (define (a-fun [x : Int] -> Int)
      6 |   (+ x 1))
      7 | 
      8 | #;(a-fun 5)
      9 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/realize.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | ;; Expected Output:
       4 | #|
       5 | received message bad
       6 | realized good
       7 | |#
       8 | 
       9 | (message-struct ping : Ping (v))
      10 | 
      11 | (define-type-alias τc
      12 |   (U (Message (Ping Symbol))
      13 |      (Observe ★/t)))
      14 | 
      15 | (run-ground-dataspace τc
      16 | (spawn
      17 |  (start-facet _
      18 |   (on (realize (ping $v:Symbol))
      19 |       (printf "realized ~a\n" v))
      20 |   (on (message (ping $v))
      21 |       (printf "received message ~a\n" v)
      22 |       (realize! (ping 'good)))))
      23 | 
      24 | (spawn
      25 |  (start-facet _
      26 |   (on start (send! (ping 'bad)))))
      27 | )
      28 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/require-struct/client.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require-struct msg #:as Msg
       4 |                 #:from "driver.rkt")
       5 | 
       6 | (define m (msg 1 "hi"))
       7 | 
       8 | (msg-in m)
       9 | (msg-out m)
      10 | 
      11 | (match m
      12 |   [(msg (bind x Int) _)
      13 |    (displayln x)])
      14 | 
      15 | ;; error: msg/checked: arity mismatch
      16 | #;(msg 1 2 3)
      17 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/require-struct/client2.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | ;; using different syntax than "client.rkt"
       4 | 
       5 | (require/typed "driver.rkt" [#:struct msg])
       6 | 
       7 | (define m : (MsgT Int String) (msg 1 "hi"))
       8 | 
       9 | (msg-in m)
      10 | (msg-out m)
      11 | 
      12 | (match m
      13 |   [(msg (bind x Int) _)
      14 |    (displayln x)])
      15 | 
      16 | ;; error: msg/checked: arity mismatch
      17 | #;(msg 1 2 3)
      18 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/require-struct/driver.rkt:
      --------------------------------------------------------------------------------
      1 | #lang racket
      2 | 
      3 | (provide (struct-out msg))
      4 | 
      5 | (struct msg (in out) #:transparent)
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/require-struct/omit-accs/lib.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket
       2 | 
       3 | (struct egg (size day) #:transparent)
       4 | 
       5 | (provide (except-out (struct-out egg)
       6 |                      egg-size
       7 |                      egg-day))
       8 | 
       9 | 
      10 | (struct chicken (eggs) #:transparent)
      11 | 
      12 | (provide chicken)
      13 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/require-struct/omit-accs/require-omit-accs.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate/roles
       2 | 
       3 | (require-struct egg #:as Egg #:from "lib.rkt" #:omit-accs)
       4 | 
       5 | (define e (egg 5 "Sun"))
       6 | 
       7 | (match e
       8 |   [(egg $sz $d)
       9 |    (displayln sz)
      10 |    (displayln d)])
      11 | 
      12 | (require-struct chicken #:as Chicken #:from "lib.rkt" #:omit-accs)
      13 | 
      14 | (define c (chicken (list e e e)))
      15 | 
      16 | (match c
      17 |   [(chicken $eggs)
      18 |    (displayln eggs)])
      19 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/require:typed/client.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate
      2 | 
      3 | (require/typed "lib.rkt" [x : Int])
      4 | 
      5 | (displayln (+ x 1))
      6 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/require:typed/lib.rkt:
      --------------------------------------------------------------------------------
      1 | #lang racket
      2 | 
      3 | (provide x)
      4 | 
      5 | (define x 42)
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/require:typed/opaque/client-arity.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate
      2 | 
      3 | (require/typed "lib.rkt"
      4 |   [#:opaque Vec #:arity = 3]
      5 |   [ones : (Vec Int Int Int)]
      6 |   [vec+ : (→fn (Vec Int Int Int) (Vec Int Int Int) (Vec Int Int Int))])
      7 | 
      8 | (vec+ ones ones)
      9 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/require:typed/opaque/client.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate
      2 | 
      3 | (require/typed "lib.rkt"
      4 |   [#:opaque Vec]
      5 |   [ones : Vec]
      6 |   [vec+ : (→fn Vec Vec Vec)])
      7 | 
      8 | (vec+ ones ones)
      9 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/require:typed/opaque/lib.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket
       2 | 
       3 | (provide ones
       4 |          vec+)
       5 | 
       6 | (struct vec (x y z) #:transparent)
       7 | 
       8 | (define ones (vec 1 1 1))
       9 | 
      10 | (define (vec+ v1 v2)
      11 |   (vec (+ (vec-x v1) (vec-x v2))
      12 |        (+ (vec-y v1) (vec-y v2))
      13 |        (+ (vec-z v1) (vec-z v2))))
      14 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/requires.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate
      2 | 
      3 | (require "provides.rkt")
      4 | 
      5 | (a-fun 5)
      6 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/simple-dataflow.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | ;; Expected Output
       4 | ;; f: 0
       5 | ;; f: 18
       6 | 
       7 | (define-type-alias ds-type
       8 |   (U (Tuple String Int)
       9 |      (Observe ★/t)))
      10 | 
      11 | (run-ground-dataspace ds-type
      12 |   (spawn ds-type
      13 |     (start-facet server
      14 |       (field [f Int 0])
      15 |       (begin/dataflow
      16 |         (printf "f = ~v\n" (ref f)))
      17 |       (on (asserted (tuple "key" (bind v Int)))
      18 |           (set! f v))))
      19 |   (spawn ds-type
      20 |     (start-facet client
      21 |       (assert (tuple "key" 18)))))
      22 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/simple-dataspace.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate
      2 | 
      3 | (run-ground-dataspace Int
      4 |   (spawn #:type Int
      5 |     (start-facet _
      6 |       (assert 42))))
      7 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/simple-during.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | ;; Expected Output
       4 | ;; +GO
       5 | ;; +ready
       6 | ;; -GO
       7 | ;; -ready
       8 | 
       9 | (define-type-alias ds-type
      10 |   (U (Tuple String) (Observe (Tuple ★/t))))
      11 | 
      12 | (run-ground-dataspace ds-type
      13 |   (spawn ds-type
      14 |     (start-facet _
      15 |       (during (tuple "GO")
      16 |         (assert (tuple "ready")))))
      17 |   (spawn ds-type
      18 |     (start-facet flag
      19 |       ;; type error when this was mistakenly just "GO"
      20 |       (assert (tuple "GO"))
      21 |       (on (asserted (tuple "ready"))
      22 |           (stop flag))))
      23 |   (spawn ds-type
      24 |     (start-facet obs
      25 |       (during (tuple (bind s String))
      26 |         (on start
      27 |             (printf "+~a\n" s))
      28 |         (on stop
      29 |             (printf "-~a\n" s))))))
      30 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/simple-query-hash.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | ;; Expected Output
       4 | ;; adding key2 -> 88
       5 | ;; adding key1 -> 18
       6 | ;; size: 0
       7 | ;; size: 2
       8 | ;; removing key2
       9 | ;; adding key2 -> 99
      10 | 
      11 | (assertion-struct output : Output (v))
      12 | 
      13 | (define-type-alias ds-type
      14 |   (U (Tuple String Int)
      15 |      (Output Int)
      16 |      (Observe ★/t)))
      17 | 
      18 | (run-ground-dataspace ds-type
      19 |   (spawn ds-type
      20 |    (start-facet querier
      21 |      (define/query-hash key# (tuple (bind k String) (bind v Int)) k v
      22 |        #:on-add (printf "adding ~a -> ~a\n" k v)
      23 |        #:on-remove (printf "removing ~a\n" k))
      24 |      (assert (output (hash-count (ref key#))))))
      25 |    (spawn ds-type
      26 |     (start-facet client
      27 |       (assert (tuple "key1" 18))
      28 |       (on start
      29 |           (start-facet tmp
      30 |             (field [v Int 88])
      31 |             (assert (tuple "key2" (ref v)))
      32 |             (on (asserted (output 2))
      33 |                 (set! v 99))))
      34 |       (during (output (bind v Int))
      35 |         (on start
      36 |             (printf "size: ~v\n" v))))))
      37 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/simple-query-set.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | ;; Expected Output
       4 | ;; size: 0
       5 | ;; size: 2
       6 | 
       7 | (define-type-alias ds-type
       8 |   (U (Tuple String Int)
       9 |      (Observe ★/t)))
      10 | 
      11 | (run-ground-dataspace ds-type
      12 |   (spawn ds-type
      13 |     (start-facet querier
      14 |       (define/query-set key (tuple "key" (bind v Int)) v)
      15 |       (assert (tuple "size" (set-count (ref key))))))
      16 |   (spawn ds-type
      17 |     (start-facet client
      18 |       (assert (tuple "key" 18))
      19 |       (assert (tuple "key" 88))
      20 |       (during (tuple "size" (bind v Int))
      21 |         (on start
      22 |             (printf "size: ~v\n" v))))))
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/simple-query-value.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | ;; Expected Output
       4 | ;; query: 0
       5 | ;; query: 19
       6 | 
       7 | (define-type-alias ds-type
       8 |   (U (Tuple String Int)
       9 |      (Observe ★/t)))
      10 | 
      11 | (run-ground-dataspace ds-type
      12 |   (spawn ds-type
      13 |     (start-facet querier
      14 |       (define/query-value [key : Int] 0 (tuple "key" (bind v Int)) (+ v 1))
      15 |       (assert (tuple "query" (ref key)))))
      16 |   (spawn ds-type
      17 |     (start-facet client
      18 |       (assert (tuple "key" 18))
      19 |       (during (tuple "query" (bind v Int))
      20 |         (on start
      21 |             (printf "query: ~v\n" v))))))
      22 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/simple-stop-facet.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | ;; Expected Output:
       4 | ;; +42
       5 | ;; +18
       6 | ;; +9
       7 | ;; +88
       8 | ;; -18
       9 | ;; -9
      10 | 
      11 | (define-type-alias ds-type
      12 |   (U (Tuple Int)
      13 |      (Observe (Tuple ★/t))))
      14 | 
      15 | (run-ground-dataspace ds-type
      16 |   (spawn #:type ds-type
      17 |    (print-role
      18 |    (start-facet doomed
      19 |      (assert (tuple 18))
      20 |      (on (asserted (tuple 42))
      21 |          (stop doomed
      22 |                 (start-facet the-afterlife
      23 |                   (assert (tuple 88))))))))
      24 | 
      25 |   (spawn #:type ds-type
      26 |     (start-facet obs
      27 |       (assert (tuple 42))
      28 |       (on (asserted (tuple (bind x Int)))
      29 |           (printf "+~v\n" x))
      30 |       (on (retracted (tuple (bind x Int)))
      31 |           (printf "-~v\n" x))))
      32 | 
      33 |   ;; null-ary stop
      34 |   (spawn #:type ds-type
      35 |     (start-facet meep
      36 |       (assert (tuple 9))
      37 |       (on (asserted (tuple 88))
      38 |           (stop meep)))))
      39 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/struct-out/client.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate/roles
      2 | 
      3 | (require "typed-out.rkt")
      4 | 
      5 | (define c : (Cow Int) (cow 5))
      6 | 
      7 | (cow-moos c)
      8 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/struct-out/struct-in.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate/roles
      2 | 
      3 | (require "struct-out.rkt")
      4 | 
      5 | (happy-days (happy 5))
      6 | 
      7 | (define classic : (Happy Int) (happy 100))
      8 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/struct-out/struct-out.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate/roles
      2 | 
      3 | (provide (struct-out happy))
      4 | 
      5 | (define-constructor* (happy : Happy days))
      6 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/struct-out/typed-out.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate/roles
      2 | 
      3 | (require-struct cow #:as Cow #:from "untyped.rkt")
      4 | 
      5 | (provide (struct-out cow))
      6 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/struct-out/untyped.rkt:
      --------------------------------------------------------------------------------
      1 | #lang racket
      2 | 
      3 | (provide (struct-out cow))
      4 | 
      5 | (struct cow (moos) #:transparent)
      6 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/examples/with-facets.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define (wf1)
       4 | (spawn
       5 |  (with-facets
       6 |    ([onn (facet (assert (tuple 'on))
       7 |                 (on start (printf "on\n")))]
       8 |     [off (facet (on (asserted (tuple 'go))
       9 |                     (stop off
      10 |                           (start onn)))
      11 |                 (on start (printf "off\n")))])
      12 |    off)))
      13 | 
      14 | (run-ground-dataspace
      15 |  (wf1)
      16 |  (spawn (start-facet _ (assert (tuple 'go)))))
      17 | 
      18 | ;; BAD
      19 | #;(spawn
      20 |  (with-facets
      21 |    [on (facet (on start (start on)))]
      22 |    on))
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/info.rkt:
      --------------------------------------------------------------------------------
       1 | #lang info
       2 | 
       3 | (define scribblings '(("scribblings/typed-syndicate.scrbl" ())))
       4 | 
       5 | (define compile-omit-paths
       6 |   '("examples"
       7 |     "tests"))
       8 | 
       9 | (define test-omit-paths
      10 |   ;; a number of the examples use SPIN for model checking which I need
      11 |   ;; to figure out how to get working on the package server
      12 |   '("examples/"
      13 |     "tests/spin/"))
      14 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/syndicate/2d.rkt:
      --------------------------------------------------------------------------------
       1 | #lang turnstile
       2 | 
       3 | (provide run-2d-dataspace)
       4 | 
       5 | (require "core-types.rkt"
       6 |          "roles.rkt")
       7 | 
       8 | 
       9 | (module shim racket
      10 |   (provide run-2d run-2d*)
      11 |   (require (only-in syndicate-gl/2d 2d-dataspace))
      12 |   (require (only-in (submod syndicate/actor for-module-begin) capture-actor-actions))
      13 |   (require syntax/parse/define)
      14 | 
      15 |   (define (run-2d boot)
      16 |     ((2d-dataspace) (capture-actor-actions boot)))
      17 | 
      18 |   (define-simple-macro (run-2d* s ...)
      19 |     (run-2d (lambda () (list s ...))))
      20 | 
      21 |   )
      22 | 
      23 | (require (submod "." shim))
      24 | 
      25 | (define-typed-syntax (run-2d-dataspace s ...) ≫
      26 |   [⊢ s ≫ s-] ...
      27 |   [⊢ (dataspace s- ...) ≫ _ (⇒ ν (~effs (~AnyActor τ-ds)))]
      28 |   -----------------------------------------------------------------------------------
      29 |   [⊢ (run-2d* s- ...)
      30 |      (⇒ : (AssertionSet τ-ds))]
      31 | 
      32 |   )
      33 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/syndicate/core/lang/reader.rkt:
      --------------------------------------------------------------------------------
      1 | #lang s-exp syntax/module-reader
      2 | typed/core
      3 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/syndicate/drivers/timestate.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate/roles
       2 | 
       3 | (provide activate!
       4 |          later-than
       5 |          LaterThanT
       6 |          LaterThan
       7 |          TimeStateDriver)
       8 | 
       9 | (require-struct later-than
      10 |                 #:as LaterThanT
      11 |                 #:from syndicate/drivers/timestate)
      12 | 
      13 | (define-type-alias LaterThan (LaterThanT Int))
      14 | 
      15 | (define-type-alias TimeStateDriver
      16 |   (U LaterThan
      17 |      (Observe (LaterThanT Int))
      18 |      (Observe (Observe (LaterThanT ★/t)))))
      19 | 
      20 | ;; TODO ignoring other driver underneath it
      21 | 
      22 | (require/typed (submod syndicate/drivers/timestate syndicate-main)
      23 |   [activate! : (proc → ⊥ #:spawns ((Actor TimeStateDriver)))])
      24 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/syndicate/either.rkt:
      --------------------------------------------------------------------------------
       1 | #lang turnstile
       2 | 
       3 | (provide Left
       4 |          Right
       5 |          Either
       6 |          left
       7 |          right
       8 |          partition/either)
       9 | 
      10 | (require "core-types.rkt")
      11 | (require "core-expressions.rkt")
      12 | (require "for-loops.rkt")
      13 | (require "list.rkt")
      14 | 
      15 | (define-constructor* (left : Left v))
      16 | (define-constructor* (right : Right v))
      17 | 
      18 | (define-type-alias (Either A B)
      19 |   (U (Left A)
      20 |      (Right B)))
      21 | 
      22 | (define (∀ (X Y Z) (partition/either [xs : (List X)]
      23 |                                      [pred : (→fn X (Either Y Z))]
      24 |                                      -> (Tuple (List Y) (List Z))))
      25 |   (for/fold ([lefts (List Y) (list)]
      26 |              [rights (List Z) (list)])
      27 |             ([x xs])
      28 |     (define y-or-z (pred x))
      29 |     (match y-or-z
      30 |       [(left (bind y Y))
      31 |        (tuple (cons y lefts)
      32 |               rights)]
      33 |       [(right (bind z Z))
      34 |        (tuple lefts
      35 |               (cons z rights))])))
      36 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/syndicate/lang/reader.rkt:
      --------------------------------------------------------------------------------
      1 | #lang s-exp syntax/module-reader
      2 | typed/syndicate/roles
      3 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/syndicate/maybe.rkt:
      --------------------------------------------------------------------------------
       1 | #lang turnstile
       2 | 
       3 | (provide Maybe
       4 |          None
       5 |          None*
       6 |          Some
       7 |          some
       8 |          none
       9 |          has?)
      10 | 
      11 | (require "core-types.rkt")
      12 | (require "prim.rkt")
      13 | (require "core-expressions.rkt")
      14 | 
      15 | 
      16 | (define-constructor* (none* : None*))
      17 | (define-constructor* (some : Some v))
      18 | 
      19 | (define-type-alias None (None*))
      20 | 
      21 | (define none : None
      22 |   (none*))
      23 | 
      24 | (define-type-alias (Maybe X)
      25 |   (U None
      26 |      (Some X)))
      27 | 
      28 | #;(define (∀ (X Y) (partition/maybe [xs : (List X)]
      29 |                                   [pred : (→fn X (Maybe Y))]
      30 |                                   -> (Tuple (List Y) (List X))))
      31 |     #f)
      32 | 
      33 | #;(require (only-in "core-expressions.rkt" match error discard)
      34 |          "prim.rkt")
      35 | #;(define (∀ (X) (unwrap! [x : (Maybe X)] -> (Maybe X)))
      36 |   (match x
      37 |     [(some discard)
      38 |      (error "some")]
      39 |     [none
      40 |      (error "none")]))
      41 | 
      42 | (define (∀ (X) (has? [v : (Maybe X)] [p : (→fn X Bool)] -> Bool))
      43 |   (match v
      44 |     [none
      45 |      #f]
      46 |     [(some $x)
      47 |      (p x)]))
      48 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/syndicate/replay-trail.sh:
      --------------------------------------------------------------------------------
      1 | #!/bin/sh
      2 | 
      3 | spin -p -t $1
      4 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/syndicate/roles/lang/reader.rkt:
      --------------------------------------------------------------------------------
      1 | #lang s-exp syntax/module-reader
      2 | typed/syndicate/roles
      3 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/syndicate/run-spin.sh:
      --------------------------------------------------------------------------------
       1 | #!/bin/sh
       2 | 
       3 | pushd ${1%/*}/ > /dev/null
       4 | 
       5 | EXE="$1-verifier.o"
       6 | 
       7 | spin -a $1
       8 | if [[ $? -ne 0 ]]; then
       9 |     popd > /dev/null
      10 |     exit 1
      11 | fi
      12 | 
      13 | gcc -O3 -o $EXE -D NFAIR=3 pan.c
      14 | 
      15 | # -a to analyze, -f for (weak) fairness
      16 | # -n to elide report of unreached states
      17 | # -I to search for (approximate) shorter error paths
      18 | # -N spec-name to verify a particular specification
      19 | $EXE -a -f -n -I -N $2
      20 | rm $EXE pan.*
      21 | 
      22 | popd > /dev/null
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/syndicate/spin-prelude.pml:
      --------------------------------------------------------------------------------
       1 | /* Useful macros */
       2 | 
       3 | #define ASSERTED(x) (x##_assertions > 0)
       4 | #define RETRACTED(x) (x##_assertions == 0)
       5 | #define ASSERT(x) x##_update = x##_update + 1
       6 | #define RETRACT(x) x##_update = x##_update - 1
       7 | #define SEND(x) x##_messages = x##_messages + 1
       8 | 
       9 | /* Rest of Program */
      10 | 
      11 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/syndicate/supervise.rkt:
      --------------------------------------------------------------------------------
       1 | #lang turnstile
       2 | 
       3 | (provide supervise)
       4 | 
       5 | (require "core-types.rkt")
       6 | (require (submod "roles.rkt" implementation-details))
       7 | (require (prefix-in syndicate: syndicate/supervise))
       8 | 
       9 | ;; TODO - need to activate timestate driver for supervise to actually work
      10 | 
      11 | (define-typed-syntax (supervise on:opt-name s ...+) ≫
      12 |   [⊢ s ≫ s- (⇒ ν (~effs F ...))] ...
      13 |   #:do [(ensure-all! AnyActor? #'(F ... ...) "only spawn effects allowed" #:src this-syntax)]
      14 |   ------------------------------
      15 |   [⊢ (syndicate:supervise (~? (~@ #:name on.name-)) s- ...)
      16 |      (⇒ : ★/t)
      17 |      (⇒ ν (F ... ...))]
      18 |   )
      19 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/syndicate/test-utils.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket/base
       2 | 
       3 | (provide run/timeout
       4 |          define/timeout)
       5 | 
       6 | (require racket/engine)
       7 | 
       8 | ;; (-> A) Real -> (U A Engine)
       9 | ;; run the given thunk in an engine for 'fuel' milliseconds
      10 | ;; if the engine completes, returns the result, otherwise the engine itself
      11 | (define (run/timeout tnk [fuel 1000])
      12 |   (define e (engine (lambda (p) (tnk))))
      13 |   (define r (engine-run fuel e))
      14 |   (if r (engine-result e) e))
      15 | 
      16 | (define-syntax-rule (define/timeout x e)
      17 |   (define x (run/timeout (lambda () e))))
      18 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/assert-star.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (lambda ()
       6 |   (assert (tuple ★)))
       7 | 
       8 | (lambda ()
       9 |   (spawn
      10 |     (react
      11 |       (assert (tuple ★))
      12 |       (on (asserted (tuple ★))
      13 |           #f))))
      14 | 
      15 | (typecheck-fail
      16 |  (spawn
      17 |    (react
      18 |      (assert (tuple ★))
      19 |      (on (asserted (tuple $x:Int))
      20 |          #f)))
      21 |  #:with-msg "Not prepared to handle inputs")
      22 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/basic-bad-assertion.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate
      2 | 
      3 | (require rackunit/turnstile)
      4 | 
      5 | (typecheck-fail (spawn #:type (U)
      6 |                        (start-facet x
      7 |                                     (assert 42))))
      8 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/bind-big-pattern.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (define-constructor* (go [t : Int] [w : String]))
       6 | 
       7 | (check-type
       8 |  (on (asserted ($ g (go 5 "home")))
       9 |      (add1 (go-t g))
      10 |      (string->symbol (go-w g)))
      11 |  : ★/t)
      12 | 
      13 | (check-type
      14 |  (on (message ($ g (go $t _)))
      15 |      (add1 (go-t g))
      16 |      (add1 t)
      17 |      (string->symbol (go-w g)))
      18 |  : ★/t)
      19 | 
      20 | (typecheck-fail (on (asserted ($ g (go $t _))) #f)
      21 |                 #:with-msg "Nested bindings only supported in message events")
      22 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/comm-ty-composition.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (assertion-struct ping : Ping (v))
       4 | (assertion-struct pong : Pong (v))
       5 | 
       6 | (assertion-struct flip : Flip (v))
       7 | (assertion-struct flop : Flop (v))
       8 | 
       9 | (define-type-alias Pinger (Ping Int))
      10 | (define-type-alias Ponger (U (Ping Int)
      11 |                              (Pong Int)
      12 |                              (Observe (Ping ★/t))))
      13 | (define-type-alias PingPong (U Pinger Ponger))
      14 | 
      15 | (define-type-alias Flipper (Flip Int))
      16 | (define-type-alias Flopper (U (Flip Int)
      17 |                               (Flop Int)
      18 |                               (Observe (Flip ★/t))))
      19 | (define-type-alias FlipFlop (U Flipper Flopper))
      20 | 
      21 | (run-ground-dataspace (U PingPong FlipFlop)
      22 |   (spawn #:type Pinger (start-facet _ (assert (ping 5))))
      23 |   (spawn #:type Ponger (start-facet _ (during (ping $v) (assert (pong v)))))
      24 | 
      25 |   (spawn #:type Flipper (start-facet _ (assert (flip 8))))
      26 |   (spawn #:type Flopper (start-facet _ (during (flip $v) (assert (flop v))))))
      27 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/constructor-naming-conventions.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (define-constructor* (trust lvl))
       6 | 
       7 | (check-type (trust 5) : (TrustT Int))
       8 | 
       9 | (define-constructor* (hungry-hippos count appetite)
      10 |   #:with HungryHippos (HungryHipposT Int String))
      11 | 
      12 | (check-type (hungry-hippos 12 "massive") : HungryHippos)
      13 | 
      14 | (define-constructor* (doggy [color : String] [weight : Int]))
      15 | 
      16 | (check-type (doggy "black" 60) : (DoggyT String Int))
      17 | (check-type (doggy "brown" 45) : Doggy)
      18 | 
      19 | (define-constructor* (leaf))
      20 | 
      21 | (check-type (leaf) : (LeafT))
      22 | (check-type (leaf) : Leaf)
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/constructor-some-default-tys.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (define-constructor* (session [id : Int] v))
       6 | 
       7 | (check-type (session 5 "hi")
       8 |             : (Session String))
       9 | 
      10 | (check-type (session "hi" 42)
      11 |             : (SessionT String Int))
      12 | 
      13 | (lambda ()
      14 |   (on (asserted (session $id ★))
      15 |       (add1 id)))
      16 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/define-dataflow.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (run-ground-dataspace (U)
       4 | (spawn #:type (U)
       5 |        (start-facet x
       6 |                     (field [y Int 0])
       7 |                     (define/dataflow x (add1 (ref y)))
       8 |                     (displayln (add1 (ref x)))
       9 |                     ;; print 2
      10 |                     #f))
      11 | )
      12 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/discard-pattern-tys.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define-constructor* (price [v : Int]))
       4 | 
       5 | (define (A)
       6 |   (spawn
       7 |     (react
       8 |       (during/spawn (price _)
       9 |         (on (asserted (price $v))
      10 |             #f)))))
      11 | 
      12 | (define (B)
      13 |   (spawn
      14 |     (react
      15 |       (during (observe (price ★))
      16 |         (assert (price (ann 5 Int)))))))
      17 | 
      18 | (define (C)
      19 |   (spawn
      20 |     (react
      21 |       (on (message (inbound (price _)))
      22 |           (react
      23 |             (on (message (inbound (price $v)))
      24 |                 #f))))))
      25 | 
      26 | (run-ground-dataspace
      27 |  (A)
      28 |  (B))
      29 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/effect-polymorhpism.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (define (∀ (ρ) (assert-something! [p : (proc → ★/t #:effects (ρ))]))
       6 |   (p))
       7 | 
       8 | (define (test-fun)
       9 |   (call/inst assert-something! (lambda () (assert 5))))
      10 | 
      11 | (check-type test-fun : (proc → ★/t #:effects ((Shares NonZero))))
      12 | 
      13 | (define (test-call/inst-insertion)
      14 |   (assert-something! (lambda () (assert 5))))
      15 | 
      16 | (check-type test-call/inst-insertion : (proc → ★/t #:effects ((Shares NonZero))))
      17 | 
      18 | (define (∀ (ρ) (start-something! [p : (proc → ★/t #:effects (ρ))]))
      19 |   (p))
      20 | 
      21 | (define (test-call-start-something)
      22 |   (start-something! (lambda () (start-facet x (assert 5)))))
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/endpoint-effects-branch.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate
      2 | 
      3 | (lambda ()
      4 |   (start-facet x
      5 |     (if #f
      6 |         (assert (tuple 0))
      7 |         (assert (tuple 1)))))
      8 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/floating-define.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | ;; TODO - currently fails with a racket error. Is that OK?
       6 | ;; (ideally, this would fail with a better error message)
       7 | (typecheck-fail
       8 |  (let ([x (define y 5)])
       9 |    (add1 1)))
      10 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/for-loop-regression.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (check-type (for/list ([x (for/list ([y (list 1 2 3)])
       6 |                             y)])
       7 |               x)
       8 |             : (List Int)
       9 |             ⇒ (list 1 2 3))
      10 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/hashes.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (check-type (hash) : (Hash (U) (U)))
       6 | 
       7 | (check-type (hash 1 2) : (Hash Int Int))
       8 | 
       9 | (check-type (hash "greetings" 8) : (Hash String Int))
      10 | 
      11 | (check-type (hash "smelly" 0
      12 |                   "feet" 18
      13 |                   "robust" 9)
      14 |             : (Hash String Int))
      15 | 
      16 | (check-type (hash "smelly" 0
      17 |                   "feet" "grosss"
      18 |                   "robust" #t)
      19 |             : (Hash String (U Int String Bool)))
      20 | 
      21 | (define a-hash
      22 |   (hash "smelly" 0
      23 |         "feet" 18
      24 |         "robust" 9))
      25 | 
      26 | (define hash-ref/inst (inst hash-ref String Int))
      27 | 
      28 | (check-type (hash-ref/inst a-hash "smelly")
      29 |             : Int
      30 |             ⇒ 0)
      31 | 
      32 | (check-type ((inst hash-count String Int) a-hash)
      33 |             : Int
      34 |             ⇒ 3)
      35 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/implicit-root-facet.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (lambda ()
       4 |   (spawn
       5 |     (on (asserted (tuple))
       6 |         #f)))
       7 | 
       8 | (lambda ()
       9 |   (spawn
      10 |     (field [v #t])
      11 |     (assert "hello")
      12 |     (on (asserted (tuple))
      13 |         #f)))
      14 | 
      15 | (lambda ()
      16 |   (spawn
      17 |     (field [v #t])
      18 |     (assert "hello")
      19 |     (on (asserted (tuple))
      20 |         #f)))
      21 | 
      22 | (lambda ()
      23 |   (spawn
      24 |     (on (asserted (tuple))
      25 |         (stop-current-facet))))
      26 | 
      27 | (lambda ()
      28 |   (spawn
      29 |     (stop-when (asserted (tuple)))))
      30 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/lift-facet-names.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define (start)
       4 |   (start-facet room
       5 |     #f))
       6 | 
       7 | (define (another)
       8 |   (start-facet
       9 |     (field [room #f])
      10 |     (assert (tuple (! room)))))
      11 | 
      12 | (module+ test
      13 |   (define-type-alias ROOM room))
      14 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/list.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (check-type (map add1 (list 1 2 3))
       6 |             : (List Int))
       7 | 
       8 | (typecheck-fail (map add1 (list (list 1 2 3))))
       9 | 
      10 | (check-type (map (inst first Int) (list (list 1 2 3)
      11 |                                         (list 4 5 6)))
      12 |             : (List Int))
      13 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/overly-broad-interests.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (typecheck-fail (spawn ⊥
       6 |                        (start-facet x
       7 |                                     (on (asserted $x:Int)
       8 |                                         #f)))
       9 |                 #:with-msg "overly broad interest")
      10 | 
      11 | (typecheck-fail (spawn ⊥
      12 |                        (start-facet x
      13 |                                     (on (asserted (observe $x:Int))
      14 |                                         #f)))
      15 |                 #:with-msg "overly broad interest")
      16 | 
      17 | ;; TODO - but this one seems fine?
      18 | (typecheck-fail (spawn ⊥
      19 |                  (start-facet x
      20 |                               (on (asserted _:⊥)
      21 |                                   #f)))
      22 |                 #:with-msg "overly broad interest")
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/pattern-annotations.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (define-type-alias τc
       6 |   (U (Tuple Int)
       7 |      (Observe (Tuple ★/t))))
       8 | 
       9 | ;; I actually think this is OK, since elaborating the pattern inserts a type
      10 | ;; that will still be checked by `project-safe?`
      11 | 
      12 | (lambda ()
      13 |   (spawn #:type τc
      14 |          (begin
      15 |            (define (on!)
      16 |              (on (asserted (tuple $x))
      17 |                  #f))
      18 |            (start-facet x
      19 |              (on!)))))
      20 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/phantom-rho.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | ;; make sure that we can look at the type of the facet without the ρ in it
       6 | (check-type
       7 |  (role-strings
       8 |    (start-facet x
       9 |      (define (push-results)
      10 |        (cond
      11 |          [(zero? 0)
      12 |           (start-facet done (assert #t))]
      13 |          [else
      14 |           #f]))
      15 |     (define (∀ (ρ) (perform-task [k : (proc -> ★/t #:roles (ρ))]))
      16 |         (start-facet perform
      17 |          (on start (stop perform (k)))))
      18 |     (on start (call/inst perform-task push-results))))
      19 |  : (List String)
      20 |  -> (list
      21 |      "(Role (x) (Reacts OnStart (Role (perform) (Reacts OnStart (Stop perform (Branch (Effs (Role (done) (Shares True))) (Effs)))))))"))
      22 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/primitives.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (check-type (or #f #t)
       6 |             : Bool
       7 |             ⇒ #t)
       8 | 
       9 | (check-type (and #t #f)
      10 |             : Bool
      11 |             ⇒ #f)
      12 | 
      13 | (check-type (or)
      14 |             : Bool
      15 |             ⇒ #f)
      16 | 
      17 | (check-type (and)
      18 |             : Bool
      19 |             ⇒ #t)
      20 | 
      21 | (check-type (or #f #f #f #f #f #t)
      22 |             : Bool
      23 |             ⇒ #t)
      24 | 
      25 | (check-type (and #t #t #t #t #t #f)
      26 |             : Bool
      27 |             ⇒ #f)
      28 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/regression-count-new-words.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (define-type-alias WordCount (Hash String Int))
       6 | 
       7 | (define (word-count-increment [h : WordCount]
       8 |                               [word : String]
       9 |                               -> WordCount)
      10 |   (hash-update/failure h
      11 |                        word
      12 |                        add1
      13 |                        0))
      14 | 
      15 | (define (count-new-words [word-count : WordCount]
      16 |                          [words : (List String)]
      17 |                          -> WordCount)
      18 |   (for/fold ([result word-count])
      19 |             ([word words])
      20 |     (word-count-increment result word)))
      21 | 
      22 | (check-type (count-new-words (hash) (list "hi" "bye"))
      23 |             : WordCount
      24 |             ⇒ (hash "bye" 1 "hi" 1))
      25 | 
      26 | ;; OG error:
      27 | ; /syndicate/typed/tests/regression-count-new-words.rkt:20.4: #%app: bad syntax
      28 | ;   in: (#%app word-count-increment result word)
      29 | 
      30 | ;; turns out I needed a #:cut in the rule for #%app (even tho it was the last
      31 | ;; syntax-parse case??)
      32 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/regression-define-with-effects.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (check-type
       6 |  (let ()
       7 |   (field [boo Int 0])
       8 |   (define x (begin (send! "hi") 5))
       9 |   ;; relying on `set` not allowing effects for this to be a good test
      10 |   (set! boo x)
      11 |   3)
      12 |  : Int)
      13 | 
      14 | ;; Used to get the error:
      15 | ; /syndicate/typed/tests/define-with-effects.rkt:10.2: set!: expression not allowed to have effects
      16 | ;   at: (set! boo x)
      17 | ;   in: (set! boo x)
      18 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/removing-annotations.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (define-constructor* (run [distance : Int] [windy? : Bool]))
       6 | 
       7 | (check-type
       8 |  (spawn
       9 |   (start-facet runner
      10 |     (assert (run 5 #t))))
      11 |  : ★/t)
      12 | 
      13 | (check-type
      14 |  (spawn
      15 |   (start-facet longer
      16 |     (on (asserted (run $d $w?))
      17 |         (printf "run ~a ~a\n" (add1 d) (if w? "brr" "")))))
      18 |  : ★/t)
      19 | 
      20 | (check-type
      21 |  (dataspace
      22 |   (spawn
      23 |    (start-facet runner
      24 |                 (assert (run 5 #t))))
      25 |   (spawn
      26 |    (start-facet longer
      27 |                 (on (asserted (run $d $w?))
      28 |                     (printf "run ~a ~a\n" (add1 d) (if w? "brr" ""))))))
      29 |  : ★/t)
      30 | 
      31 | (typecheck-fail
      32 |  (dataspace
      33 |   (spawn
      34 |    (start-facet runner
      35 |                 ;; NB
      36 |                 (assert (run "FAR" #t))))
      37 |   (spawn
      38 |    (start-facet longer
      39 |                 (on (asserted (run $d $w?))
      40 |                     (printf "run ~a ~a\n" (add1 d) (if w? "brr" ""))))))
      41 |  #:verb-msg "unprepared to handle inputs: (RunT String True)")
      42 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/require-struct-some-default-tys.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (require/typed "struct-provider.rkt"
       6 |   [#:struct donkey [weight : Int] grey?])
       7 | 
       8 | (check-type (donkey 5 #t)
       9 |             : (Donkey Bool))
      10 | 
      11 | (check-type (donkey "boo" #t)
      12 |             : (DonkeyT String Bool))
      13 | 
      14 | (check-type (donkey-grey? (donkey "boo" #t))
      15 |             : Bool)
      16 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/require-struct.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (require/typed "struct-provider.rkt"
       6 |   [#:struct donkey [weight : Int] [grey? : Bool]])
       7 | 
       8 | (check-type (donkey 5 #t)
       9 |             : (DonkeyT Int Bool))
      10 | 
      11 | (check-type (donkey 5 #t)
      12 |             : Donkey)
      13 | 
      14 | (check-type (donkey-grey? (donkey 5 #t))
      15 |             : Bool)
      16 | 
      17 | (require/typed "struct-provider.rkt"
      18 |   [#:struct pot])
      19 | 
      20 | (check-type (pot) : (PotT))
      21 | (check-type (pot) : Pot)
      22 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/require-typed.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate
      2 | 
      3 | (require/typed "untyped-lib.rkt"
      4 |   [#:struct chicken [eggs : Int]]
      5 |   [#:alias Chickens (List Chicken)]
      6 |   [#:struct roost [chickens : Chickens]])
      7 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/sequences.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (check-type empty-sequence : (Sequence (U)))
       6 | 
       7 | (check-type (sequence-length empty-sequence)
       8 |             : Int
       9 |             ⇒ 0)
      10 | 
      11 | (define sequence-length/Int (inst sequence-length Int))
      12 | (define sequence->list/Int (inst sequence->list Int))
      13 | (define in-list/Int (inst in-list Int))
      14 | 
      15 | (check-type (sequence->list/Int (in-list/Int (list 3 9 20)))
      16 |             : (List Int)
      17 |             ⇒ (list 3 9 20))
      18 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/sets.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (check-type (set 1 2 3)
       6 |             : (Set Int)
       7 |             -> (set 2 3 1))
       8 | (check-type (set 1 "hello" 3)
       9 |             : (Set (U Int String))
      10 |             -> (set "hello" 3 1))
      11 | (check-type (set-count (set 1 "hello" 3))
      12 |             : Int
      13 |             -> 3)
      14 | (check-type (set-union (set 1 2 3) (set "hello" "world"))
      15 |             : (Set (U Int String))
      16 |             -> (set 1 2 3 "hello" "world"))
      17 | (check-type (set-intersect (set 1 2 3) (set "hello" "world"))
      18 |             : (Set ⊥)
      19 |             -> (set))
      20 | (check-type (set-intersect (set 1 "hello" 3) (set #t "world" #f "hello"))
      21 |             : (Set String)
      22 |             -> (set "hello"))
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spawn-cell-bug.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define-constructor* (create-cell : CreateCellT id value))
       4 | 
       5 | (define-type-alias ds-type
       6 |   (U (Message (CreateCellT Symbol Int))
       7 |      (Observe (CreateCellT ★/t ★/t)))
       8 |   )
       9 | 
      10 | (define (spawn-cell-factory)
      11 |   (spawn ds-type
      12 |          (start-facet cell-factory
      13 |            (on (message (create-cell (bind id Symbol) (bind init Int)))
      14 |                (spawn ds-type
      15 |                       (react #f))))))
      16 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spawn-with-name.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (lambda ()
       6 |   (spawn #:name 'an-actor
       7 |          (react #f)))
       8 | 
       9 | (lambda ()
      10 |   (spawn #:name (list 'x 'y 'z)
      11 |          (react #f)))
      12 | 
      13 | (lambda ([x : Int])
      14 |   (spawn #:name (add1 x)
      15 |          (react #f)))
      16 | 
      17 | (typecheck-fail (spawn #:name (assert (tuple)))
      18 |                 #:with-msg "must be pure")
      19 | 
      20 | (lambda ()
      21 |   (during/spawn (tuple)
      22 |     #:name (list 'x 'y 'z)
      23 |     #f))
      24 | 
      25 | (lambda ()
      26 |   (during/spawn (tuple $x:Int)
      27 |     #:name (list x)
      28 |     #f))
      29 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spawn.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (check-type
       6 |   (spawn #:type (U (Tuple Int) (Observe (Tuple ★/t)))
       7 |    (start-facet _
       8 |      (on (asserted (tuple $x))
       9 |          (add1 x))))
      10 |   ;; wanted: ν-s ((Actor (Tuple Int)))
      11 |   : ★/t)
      12 | 
      13 | (typecheck-fail
      14 |  (spawn #:type (U (Tuple String) (Observe (Tuple ★/t)))
      15 |         (start-facet _
      16 |                      (on (asserted (tuple $x:Int))
      17 |                          (add1 x))))
      18 |  #:with-msg "Not prepared to handle inputs:\n\\(Tuple String\\)")
      19 | 
      20 | (check-type
      21 |  (spawn #:type (U)
      22 |         (start-facet _
      23 |                      (know (tuple 5))
      24 |                      (on (know (tuple $x:Int))
      25 |                          (add1 x))))
      26 |  ;; wanted: ν-s ((Actor (U)))
      27 |  : ★/t)
      28 | 
      29 | (typecheck-fail
      30 |  (spawn #:type (U)
      31 |         (start-facet _
      32 |                      (know (tuple "hi"))
      33 |                      (on (know (tuple $x:Int))
      34 |                          (add1 x))))
      35 |  #:with-msg "Not prepared to handle inputs:\n\\(Tuple String\\)")
      36 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/A-and-M-not-necessary.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define-constructor* (ping [v : Int]))
       4 | (define-constructor* (pong))
       5 | 
       6 | (define (spawn-asserter)
       7 |   (spawn
       8 |     (start-facet a
       9 |       (assert (ping 0)))))
      10 | 
      11 | (define (spawn-responder)
      12 |   (spawn
      13 |     (start-facet r
      14 |       (on (asserted (ping $x))
      15 |           (send! (pong))))))
      16 | 
      17 | (module+ test
      18 |   (verify-actors (Eventually (Message Pong))
      19 |     a
      20 |     r)
      21 | 
      22 |   (verify-actors (Eventually Ping)
      23 |     a
      24 |     r)
      25 | 
      26 |   (verify-actors/fail (Eventually (Message Pong))
      27 |     r))
      28 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/basic-assertion-communication.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define-constructor* (ping [v : Int]))
       4 | (define-constructor* (pong))
       5 | 
       6 | (define (spawn-asserter)
       7 |   (spawn
       8 |    (lift+define-role ar
       9 |    (start-facet a
      10 |      (assert (ping 0))))))
      11 | 
      12 | (define (spawn-responder)
      13 |   (spawn
      14 |    (lift+define-role rr
      15 |    (start-facet r
      16 |      (on (asserted (ping $x))
      17 |          (start-facet go
      18 |            (assert (pong))))))))
      19 | 
      20 | (module+ test
      21 |   (verify-actors (Eventually (A Pong))
      22 |                  ar
      23 |                  rr)
      24 | 
      25 |   (verify-actors/fail (Eventually (A Pong))
      26 |                       rr))
      27 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/basic-assertion.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define (spawn-asserter)
       4 |   (spawn
       5 |    (lift+define-role ar
       6 |    (start-facet a
       7 |      (assert (tuple 0))))))
       8 | 
       9 | (module+ test
      10 |   (verify-actors (Eventually (A (Tuple Int)))
      11 |                  ar)
      12 | 
      13 |   (verify-actors/fail (Not (Eventually (A (Tuple Int))))
      14 |                       ar)
      15 | 
      16 |   (verify-actors/fail (Always (A (Tuple Int)))
      17 |                       ar)
      18 | 
      19 |   (verify-actors (Eventually (Always (A (Tuple Int))))
      20 |                  ar))
      21 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/basic-io.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define-constructor* (go))
       4 | (define-constructor* (ack))
       5 | 
       6 | (define (spawn-reactor)
       7 |   (spawn
       8 |     (start-facet r
       9 |       (on (message (go))
      10 |           (react
      11 |             (assert (ack)))))))
      12 | 
      13 | (module+ test
      14 |   (verify-actors (Or (Always (Not (M Go)))
      15 |                      (Eventually (A Ack)))
      16 |     #:IO (Message Go)
      17 |     r)
      18 |   (verify-actors/fail (Always (Not (M Go)))
      19 |     #:IO (Message Go)
      20 |     r))
      21 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/cyclic-role-graph-regression.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define (spawn-post-factory)
       4 |   (spawn #:name 'post-factory
       5 |     (on (message ($ p0 (tuple $timestamp:Int)))
       6 |         (spawn #:name p0
       7 |           (field [items Int 0])
       8 |           ;; The problem was that this dataflow
       9 |           #;(define/dataflow p (tuple (! items)))
      10 |           ;; gave rise to an effect:
      11 |           ;; (Reacts OnDataflow (WritesField p) (ReadsField items))
      12 |           ;; and because Int is a union type, the below assertion becomes a var-assert, and the WritesField
      13 |           ;; effect becomes a Realize for the generated state machine, meaning the SPIN compiler can't ignore
      14 |           ;; that self-loop
      15 |           (assert (tuple (! items)))
      16 |           (on (message (tuple _:Int))
      17 |               (:= items 0))))))
      18 | 
      19 | (module+ test
      20 |   (verify-actors TT
      21 |     (spawn-post-factory)))
      22 | 
      23 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/deadlock-free-syntax-bug.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (module+ test
       6 |   ;; no interests, also only one output
       7 |   (check-deadlock-free* (Role (x) (Shares (Tuple))))
       8 |   ;; has an interest, but no IO
       9 |   (check-deadlock-free* (Role (x)
      10 |                               (Reacts (Asserted (Tuple)))
      11 |                               (Shares (Tuple)))))
      12 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/duplicate-facet-names-behavior-lost-regression.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define (spawn-A)
       4 |   (spawn
       5 |     (start-facet A
       6 |       (assert (tuple "hello"))
       7 |       (on-start
       8 |        (start-facet A
       9 |          (assert (tuple 'hello)))))))
      10 | 
      11 | (define (spawn-B)
      12 |   (spawn
      13 |     (during (tuple)
      14 |       (assert (tuple "hello"))
      15 |       (during (tuple "hello")
      16 |         (assert (tuple 'hello))))))
      17 | 
      18 | (module+ test
      19 |   (verify-actors (Eventually (And (Tuple String)
      20 |                                   (Tuple Symbol)))
      21 |     (spawn-A))
      22 | 
      23 |   (verify-actors (Eventually (And (Tuple String)
      24 |                                   (Tuple Symbol)))
      25 |     #:IO (Tuple)
      26 |     (spawn-B)))
      27 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/duplicate-facet-names-regression.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | ;; Previously, this would generate two `mtype = {roo}` declarations, which is illegal in SPIN
       4 | 
       5 | (define (spawn-A)
       6 |   (spawn (start-facet root #f)))
       7 | 
       8 | (define (spawn-B)
       9 |   (spawn (start-facet root (on-start (stop root)))))
      10 | 
      11 | (module+ test
      12 |   (verify-actors TT
      13 |     (spawn-A)
      14 |     (spawn-A))
      15 | 
      16 |   (verify-actors TT
      17 |     (spawn-B)
      18 |     (spawn-B)))
      19 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/during-spawn-stop-when.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define (A1)
       4 |   (spawn
       5 |     (start-facet a1
       6 |       (during/spawn (tuple)
       7 |         (stop-when (message (tuple 5))
       8 |                    (react (assert (tuple "hi"))))))))
       9 | 
      10 | (define (A2)
      11 |   (spawn
      12 |     (start-facet a2
      13 |       (assert (tuple))
      14 |       (on (asserted (observe (tuple 5)))
      15 |           (send! (tuple 5))))))
      16 | 
      17 | (module+ test
      18 |   (verify-actors (Eventually (A (Tuple String)))
      19 |     a1
      20 |     a2))
      21 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/io-subtype-regression.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate
      2 | 
      3 | (module+ test
      4 |   (verify-actors (Always (Implies (Tuple True) (Tuple Bool)))
      5 |     #:IO (Tuple Bool)
      6 |     (spawn (react #f))))
      7 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/message-subtyping-regression.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define (spawn-sender)
       4 |   (spawn
       5 |     (on (asserted (observe (tuple ★)))
       6 |         (send! (tuple #t)))))
       7 | 
       8 | (define (spawn-receiver)
       9 |   (spawn
      10 |     (on (message (tuple $b:Bool))
      11 |         (react
      12 |           (assert (tuple 0))))))
      13 | 
      14 | (module+ test
      15 |   (verify-actors (Eventually (Tuple Zero))
      16 |     (spawn-sender)
      17 |     (spawn-receiver)))
      18 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/no-behavior-regression.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | ;; Previously, this would generate an empty atomic block in the SPIN program for
       4 | ;; the initial actions, which is illegal syntax apparently
       5 | 
       6 | (define (spawn-A)
       7 |   (spawn (start-facet root #f)))
       8 | 
       9 | (module+ test
      10 |   (verify-actors TT
      11 |     (spawn-A)))
      12 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/spec-message-supertype-regression.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define (spawnA)
       4 |   (spawn
       5 |     (react
       6 |       (assert (tuple))
       7 |       (on (asserted (tuple))
       8 |           (send! (tuple 0))))))
       9 | 
      10 | (module+ test
      11 |   (verify-actors (Eventually (Tuple Int))
      12 |     (spawnA)))
      13 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/super-to-partial-subtype-regression.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define (booler)
       4 |   (spawn
       5 |     (assert (tuple (ann #t Bool)))))
       6 | 
       7 | (define (onT)
       8 |   (spawn
       9 |     (on (asserted (tuple #t))
      10 |         (react
      11 |           (assert (tuple "hello"))))))
      12 | 
      13 | (module+ test
      14 |   (verify-actors/fail (Eventually (Tuple String))
      15 |     (booler)
      16 |     (onT)))
      17 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/uninterested-retraction.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | ;; The point of this test is to show that the SPIN output captures the fact that
       4 | ;; A's event handler repeatedly fires, even though it doesn't explicitly pay
       5 | ;; attention to the retraction of (tuple) assertions.
       6 | 
       7 | (define (spawn-A)
       8 | (spawn
       9 |   (start-facet AA
      10 |       (on (asserted (tuple))
      11 |           (displayln 'got)
      12 |           (send! (tuple 1))))))
      13 | 
      14 | (define (spawn-B)
      15 |   (spawn
      16 |     (start-facet B
      17 |       (define (once)
      18 |         (start-facet xx
      19 |           (assert (tuple))
      20 |           (on (message (tuple 1))
      21 |               (stop xx)
      22 |               (displayln 'send)
      23 |               (send! (tuple "again")))))
      24 |       (on start (once))
      25 |       (on (message (tuple "again"))
      26 |           (once)))))
      27 | 
      28 | (module+ main
      29 |   (run-ground-dataspace
      30 |    (spawn-A)
      31 |    (spawn-B)
      32 |    (spawn
      33 |      (start-facet
      34 |          (on (retracted (tuple))
      35 |              (displayln 'gone))))))
      36 | 
      37 | (module+ test
      38 |   (verify-actors (Always (Eventually (M (Tuple NonZero))))
      39 |     AA
      40 |     B))
      41 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/use-type-of-expression.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define-constructor* (ping [v : Int]))
       4 | (define-constructor* (pong))
       5 | 
       6 | (define (spawn-asserter)
       7 |   (spawn
       8 |     (start-facet a
       9 |       (assert (ping 0)))))
      10 | 
      11 | (define (spawn-responder)
      12 |   (spawn
      13 |     (start-facet r
      14 |       (on (asserted (ping $x))
      15 |           (start-facet go
      16 |             (assert (pong)))))))
      17 | 
      18 | (module+ test
      19 |   (verify-actors (Eventually (A Pong))
      20 |     (spawn-asserter)
      21 |     (spawn-responder))
      22 | 
      23 |   (verify-actors/fail (Eventually (A Pong))
      24 |     (start-facet r
      25 |       (on (asserted (ping $x))
      26 |           (start-facet go
      27 |             (assert (pong)))))))
      28 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/var-assert-basic.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define (fut1)
       4 | (lift+define-role va1
       5 | (start-facet X
       6 |   (field [state Bool #t])
       7 |   (assert (tuple (! state))))))
       8 | 
       9 | (module+ test
      10 |   (verify-actors (Eventually (A (Tuple Bool)))
      11 |                  va1)
      12 |   )
      13 | 
      14 | (define-constructor* (go-true))
      15 | (define-constructor* (go-false))
      16 | 
      17 | (define (fut2)
      18 |   (lift+define-role va2
      19 |   (export-roles "va2.rktd"
      20 |   (print-role
      21 |   (start-facet X
      22 |     (field [state Bool #f])
      23 |     (assert (tuple (! state)))
      24 |     (on (message (go-true))
      25 |         (:= state #t))))))
      26 | 
      27 |   (lift+define-role gt
      28 |   (start-facet Y
      29 |     (on (asserted (tuple _))
      30 |         (send! (go-true))))))
      31 | 
      32 | (module+ test
      33 |   (verify-actors (Eventually (A (Tuple True)))
      34 |                  va2
      35 |                  gt)
      36 |   (verify-actors/fail (Always (Not (A (Tuple False))))
      37 |     va2
      38 |     gt))
      39 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/verify-actors-none-error-message.rkt:
      --------------------------------------------------------------------------------
      1 | #lang typed/syndicate
      2 | 
      3 | (require rackunit/turnstile)
      4 | 
      5 | (module+ test
      6 |   (typecheck-fail (verify-actors TT)
      7 |                   #:with-msg "verify-actors: expected more terms"))
      8 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/spin/webchat-performance-regression.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define-constructor* (invitation))
       4 | (define-constructor* (conversation))
       5 | (define-constructor* (permitted))
       6 | (define-constructor* (question [a : Bool] [b : Bool] [c : Bool] [d : Bool] [e : Bool] [f : Bool] [g : Bool] [h : Bool] [i : Bool]))
       7 | (define-constructor* (answer))
       8 | 
       9 | (define (spawnA)
      10 |   (spawn
      11 |     (during (invitation)
      12 |       (during (conversation)
      13 |         (during (permitted)
      14 |           (assert (question #t #t #t #t #t #t #t #t #t))
      15 |           (stop-when (asserted (answer))))))))
      16 | 
      17 | (define (spawnB)
      18 |   (spawn
      19 |     (assert (tuple))))
      20 | 
      21 | (module+ test
      22 |   (define-type-alias IO-types
      23 |     (U Invitation
      24 |        Conversation
      25 |        Permitted
      26 |        Question
      27 |        Answer))
      28 |   (define-ltl spec
      29 |     (Always (Implies (And (And Invitation Question (Not Answer))
      30 |                           (Until (And Invitation Question (Not Answer))
      31 |                                  (Not Invitation)))
      32 |                      (Eventually (Not Question)))))
      33 |   (verify-actors/fail spec
      34 |     #:IO IO-types
      35 |     (spawnA)))
      36 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/stop-when.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (lambda ()
       6 |   (start-facet boop
       7 |     (stop-when (message (tuple)))))
       8 | 
       9 | (lambda ()
      10 |   (start-facet boop
      11 |     (stop-when #:when #t
      12 |                (message (tuple))
      13 |                (+ 1 1))))
      14 | 
      15 | (lambda ()
      16 |   (react (stop-when (message (tuple)))))
      17 | 
      18 | (typecheck-fail (react
      19 |                   (define (f) (stop-when (message (tuple))))
      20 |                   #f))
      21 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/struct-provider.rkt:
      --------------------------------------------------------------------------------
       1 | #lang racket
       2 | 
       3 | (struct donkey (weight stubborn?) #:transparent)
       4 | 
       5 | (provide (struct-out donkey))
       6 | 
       7 | (struct pot () #:transparent)
       8 | 
       9 | (provide (struct-out pot))
      10 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/this-facet.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (lambda ()
       6 |   (react
       7 |     (on start
       8 |         (stop this-facet))))
       9 | 
      10 | (typecheck-fail this-facet
      11 |                 #:with-msg "use of this-facet outside of a facet")
      12 | (typecheck-fail (start-facet named
      13 |                   (lambda () (stop this-facet)))
      14 |                 #:with-msg "use of this-facet outside of a facet")
      15 | (typecheck-fail (stop-when #t)
      16 |                 #:with-msg "Not in a context with a known parent facet")
      17 | (lambda ()
      18 |   (during/spawn (tuple $x:Int)
      19 |     (displayln x)
      20 |     (stop-when (message (tuple)))))
      21 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/typed-gui-input-bug.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (define-constructor* (a [v : Int]))
       4 | (define-constructor* (b [v : Int]))
       5 | (define-type-alias AB (U A B))
       6 | (define-constructor* (m [v : AB]))
       7 | 
       8 | (define (s)
       9 |   (spawn
      10 |     (react
      11 |       (during/spawn (m _)
      12 |         (stop-when (asserted (observe (m (a ★)))))
      13 |         (on (asserted (m (a $v)))
      14 |             #f)))))
      15 | 
      16 | (define (t)
      17 |   (spawn
      18 |     (react
      19 |       (on-start
      20 |        (spawn
      21 |          (react
      22 |            (on (message (m _))
      23 |                #f))))
      24 |       (on (message (m $ab))
      25 |           #f))))
      26 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/untyped-lib.rkt:
      --------------------------------------------------------------------------------
      1 | #lang racket
      2 | 
      3 | (provide (struct-out chicken)
      4 |          (struct-out roost))
      5 | 
      6 | (struct chicken (eggs) #:transparent)
      7 | (struct roost (chickens) #:transparent)
      8 | 
      
      
      --------------------------------------------------------------------------------
      /racket/typed/tests/var-assert.rkt:
      --------------------------------------------------------------------------------
       1 | #lang typed/syndicate
       2 | 
       3 | (require rackunit/turnstile)
       4 | 
       5 | (check-type
       6 |  (role-strings
       7 |   (start-facet X
       8 |     (field [state Bool #t])
       9 |     (assert (tuple (! state)))))
      10 |   : (List String)
      11 |   -> (list "(Role (X) (VarAssert state (--> (U False True) (Tuple (U False True))) (--> False (Tuple False)) (--> True (Tuple True))) (MakesField state (U False True) True))"))
      12 | 
      13 | (define (spawn-B)
      14 |   (spawn
      15 |    (start-facet B
      16 |                 (field [Bst Bool #t])
      17 |                 (assert (tuple (! Bst))))))
      18 | 
      19 | (lambda ()
      20 |   (lift+define-role rA
      21 |   (start-facet A (on start (spawn-B))
      22 |     (field [Ast Bool #t])
      23 |     (assert (tuple (! Ast))))))
      24 | 
      
      
      --------------------------------------------------------------------------------