Name: Anonymous 2009-09-07 11:18
Let's reimplement ed with modern languages!
10 INPUT
20 PRINT "?"
30 GOTO 10
10 INPUT
20 PRINT "?"
30 GOTO 10
#include <stdio.h>
int main(void)
{
while (getchar() != EOF) {
printf("?\n");
}
return 0;
}
import Control.Monad
main = do getLine >>= (\p -> when (p `compare` "q" /= EQ) $ putStrLn "?" >> main)
/* Anonix ed - public domain */
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void int_handler(int);
void hup_handler(int);
char *prompt = "";
int main(int argc, char **argv){
char line[LINE_MAX];
int c;
while((c = getopt(argc, argv, "p:s")) != -1)
switch(c){
case 'p':
prompt = optarg;
break;
case 's':
break;
case '?':
printf("Usage: %s [-p string] [-s] [file]\n", argv[0]);
return EXIT_FAILURE;
default:
abort();
}
signal(SIGINT, &int_handler);
signal(SIGHUP, &hup_handler);
signal(SIGQUIT, SIG_IGN);
for(
fputs(prompt, stdout) && fflush(stdout);
fgets(line, LINE_MAX, stdin) && strcasecmp(line, "q\n");
printf("?\n%s", prompt) && fflush(stdout));
return 0;
}
void int_handler(int n){
fpurge(stdin);
printf("\n?\n%s", prompt);
fflush(stdout);
}
void hup_handler(int n){
_Exit(0);
}
(loop (read-line) (princ "?"))
(loop (read-line) (format t "?~&"))
print "hello world"'' (Thanks, Wikipedia. I really appreciate you).
-module(example).
-export([main/0]).
main() ->
io:format("Hello world!~n").
-module(hello).
-export([main/0, printer/1, worker/1]).
-define(NWORKERS, 8).
main() ->
PID = spawn(?MODULE, printer, ["hello world" ++ [10]]),
% ?MODULE is a macro which expands to the name of the current module
lists:foreach(fun(_) -> spawn(?MODULE, worker, [PID]) end, lists:seq(1, ?NWORKERS)),
ok.
printer([]) -> ok;
printer([C | String]) ->
receive
{give_me_a_char, PID} ->
PID ! {'here you go', C},
receive {thanks, PID} -> ok end
end,
printer(String).
worker(PID) ->
PID ! {'give_me_a_char', self()},
receive
{'here you go', C} ->
io:format("~c", [C]),
PID ! {'thanks', self()},
worker(PID)
after
1000 -> timeout
end.print "?\n" while(<>)