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
;;For http://stackoverflow.com/questions/24798831/clojure-increment-a-counter | |
(ns hack1 | |
;; (:use clojure.contrib.command-line) | |
) | |
(def collection-x ['({:customer_id "111", :product_id "222"}) | |
'({:customer_id "333", :product_id "444"}{:customer_id "555", :product_id "666"}{:customer_id "777", :product_id "888"})] ) |
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
// borrowed from https://blog.jcoglan.com/2011/03/11/promises-are-the-monad-of-asynchronous-programming/ | |
// also http://blog.jcoglan.com/2011/03/05/translation-from-haskell-to-javascript-of-selected-portions-of-the-best-introduction-to-monads-ive-ever-read/ | |
// and http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html | |
var pp = console.log | |
var f = function(x) { return x*3 } // a "Float" value | |
var g = function(x) { return x+10 } // a "Float" value | |
// http://en.wikipedia.org/wiki/Monad_(functional_programming)#Formal_definition | |
// turns monad type from type |
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
var pp = console.log | |
function Base(name) { | |
this.name = name || "unnamed" | |
} | |
Base.prototype.giveName= function() { | |
return "[["+ this.name +"]]" | |
} | |
function DataBase(name) { | |
Base.call(this,name); |
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
var fs = require("fs") | |
var path = require("path"); //extname, resolve | |
var pp= console.log | |
var FILEPATH = "/home/stephan/Music" | |
// verify with "ls ~/Music/ |wc -l" in one folder |
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 cons(x, y) { | |
return function(w) { return w(x, y) }; | |
}; | |
function car(z) { | |
return z(function(x, y) { return x }); | |
}; | |
function cdr(z) { | |
return z(function(x, y) { return 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
// with recursion: | |
var results = [1,1]; | |
function recufib(N) { | |
function getN() { | |
var a = results[results.length-2] | |
var b = results[results.length-1]; | |
if(!--N) { | |
return; |
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
var list_monad = {} | |
// a -> [a] | |
list_monad.unit = function (value) { | |
return [value] | |
} | |
// (a -> [a]) -> ([a] -> [a]) | |
list_monad.bind = function(fn) { | |
return function(values) { |
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
var pp = console.log | |
var Person = { name : "Frank Cadillac", | |
greet: function() { return "Hello world, my name is "+this.name+"!!!";} | |
} | |
// does not work! | |
// Person.prototype.getName = function(){ | |
// return this.name; | |
// } |
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
var Foo = function (name) { this.name = name; }; | |
Foo.prototype.data = [1, 2, 3]; // setting a non-primitive property | |
Foo.prototype.showData = function () { console.log(this.name, this.data); }; | |
var foo1 = new Foo("foo1"); | |
var foo2 = new Foo("foo2"); | |
// both instances use the same default value of data | |
foo1.showData(); // "foo1", [1, 2, 3] | |
foo2.showData(); // "foo2", [1, 2, 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
local function __define_class(base) | |
local __classmethods = {} -- define static/classmethods here.. | |
function __classmethods.new ( cls, ...) -- classmethod | |
local self = setmetatable({}, { __index = cls }) | |
if self.init then | |
self:init(...) | |
end | |
return self | |
end |
OlderNewer