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
import Data.Maybe | |
import Data.List | |
import Control.Monad | |
type State = Int | |
data TransitionKey a = Epsilon | Key a | Other | Wildcard deriving (Eq, Show) | |
type Transition a = (State, (TransitionKey a, TransitionKey a)) |
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
%%% Monad.oz --- A synax that resembles Haskell's do notation for monads. | |
%% NB: The macros need to be evaluated before the examples can be run | |
declare Maybe Reader State Seq in | |
fun {Seq Monad A B} | |
{Monad.bind A fun {$ _} B end} | |
end | |
%% Syntax: return X |
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
def ap(*args, &block) | |
lambda do |recv, *new_args, &new_block| | |
recv.send(*(args + new_args), &(block || new_block)) | |
end | |
end | |
class Object | |
def try_it(*arguments, &block) | |
puts "Called try_it on #{inspect} with #{arguments.inspect} and " + | |
"block: #{block.inspect}" |
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
test_data = <<eof | |
do not match this line | |
match this as event 1 | |
and this a as 1 | |
and this b as 1 | |
do not match this line | |
match this as event 2 | |
and this x as 2 | |
and this y as 2 | |
and this z as 2 |
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
(defun indent-buffer () | |
(interactive) | |
(indent-region (point-min) (point-max))) | |
(defun indent-region-or-buffer () | |
(interactive) | |
(if (use-region-p) (indent-region (region-beginning) (region-end)) | |
(indent-buffer))) | |
(global-set-key (kbd "C-M-/") 'indent-region-or-buffer) |
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
class Foo | |
def initialize(n) | |
@n = n | |
end | |
attr_reader :n | |
def abracadabra_alakazam(x) | |
Foo.new(n + x.n) | |
end |
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
(defun indent-buffer () | |
(interactive) | |
(indent-region (point-min) (point-max))) | |
(defun indent-region-or-buffer () | |
(interactive) | |
(if (use-region-p) (indent-region (region-beginning) (region-end)) | |
(indent-buffer))) |
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
class Array | |
def merge_sort(&block) | |
return self if size < 2 | |
block ||= lambda { |a, b| a <=> b } | |
half_size = size / 2 | |
first_ary = self[0, half_size].merge_sort(&block) | |
second_ary = self[half_size, size].merge_sort(&block) |
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
(defun tmp-function (argument) | |
(interactive (list (read-string "enter: " "default"))) | |
(message "the argument was %s" argument)) |
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
class Module | |
def around_module | |
unless defined? @around_module | |
prepend (@around_module = Module.new) | |
end | |
@around_module | |
end | |
def around(&block) |