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-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.
    )

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