Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

ed reimplementation contest

Name: Anonymous 2009-09-07 11:18

Let's reimplement ed with modern languages!

10 INPUT
20 PRINT "?"
30 GOTO 10

Name: Anonymous 2009-09-07 11:20

inb4 Enterprise Ed in C#

Name: Anonymous 2009-09-07 11:38

Something about Haskell's [coe]interact[/code].

Name: Anonymous 2009-09-07 12:01

#include <stdio.h>

int main(void)
{
  while (getchar() != EOF) {
    printf("?\n");
  }

  return 0;
}

Name: Anonymous 2009-09-07 12:02

>>1
Nice try Cudder

Name: Anonymous 2009-09-07 12:11

import Control.Monad
main = do getLine >>= (\p -> when (p `compare` "q" /= EQ) $ putStrLn "?" >> main)

Name: Anonymous 2009-09-07 12:13

>>6
Ooops, you can drop the first do. I'm new to HASKAL, forgive me. :(

Name: Anonymous 2009-09-07 12:20

>>7
NO EXCEPTIONS

ed  R *a  W "?",!  G ed

Name: Anonymous 2009-09-08 11:08

Where's the ENTERPRISE C# or Java version?

Name: Anonymous 2009-09-08 12:05

[span]how?[/span]

Name: Anonymous 2009-09-08 12:24

>>5
/* 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);
}

Name: Anonymous 2009-10-30 8:26

[code]public class Ed {
  public static void main(String[] args) {
    while (true) {
      System.in.read();
      System.out.println("\n?");
    }
  }
}

Name: Anonymous 2009-10-30 9:52

(define (ed) ((read)
              (display '?) (newline)
              (ed)))

Name: Anonymous 2009-10-30 10:35

>>11
using strcasecmp

Name: Anonymous 2009-10-30 10:56

(loop (read-line) (princ "?"))

Name: Anonymous 2009-10-30 15:07

Yeah, I thought about doing that once.

(defpackage #:led
  (:use common-lisp)
  (:export start))

(in-package #:led)

(defvar *edit-functions*)
(defvar *buffer*)
(defvar *dot-l* 0)
(defvar *dot-r* 0)

(defun start (&optional (init-dot '(0 . 0)))
  (setf *edit-functions*
    (list (cons "o" #'open-phrase)
          (cons "!" #'(lambda ()
                (eval (read))
                (wait-for-input)))
          (cons "q" #'quit-editor)))
  (setf *dot-l* (car init-dot)
        *dot-r* (cdr init-dot))
  (setf *buffer* "Here is some default text for testing.")
  (wait-for-input))

(defun wait-for-input ()
  (let ((called-function (assoc (read-line
                 *edit-functions*
                 :test #'string=)))
    (if called-function (funcall (cdr called-function))
        (progn (format t "? ")
           (finish-output)
           (wait-for-input)))))

  (defun open-phrase ()
    (let ((phrase (read-line)))
      (setf *buffer* (replace-dot phrase *buffer* *dot-l* *dot-r*)))
    (wait-for-input))
   
  (defun replace-dot (phrase string dot-l dot-r)
    (concatenate 'string (subseq string 0 (+ dot-l))
         phrase
         (subseq string (+ dot-r) (length string))))

  (defun quit-editor ()
    ; Does nothing yet; will check for changes in the future.
    )

Name: Anonymous 2009-10-30 15:08

Make that,
(loop (read-line) (format t "?~&"))

Name: Anonymous 2009-10-30 15:17

>>16
You're missing a paren after:
  (let ((called-function (assoc (read-line

Name: Anonymous 2009-10-30 15:20

whats an ED program

Name: Anonymous 2009-10-30 15:28

>>19
it's like unix 'yes', except it outputs '?' instead of 'y' and it does it when it reads '\n' on stdin

Name: Anonymous 2009-10-30 16:01

>>18
Weird. Must have been bit rot.

Name: Anonymous 2009-10-30 16:14

>>20
yes | rm *.*

Name: Anonymous 2009-10-30 16:17

>>21
bit rot

Name: Anonymous 2009-10-30 17:48

>>22
rm *.* ? why the fuck not just rm * ?

Name: Anonymous 2009-10-30 17:56

Guess what would be cool. A thread about actual, fully functional ed reimplementations in readers' languages of choice, not reimplementations of the most tired joke in the history of programming. This is about as entertaining or useful as learning that the `hello world' program in a language I've never heard about is approximately ``print "hello world"'' (Thanks, Wikipedia. I really appreciate you).

Name: Anonymous 2009-10-30 18:02

only deletes files with an extension
i.e. README.txt but not README

Name: Anonymous 2009-10-30 18:29

>>25
Hello world is a good example because it usually is able to represent a majority of how the language works.

Name: Anonymous 2009-10-30 19:14

>>27
-module(example).
-export([main/0]).

main() ->
    io:format("Hello world!~n").

Now, how much of the language do you think I have shown?

Unless you write a "hello world" program like
-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.

you aren't going to show even the basics of what makes a language special.

Name: Anonymous 2009-10-30 19:29

>>25
Forgot your sage

Name: Anonymous 2009-10-30 20:28

>>29
Remembered your sage

Name: Anonymous 2009-10-31 14:16

>>30
Haxed your anus

Name: Anonymous 2009-10-31 18:34

Please refrain from posting non-programming related material.

Thank you.

Name: Anonymous 2009-11-02 16:44

>>32

Please refrain from posting "Please refrain from posting non-programming related material.".

Thank you.

Name: Anonymous 2009-11-25 8:03

REFRAIN MY ANUS

Name: Anonymous 2009-11-25 8:30

lets reimplement emacs with modern languages and get rid of that SCHEME shit

Name: Anonymous 2009-11-25 8:37

>>31
I can't even read thatfucking line, i don't give a shti what your views are, get the hell off and drink paint thinner.

Name: Anonymous 2009-11-25 11:40

drink paint thinner
My hobby!

Name: Anonymous 2009-11-25 13:22

>>33
Please refrain from redundant punctuation. Thank you.

Name: Anonymous 2009-11-25 14:01

>>38
plz rfrn frm excss lttrs

Name: Anonymous 2009-11-25 17:04

>>39
>>38
Please refrain from ``Please refrain from''.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List