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
#!/usr/bin/escript | |
-module(options). | |
% main/1 calls main/3 with default values | |
main(Args) -> main(false, "", Args). | |
main(_, _, ["-h" | _ ] ) -> io:format("Help text...~n"); % help | |
main(_, Value, ["-f" | Args ] ) -> main(true, Value, Args); % set flag | |
main(Flag, _, ["-v", Value | Args ] ) -> main(Flag, Value, Args); % set value |
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
-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. |
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
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 |
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
-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. |
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
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 |
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 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) |
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
-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 -> |
NewerOlder