This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const t = require("tcomb"); | |
// imstruct is a tcomb type builder that internally builds an | |
// Immutable.Record object, but applies tcomb's type system to it | |
const imstruct = require("../util/imstruct"); | |
const Person = imstruct({ | |
name: t.String, | |
age: t.Number | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function: | |
function foo() { | |
var x = 5; | |
var y = 6; | |
debugger; | |
return x + y; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (foo) | |
(let ([a 1] | |
[c (call/cc | |
(lambda (cont) (cont cont)))]) | |
(if c | |
(begin | |
(display "setting a = 2\n") | |
(set! a 2) | |
(c #f))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example code, see below for run/yield implementation. Note how we | |
// can even do yields across the stack, so this implements something | |
// more like coroutines than generators. | |
function foo() { | |
var x = Yield(); | |
return x + 1; | |
} | |
var process = Run(function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example code, see try/catch/throw implementation below | |
function bar(x) { | |
if(x < 0) { | |
Throw(new Error("error!")); | |
} | |
return x * 2; | |
} | |
function foo(x) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bar(func) { | |
console.log('bar entered'); | |
func(5); | |
console.log('bar exiting'); | |
} | |
function foo() { | |
var x = callCC(function(cont) { | |
console.log('calling bar'); | |
bar(cont); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (test start) | |
(let-values | |
([(c v x) (call/cc | |
(lambda (cont) | |
(cont cont 0 start)))]) | |
(if (> x 0) | |
(c c (+ v x) (- x 1)) | |
v))) | |
(display (test 3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns state_bug.core | |
(:require [om.next :as om :refer-macros [defui ui]] | |
[om.next :as om] | |
[om.dom :as dom] | |
[goog.dom :as gdom])) | |
(enable-console-print!) | |
(defui C | |
static om/IQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Let's say you have 2 tables, transactions and accounts, | |
;; created with the following schema. Essentially, `transactions` | |
;; has 2 foreign keys into the `accounts` table: | |
;; | |
;; CREATE TABLE accounts | |
;; (id INTEGER PRIMARY KEY, | |
;; name TEXT NOT NULL, | |
;; balance INTEGER); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn read [{:keys [state ast]} key params] | |
(println "called") | |
{:value (get @state key :not-found)}) | |
((om/parser {:read read}) {:state (atom {})} '[:foo]) | |
;; output: | |
;; called |