From 1d8ea0404eeb23e8fea9fe3fe46002908a94bcb8 Mon Sep 17 00:00:00 2001 From: vindarel Date: Tue, 10 Nov 2020 00:09:31 +0100 Subject: [PATCH] lisp-critic: criticize AND eval for #7 --- docs/README.md | 11 +++++++++++ repl.lisp | 25 ++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/docs/README.md b/docs/README.md index ce05f68..aa4293d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -149,6 +149,17 @@ USE-EQL: Unless something special is going on, use EQL, not EQUAL. X-PLUS-1: Don't use (+ N 1), use (1+ N) for its value or (INCF N) to change N, whichever is appropriate here. ---------------------------------------------------------------------- +; in: DEFUN COUNT-A +; (SETQ CIEL-USER::N 0) +; +; caught WARNING: +; undefined variable: N +; +; compilation unit finished +; Undefined variable: +; N +; caught 1 WARNING condition +=> COUNT-A ``` diff --git a/repl.lisp b/repl.lisp index f8cf2c0..22e4757 100755 --- a/repl.lisp +++ b/repl.lisp @@ -240,15 +240,26 @@ (defun handle-lisp (before text) (let* ((new-txt (format nil "~a ~a" before text)) - (txt (if (and *lisp-critic* - (lisp-critic-applicalbe new-txt)) - (format nil "(LISP-CRITIC:CRITIQUE ~a)" new-txt) - new-txt)) - (parsed (handler-case (read-from-string txt) - (end-of-file () (sbcli txt *prompt2*)) + (to-critic (when (and *lisp-critic* + (lisp-critic-applicalbe new-txt)) + (format nil "(LISP-CRITIC:CRITIQUE ~a)" new-txt))) + (parsed (handler-case (read-from-string new-txt) + (end-of-file () (sbcli new-txt *prompt2*)) (error (condition) - (format *error-output* "Parser error: ~a~%" condition))))) + (format *error-output* "Parser error: ~a~%" condition)))) + (to-critic-parsed (when (and to-critic + parsed) + (handler-case (read-from-string to-critic) + (end-of-file () (sbcli to-critic *prompt2*)) + (error (condition) + (format *error-output* "Critic parser error: ~a~%" condition)))))) + (when to-critic-parsed + ;; The call to lisp-critic doesn't evaluate the lisp code, + ;; it only scans it and prints feedback. + (evaluate-lisp text to-critic-parsed)) + ;; But even if the lisp-critic is enabled, + ;; we want the code we type to be eval'ed. (when parsed (evaluate-lisp text parsed))))