This file contains hidden or 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
Object.extend(Number.prototype, ( | |
function() { | |
function succ() { | |
return this + 1; | |
} | |
function times(iterator, context) { | |
$R(0, this, true).each(iterator, context); | |
return this; | |
} | |
// shortened to fit on this slide! |
This file contains hidden or 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
// Part 1. | |
// Implement a function prototype extension that caches function results for | |
// the same input arguments of a function with one parameter. | |
// | |
// For example: | |
// Make sin(1) have the result of Math.sin(1), but use a cached value | |
// for future calls. | |
// | |
// Part 2. | |
// Use this new function to refactor the code example. |
This file contains hidden or 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
<script> | |
var Person = function(name) { | |
this.name = name; | |
this.getName = function() { | |
return this.name; | |
}; | |
} | |
var thomas = new Person('Thomas'); | |
var amy = new Person('Amy'); |
This file contains hidden or 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
<script> | |
// Part 1 | |
// Implement a function prototype extension that caches function results for | |
// the same input arguments of a function with one parameter. | |
Function.prototype.withCaching = function withCaching() { | |
if (!this.cache) { this.cache = {}; } | |
var method = this; | |
return function(input) { | |
if (typeof method.cache[input] == "undefined") { |
This file contains hidden or 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
-module(ring). | |
-export([clasp/0,shackle/1,send/1]). | |
clasp() -> | |
spawn(fun() -> loop([]) end). | |
shackle(Pid) -> | |
spawn(fun() -> loop(Pid) end). | |
send(Pid) -> |
This file contains hidden or 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
-module(circle). | |
-export([start/1]). | |
start(Msg) -> | |
CPid = clasp(), | |
Pid1 = shackle(CPid, CPid), | |
Pid2 = shackle(Pid1, CPid), | |
Pid3 = shackle(Pid2, CPid), | |
send(Pid3,Msg). |
This file contains hidden or 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
-module(ring2). | |
-export([start/1]). | |
start(Msg) -> | |
Pid1 = ring(), | |
Pid2 = ring(), | |
Pid3 = ring(), | |
Pid4 = ring(), | |
shackle(Pid1, Pid2), | |
shackle(Pid2, Pid3), |
This file contains hidden or 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
-module(ring2). | |
-export([start/2]). | |
start(Msg,Max) -> | |
Pid1 = clasp(Max), | |
Pid2 = ring(), | |
Pid3 = ring(), | |
Pid4 = ring(), | |
shackle(Pid1, Pid2), | |
shackle(Pid2, Pid3), |
This file contains hidden or 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
-module(ring2). | |
-export([start/2]). | |
start(Msg,Max) -> | |
Head = clasp(Max), | |
shackle(shackle(shackle(shackle(Head))), Head), | |
send(Head, Msg). | |
shackle(LPid) -> | |
RPid = ring(), |
This file contains hidden or 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
-module(ring2). | |
-export([start/3]). | |
start(Msg,Count,Max) -> | |
Head = clasp(Max), | |
connect(Head, Count), | |
send(Head, Msg). | |
shackle(LPid, Count) when Count > 1 -> | |
RPid = spawn(fun() -> loop(0,-1) end), |
OlderNewer