Skip to content

Instantly share code, notes, and snippets.

@willconant
willconant / readable-s-expressions
Last active December 11, 2015 02:58
Here's a simple idea for more readable s-expressions.
Imagine that you have lisp envy, but your brain can't quite handle all
the parentheses. Here's my idea for more readable s-expressions.
When you begin parsing, you start in terminator mode. In terminator
mode, an expression is a series of space separated expressions
terminated by a newline or semicolon:
print "hello"
eat "tomatoes"
clean "dishes"
@willconant
willconant / fiber.js
Created November 14, 2011 17:23
Tim Caswell's Fiber idea implemented with Mozilla Javascript 1.7 generators
/* in this case, there is no explicit wait() function, instead, fiberized functions use the yield keyword */
module.exports = function(generatorFunction) {
var iterator;
function resume() {
iterator.send(arguments);
}
iterator = generatorFunction(resume);
iterator.next();
};
@willconant
willconant / fiber.js
Created November 8, 2011 23:55
Tim Caswell's Fiber idea prototyped with Marcel Laverdet's node-fibers
require('fibers');
module.exports = function(fn) {
Fiber(function() {
var fiber = Fiber.current;
var wait = yield;
var resume = function() {
fiber.run(arguments);
};
fn(resume, wait);
// saves local changes to articles. mergeParentGuid should be null unless we are resolving a merge conflict
function editArticle(articleName, content, mergeParentGuid, callback) {
flow.exec(
function() {
// find my current head for this article
db.sync.findLastLocal("articleHeads", {name: articleName}, this)
},function(err, articleHead) {
if (err) throw err
@willconant
willconant / flow-serial-sum-2.js
Created March 11, 2010 20:46
Flow-JS Serial Sum Example 2
var sys = require('sys');
var flow = require('./flow')
// this is a simple async function for adding an amount to a running total
var currentSum = 0;
function addToSum(amountToAdd, callback) {
setTimeout(function() {
currentSum += amountToAdd;
callback();
}, 100);
@willconant
willconant / flow-serial-sum.js
Created March 11, 2010 20:19
Flow-JS Serial Sum Example 1
var sys = require('sys');
var flow = require('./flow')
// this is a simple async function for adding an amount to a running total
var currentSum = 0;
function addToSum(amountToAdd, callback) {
setTimeout(function() {
currentSum += amountToAdd;
callback();
}, 100);