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
class LazyList { | |
private Closure list | |
private LazyList(list) { | |
this.list = list | |
} | |
static LazyList nil() { | |
new LazyList( {-> []} ) |
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(generic_server). | |
-export([start/0, loop/2]). | |
-export([request/1, change_state/1, change_function/1]). | |
%% Server | |
start() -> | |
register(?MODULE, spawn(?MODULE, loop, [2, fun erlang:'+'/2])). |
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(ring). | |
-export([start/3]). | |
-export([loop/1, loop/2]). | |
start(N, M, Message) when N > 1 -> spawn(fun() -> ring(N-1, M, Message) end). | |
ring(N, M, Message) when M > 0 -> | |
P = lists:foldl(fun(_, Proc) -> spawn(fun() -> loop(Proc) end) end, self(), lists:seq(1, N)), |
NewerOlder