This file contains hidden or 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(ex4_2). | |
-export([start/3, stop/0, server/1]). | |
start(M, N, Message) -> | |
register(first, spawn(?MODULE, server, [N-1])), | |
send(M, N, Message). | |
stop() -> | |
first ! stop, | |
ok. |
This file contains hidden or 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(ex3_10). | |
-export([format_pretty/2]). | |
format_pretty(Text, Width) -> do_format(Text, Width, Width). | |
do_format([], _, _) -> ok; | |
do_format([H | T], Width, 0) -> display_long_word([H | T], Width, []); | |
do_format(Text, Width, Request) -> | |
Len = length(Text), | |
if |
This file contains hidden or 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(ex3_10). | |
-export([format/2]). | |
format(Text, Width) -> do_format(Text, Width, Width). | |
do_format([], _, _) -> ok; | |
do_format(Text, _, Width) when length(Text) < Width -> io:format("~p~n", [Text]); | |
do_format([H | T], Width, 0) -> display_long_word([H | T], Width, []); | |
do_format(Text, Width, Request) -> | |
Len = length(Text), |
This file contains hidden or 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(ex3_9). | |
-export([convert_to_rawdoc/1, convert_raw/1, make_index/1, print/1]). | |
%%% convert a file into raw document | |
convert_to_rawdoc(File) -> | |
case file:open(File, [raw, {read_ahead, 1024}]) of | |
{error, Reason} -> | |
io:format("Error opening ~p: ~p~n", [File, Reason]); | |
{ok, Handle} -> | |
do_read(Handle, []) |
This file contains hidden or 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
%%% restrict: can only handle numbers from 0~9 | |
-module(ec). | |
-export([parser/1, eval/1, print/1, compile/1, simulate/1, simplify/1]). | |
parser(List) -> do_parse(List, [], []). | |
do_parse([], _, [Output]) -> Output; | |
do_parse(List, Stack, Output) -> | |
Last = lists:last(List), | |
Len = length(List), |
This file contains hidden or 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
# cat a.c | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
#include "zmalloc.h" | |
void *worker(void *arg) { | |
int j; | |
char *p; |