[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Another possible fix for the top level



Part II of the Saga of Read-Line.  

THIS IS NOT AN OFFICIAL PATCH.
DO NOT INSTALL!

Another fix is unread any character, but a #\Newline.  The fix looks
like this:

  (defun top-level ()
    (let ((+ nil) (++ nil) (+++ nil)
          (- nil)
          (* nil) (** nil) (*** nil)
          (/ nil) (// nil) (/// nil))
      (setq *lisp-initialized* t)
      (catch *quit-tag*
        (let ((kclrc-env (si::getenv "KCLRC")))
          (when kclrc-env
            (let ((kclrc (merge-pathnames (user-homedir-pathname)
                                          (pathname (if (string= kclrc-env "")
                                                        ".kclrc"
                                                        kclrc-env)))))
              (when (probe-file kclrc) (load kclrc)))))
        (when (probe-file "init.lsp") (load "init.lsp")))
      (loop
        (setq +++ ++ ++ + + -)
!        (format t "~%~a}"
                (if (eq *package* (find-package 'user)) ""
                    (package-name *package*)))
        (reset-stack-limits)
        (when (catch *quit-tag*
                (setq - (locally (declare (notinline read))
!                                (prog1
!                                     (read *standard-input* nil *eof*)
!                                   (let ((nextchar (read-char
!                                                    *standard-input* nil *eof*)))
!                                     (case nextchar
!                                       ((#\Newline *eof*)
!                                        )
!                                       (otherwise
!                                        (unread-char nextchar *standard-input*)))))))
                (when (eq - *eof*) (bye))
                (let ((values (multiple-value-list
                               (locally (declare (notinline eval)) (eval -)))))
                  (setq /// // // / / values *** ** ** * * (car /))
                  (fresh-line)
                  (dolist (val /)
                    (locally (declare (notinline prin1)) (prin1 val))
                    (terpri))
                  nil))
          (terpri *error-output*)
          (break-current)))))

I have changed the prompt character to #\}, so that we can see when
the new top-level is in effect.  Using this top-level, we get the
following behavior:

  SYSTEM>Loading /tmp/emlisp7647
  Finished loading /tmp/emlisp7647
  t

  SYSTEM>(top-level)
  Loading /u/quiroz/.kclrc
  Loading /u/quiroz/work/kcl/defsys/defsys.o
  Finished loading /u/quiroz/work/kcl/defsys/defsys.o
  Finished loading /u/quiroz/.kclrc

  SYSTEM}(read-line)
  fooo bar
  "fooo bar"
  nil

  SYSTEM}

The !'s indicate the changes I made to the current toplevel.  Please
find the holes in it.

Cesar