src/middleware/core.lisp @ 7d0cd39ee703
Don't shit the bed when `load`ing a file with errors
Refactored the evaluator a bit so the file loading middleware can just use the
same evaluation machinery and get all the error handling and stream shuttling
for free.
author |
Steve Losh <steve@stevelosh.com> |
date |
Sat, 09 Apr 2016 21:45:42 +0000 |
parents |
3e9db801d234 |
children |
919ebd924aac |
(in-package #:nrepl)
(defvar *middleware* (fset:empty-map))
(defmacro handle-op (message op fallback &rest body)
`(if (equal ,op (fset:lookup ,message "op"))
(progn ,@body)
(funcall ,fallback ,message)))
(defmacro define-middleware (name op message-binding &body body)
"Define a middleware at the symbol `name` to handle `op`.
As the body is executing `message-binding` will be bound to the message map.
"
(let ((fallback (gensym)))
`(defun ,name (,fallback)
(lambda (,message-binding)
(handle-op ,message-binding ,op ,fallback
,@body)))))