Permalink
Browse files

Introduce *SIGNAL-UNBOUND-VARIABLE-ERRORS*

  • Loading branch information...
1 parent f72fee1 commit a18aa036e579ee7f9203c9648986dd8fcc79990d @metawilm committed Feb 8, 2011
Showing with 16 additions and 11 deletions.
  1. +16 −11 compiler/compiler.lisp
View
27 compiler/compiler.lisp
@@ -1333,23 +1333,28 @@ LOCALS shares share tail structure with input arg locals."
(defvar *module-preload-hook*)
+(defvar *signal-unbound-variable-errors* nil
+ "Whether to signal UNBOUND-VARIABLE when a Python variable is unbound, before a NameError is raised.")
+
(defun unbound-variable-error (name &key (expect-value t))
(declare (special *py-signal-conditions*))
(if expect-value
(restart-case
- (py-raise '{NameError} "Variable `~A' is unbound." name)
+ (progn (when *signal-unbound-variable-errors*
+ (signal 'unbound-variable :name name))
+ (py-raise '{NameError} "Variable `~A' is unbound." name))
(cl:use-value (val)
- :report (lambda (stream)
- (format stream "Enter a Lisp value to use for `~A'." name))
- :interactive (lambda ()
- (format t "Enter new Lisp value for `~A': " name)
- (multiple-value-list (eval (read))))
- (return-from unbound-variable-error val))
+ :report (lambda (stream)
+ (format stream "Enter a Lisp value to use for `~A'." name))
+ :interactive (lambda ()
+ (format t "Enter new Lisp value for `~A': " name)
+ (multiple-value-list (eval (read))))
+ (return-from unbound-variable-error val))
(import (val)
- :report (lambda (stream) (format stream "Use the built-in module named `~A'." name))
- :test (lambda (c)
- (declare (ignore c))
- (not (null (lisp-package-as-py-module name))))
+ :report (lambda (stream) (format stream "Use the built-in module named `~A'." name))
+ :test (lambda (c)
+ (declare (ignore c))
+ (not (null (lisp-package-as-py-module name))))
:interactive (lambda () (list (lisp-package-as-py-module name)))
(return-from unbound-variable-error val)))
(with-simple-restart (continue "Continue as if `~A' is currently bound." name)

0 comments on commit a18aa03

Please sign in to comment.