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
func sample_usage() { | |
digits := "0123456789abcdefghijklmnopqrstuvwxyz" // base 36 | |
var num int64 = 9876543210 | |
fmt.Printf("input number is %d\n", num) | |
e := encode(num, digits) | |
fmt.Printf("encoded as %v\n", e) | |
d := decode(e, digits) | |
fmt.Printf("decoded as %v\n", d) | |
} |
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(server4). | |
-export([start/2, rpc/2, swap_code/2]). | |
start(Name, Mod) -> | |
register(Name, spawn(fun() -> loop(Name,Mod,Mod:init()) end)). | |
swap_code(Name, Mod) -> rpc(Name, {swap_code, Mod}). | |
rpc(Name, Request) -> | |
Name ! {self(), Request}, |
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(name_server1). | |
-export([init/0, add/2, find/1, handle/2]). | |
-import(server3, [rpc/2]). | |
%% client routines | |
add(Name, Place) -> rpc(name_server, {add, Name, Place}). | |
find(Name) -> rpc(name_server, {find, Name}). | |
%% callback routines | |
init() -> dict:new(). |
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(server3). | |
-export([start/2, rpc/2, swap_code/2]). | |
start(Name, Mod) -> | |
register(Name, | |
spawn(fun() -> loop(Name,Mod,Mod:init()) end)). | |
swap_code(Name, Mod) -> rpc(Name, {swap_code, Mod}). | |
rpc(Name, Request) -> |
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(server2). | |
-export([start/2, rpc/2]). | |
start(Name, Mod) -> | |
register(Name, spawn(fun() -> loop(Name,Mod,Mod:init()) end)). | |
rpc(Name, Request) -> | |
Name ! {self(), Request}, | |
receive | |
{Name, crash} -> exit(rpc); |
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(name_server). | |
-export([init/0, add/2, find/1, handle/2]). | |
-import(server1, [rpc/2]). | |
%% client routines | |
add(Name, Place) -> rpc(name_server, {add, Name, Place}). | |
find(Name) -> rpc(name_server, {find, Name}). | |
%% callback routines | |
init() -> dict:new(). |
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(server1). | |
-export([start/2, rpc/2]). | |
start(Name, Mod) -> | |
register(Name, spawn(fun() -> loop(Name, Mod, Mod:init()) end)). | |
rpc(Name, Request) -> | |
Name ! {self(), Request}, | |
receive | |
{Name, Response} -> Response |
NewerOlder