This is the preamble.
Table of Contents
This is the preamble.
-module(countdown). | |
-export([init/0, reload/0]). | |
-export([tick/1]). % so we can spawn this properly. | |
%% spawn a countdown process with a default start time of 10 seconds. | |
init() -> init(10). | |
init(Time) -> | |
register(ticker, spawn(?MODULE, tick, [Time])). | |
tick(Time) when Time >= 0 -> |
build_nodes(Parent, Group, []) -> Parent ! {Group, []}; | |
build_nodes(Parent, Group, Lines) -> | |
[First|Rest] = Lines, | |
%% split off our children from the rest of the Lines. | |
%% the first line with an indent =< ours is a sibling, not a child | |
Criterion = fun(X) -> X#line.indent =< First#line.indent end, | |
[ChildLines, SiblingLines] = split_list(Criterion, Rest), | |
spawn(?MODULE, build_nodes, [self(), children, ChildLines]), | |
spawn(?MODULE, build_nodes, [self(), siblings, SiblingLines]), | |
receive |
(defun parse-text-line (line) | |
;; converts " text" to (:content "text" :indent 4) | |
(let ((content (string-left-trim '(#\Space #\Tab) line))) | |
(list :content content :indent (- (length line) (length content))))) | |
(defun split-list (criterion data-list) | |
;; break a list into two lists; the second begins with the first element that matches the criterion. | |
(if data-list | |
(if (funcall criterion (first data-list)) | |
(list () data-list) |
-record(line, {content, indent}). | |
-record(node, {content, children}). | |
parse_text_line(Text) -> | |
%% converts " text" to (:content "text" :indent 4) | |
Content = string:strip(string:strip(Text, left), left, $\t), | |
Indent = length(Text) - length(Content), | |
#line{content=string:strip(Content, right, $\n), indent=Indent}. | |
%% Split a list of lines in two, breaking on the first line whose indent is =< the minimum. |
set nocompatible | |
" Don't use Ex mode, use Q for formatting | |
map Q gq | |
" Switch syntax highlighting on, when the terminal has colors | |
" Also switch on highlighting the last used search pattern. | |
if &t_Co > 2 || has("gui_running") | |
syntax on | |
set hlsearch | |
endif |
-module(game). | |
-export([score/1]). | |
score(Rolls) -> frame(1, 0, Rolls). | |
%% frame/3 takes Frame #, Score accumulator, and list of remaining Rolls. | |
%% It tail-recurses to the next frame with an updated Score and Rolls list. | |
%% Game complete. |
#!/bin/bash | |
# Update current SVN directory, creating diff & log files from previous version. | |
# For seeing what the rest of your team did. | |
last_rev=$(svn info | grep "^Revision: ") | |
last_rev=${last_rev#Revision: } | |
echo "Updating from $last_rev..." | |
svn up |
-module(hello_world). | |
-behaviour(spooky). | |
-export([init/1, get/2, loop/1]). | |
init([])-> | |
%% register a process that holds our dict in memory | |
case whereis(store) of | |
undefined -> | |
Pid = spawn(?MODULE, loop, [dict:new()]), | |
register(store, Pid), |
-module(pubsub). | |
-export([handle/0, server/0]). | |
server() -> | |
register(ps, handle()). | |
%% handle/0 | |
handle() -> | |
spawn(fun () -> handle([]) end). |