Skip to content

Instantly share code, notes, and snippets.

@pheuter
pheuter / Merge.factor
Created November 30, 2010 23:12
Factor implementation of merge assignment
! With local bindings (7 loc)
: merge ( x y z -- z )
[| a b c | a b c a length 0 > b length 0 > and ]
[| a b c | a b c 0 a nth 0 b nth over over <
[| a b c x y | 0 a remove-nth b c x over push ]
[| a b c x y | a 0 b remove-nth c y over push ] if ]
while
[| a b c | a b c b length 0 = [| a b c | c a append ] [| a b c | c b append ] if ] call ;
.LC0:
.string "%d"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
@pheuter
pheuter / wc.js
Created January 4, 2011 05:19
Wordcount bookmarklet
document.body.appendChild(document.createElement('script')).src='http://code.jquery.com/jquery-1.4.3.min.js';
setTimeout(function () {
$("textarea").after(function () {
return "<p style='color:blue;'>Word count: <b>"+$(this).val().split(/\s+/).length+"</b></p>"
});
wc = function(ta) { ta.siblings().html('Word count: <b>'+ta.val().split(/\s+/).length+'</b>'); };
$("textarea").keypress(function() {
wc($(this));
}
def add(x,y)
x+y
end
add(2,3)
[:defn,
:add,
[:args, :x, :y],
[:call, [:lvar, :x], :+, [:arglist, [:lvar, :y]]]]
[:call, :add, [:arglist, [:lit, 2], [:lit, 3]]]
λfx.f x
λx.x
λy.y
λx.x y
λy.y y
λx.λy.x y (a b)
a b