Skip to content

Instantly share code, notes, and snippets.

View jlongster's full-sized avatar
💭
Workin on my app

James Long jlongster

💭
Workin on my app
View GitHub Profile
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 function:
function foo() {
var x = 5;
var y = 6;
debugger;
return x + y;
}
(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)))
// 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() {
// Example code, see try/catch/throw implementation below
function bar(x) {
if(x < 0) {
Throw(new Error("error!"));
}
return x * 2;
}
function foo(x) {
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);
(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))
(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
;; 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);
(defn read [{:keys [state ast]} key params]
(println "called")
{:value (get @state key :not-found)})
((om/parser {:read read}) {:state (atom {})} '[:foo])
;; output:
;; called