Skip to content

Instantly share code, notes, and snippets.

View GeertVL-zz's full-sized avatar
💭
Working full time in Azure technologies

Geert Van Laethem GeertVL-zz

💭
Working full time in Azure technologies
View GitHub Profile
@GeertVL-zz
GeertVL-zz / gist:3037945
Created July 3, 2012 05:49
Erlang 8.11.2
-module(ring).
-export([clasp/0,shackle/1,send/1]).
clasp() ->
spawn(fun() -> loop([]) end).
shackle(Pid) ->
spawn(fun() -> loop(Pid) end).
send(Pid) ->
<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") {
<script>
var Person = function(name) {
this.name = name;
this.getName = function() {
return this.name;
};
}
var thomas = new Person('Thomas');
var amy = new Person('Amy');
// 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.
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!