Created
July 2, 2013 16:12
-
-
Save thezerobit/5910691 to your computer and use it in GitHub Desktop.
This is an example of how Python's features get misused in ways that hint at symbolic programming in Lisp.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In Python it is common (though probably inadvisable) to | |
# use Exceptions for flow control in situations that are | |
# really not that exceptional. The Exception classes | |
# function as symbols for what is essentially symbolic | |
# programming using the exception handling machinery | |
# for the actual flow control. | |
class ValidationError(Exception): | |
pass | |
class RouteNotFound(Exception): | |
pass | |
def handler(request): | |
try: | |
validate_request(request) | |
except ValidationError: | |
handle_validation_error(request) | |
except RouteNotFound: | |
handle_route_not_found(request) | |
;; in Common Lisp or similar you could do something like this | |
;; where the validate-request function just returns a symbol | |
;; instead of raising an exception, and normal case matching | |
;; on the symbol for flow control. | |
(defun handler (request) | |
(let ((result (validate-request request))) | |
(case request | |
(validation-error (handle-validation-error request)) | |
(route-not-found (handle-route-not-found request))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment