Skip to content

Instantly share code, notes, and snippets.

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))
%%% 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
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}"
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
(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)
class Foo
def initialize(n)
@n = n
end
attr_reader :n
def abracadabra_alakazam(x)
Foo.new(n + x.n)
end
(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)))
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)
(defun tmp-function (argument)
(interactive (list (read-string "enter: " "default")))
(message "the argument was %s" argument))
class Module
def around_module
unless defined? @around_module
prepend (@around_module = Module.new)
end
@around_module
end
def around(&block)