Skip to content

Instantly share code, notes, and snippets.

let fibonacci n =
let rec fib_cps n cont =
match n with
| 0 -> (cont 0) // <-- even the base cases need to keep the promise
| 1 -> (cont 1)
| _ -> (fib_cps (n-1) (fun a -> fib_cps (n-2) (fun b -> cont(a+b)) ) )
fib_cps n (fun x -> x) // <- this anon function is our base continuation
let fibonacci n =
let rec loop current a b =
if current == n
then a + b
else loop (current+1) b (a+b)
match n with
| 0 -> 0
| 1 -> 1
| _ -> loop 2 0 1
let rec fibonacci n =
match n with
| 0 -> 0
| 1 -> 1
| _ -> (fibonacci (n-1)) + (fibonacci (n-2))
require 'rubygems'
require 'spec'
require 'spec/autorun'
@watches = []
def watch(matcher, &block)
@watches << Matcher.new(matcher, &block)
end
def do_a_loop(sender, arg)
puts "found a #{arg.change_type} with #{arg.name}"
type expression =
| Empty
| Number of int
let expression stream =
match stream with
| [] -> Empty, stream
| h::t -> Number( Int32.Parse(h)), t
let evaluate expr =
match expr with
| Empty -> 0
class DisposableHero
include System::IDisposable
attr :name
def initialize(name = "Jed")
@name = name
end
def do_something_to(other)
puts "#{@name} washes a car for #{other.name}"
end
def do_something
@Ball
Ball / using_commands.rb
Created August 24, 2009 13:25
Command Example
require 'xamltools.rb'
class MyCommand
include System::Windows::Input::ICommand
def add_CanExecuteChanged(h)
@change_handlers << h
end
def remove_CanExecuteChanged(h)
@change_handlers.remove(h)
end
@Ball
Ball / bind_example.rb
Created August 22, 2009 16:07
Binding Example
require 'xamltools.rb'
require 'PresentationFramework'
class ViewModel
attr :greeting, true
def initialize(greet)
@greeting = greet
end
end
@Ball
Ball / xamltools.rb
Created August 22, 2009 16:06
XamlTools
require 'rubygems'
require 'builder'
require 'PresentationCore'
require 'PresentationFramework'
require 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeytoken=b77a5c561934e089'
module XamlTools
include System::Windows
StringReader = System::IO::StringReader;
XamlReader = System::Windows::Markup::XamlReader
@Ball
Ball / xamlbuilder.rb
Created August 15, 2009 17:20
With Xaml
require 'rubygems'
require 'builder'
require 'PresentationCore'
require 'PresentationFramework'
require 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeytoken=b77a5c561934e089'
include System::Windows
StringReader = System::IO::StringReader;
XamlReader = System::Windows::Markup::XamlReader
XmlReader = System::Xml::XmlReader;