Commit a0b870ed authored by Marco Antoniotti's avatar Marco Antoniotti 💬
Browse files

Fixed doc strings.

parent 6426dcbf
......@@ -32,7 +32,14 @@ examples.
(defgeneric is-exit-stack-context (x)
(:method ((x exit-stack-context)) t)
(:method ((x t)) nil))
(:method ((x t)) nil)
"Returns T when the argument X is and EXIT-CONTEXT; NIL otherwise."))
(defun exit-stack-context-p (x)
"Returns T when the argument X is and EXIT-CONTEXT; NIL otherwise."
(is-exit-stack-context x))
......@@ -61,10 +68,12 @@ examples.
;;; Constructors.
(defun exit-stack ()
"Constructor for an EXIT-STACK-CONTEXT."
(make-instance 'exit-stack-context))
(defun error-context (item error)
"Constructor for an EXIT-STACK-CONTEXT."
(make-instance 'error-context :item item :error error))
......@@ -74,12 +83,17 @@ examples.
(defgeneric enter-context (exit-stack context-manager)
(:method ((es exit-stack-context) (cm context))
(with-slots (callback-stack) cm
(with-slots (callback-stack) es
(prog1 (enter cm)
(push cm callback-stack))
(error (e) (push (error-context cm e) callback-stack))
"Calls ENTER on a CONTEXT-MANAGER and pushes it on the EXIT-STACK callback stack.
If an error occurs while ENTERing the CONTEXT-MANAGER, then an
ERROR-CONTEXT is pushed on the EXIT-CONTEXT callback stack."))
(defgeneric push-context (exit-stack context-manager)
......@@ -87,14 +101,17 @@ examples.
;; This could be a :before method for ENTER-CONTEX.
(with-slots (callback-stack) es
(push cm callback-stack))
"Pushes a CONTEXT-MANAGER on the callback stack of EXIT-MANAGER."))
(defgeneric callback (exit-stack function &rest args)
(:method ((es exit-stack-context) (f function) &rest args)
(with-slots (callback-stack) es
(push (cons f args) callback-stack))
(:documentation "Adds a FUNCTION and its ARGS to an EXIT-STACK."))
(defgeneric pop-all (exit-stack-context)
......@@ -107,7 +124,13 @@ examples.
;; "transfer" in the Python's documentation.
;; Plus the 'files' example would not work if it weren't.
"Creates a new EXIT-STACK-CONTEXT and transfers the callbacks to it.
The callbacks of the current exit stack are popped from it and moved
to the new one."
(defgeneric unwind (exit-stack)
......@@ -125,6 +148,13 @@ examples.
;; (t (error "Should this be an error?"))
"The callback stack of the EXIT-STACK are popped and called.
This is the method 'close()' in Python. The name 'UNWIND' was chosen
to be more 'lispy' and to avoid conclictsa with CL:CLOSE.")
......@@ -109,6 +109,8 @@ The actual syntax of the WITH macro is the following:
with [VAR '='] CTXT-ITEM 'do' CODE
The macro establishes a 'context' based on the nature of CTXT-ITEM,
which is the result of an evaluated expression. VAR, if supplied, is
then bound to the result of ENTERing the context; i.e., VAR is bound
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment