The with-contexts Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The with-contexts Reference Manual

This is the with-contexts Reference Manual, generated automatically by Declt version 3.0 "Montgomery Scott" on Mon Apr 19 18:17:06 2021 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

WITH-CONTEXTS

Copyright (c) 2020-2021 Marco Antoniotti See file COPYING for licensing information

DESCRIPTION

This library contains an implementation of a WITH macro with "contexts" inspired by Python, which, in turn was obviously inspired by Common Lisp macros (and other earlier languages, like Pascal).

The Python library is described in the documentation of the contextlib documentation. The current library is an implementation that overlaps with the Python one, as a few things are available in Common Lisp that are not available in Python and two things are present in Python, that are not available in Common Lisp: the yield statement and built-in threading for asynchronous computations. Note that the yield statement could be built in Common Lisp using a delimited continuation library like cl-cont. The asynchronous extensions could instead be directly built on top of the current library.

Most of the Python examples described in the ... context of contextlib are directly translatable into Common Lisp using the present library. The main difference is that, in order to leverage the Common Lisp Condition subsystem the "protocol" that "contexts" must implement is comprised of three generic functions:

The WITH macro is practically expanded as follows.

(with [VAR =] CONTEXT-ITEM do CODE)

becomes

(let ((VAR NIL))
  (unwind-protect
    (progn
      (setf VAR (ENTER CONTEXT-ITEM))
      (handler-case 
          CODE
        (error (e)
          (HANDLE VAR e))
      ))
    (EXIT VAR)))

With this setup, WITH-OPEN-FILE can be immediately rewritten as

(with f = (open "some.txt") do
  (loop for line = (read-line f)
       while line
	   do (do-stuff-to line)))

provided that the proper ENTER/HANDLE/EXIT protocol is in place. Something like the following.

(defmethod enter ((s file-stream) &key)
  (if (open-stream-p s)
      s
      (error "Stream ~S is not open." context-item)))
	   
(defmethod handle ((s file-stream) (e error) &key)
  (call-next-method))
  
(defmethod exit ((s file-stream) &key)
  (when (open-stream-p s)
    (close s)))

Note that in Python, HANDLE does not exist and EXIT is called close.

More Elaborated Contexts

The contextlib Python library contains more elaborated "contexts" that can be used to perform a number of sophisticated operations in conjunction with the WITH statement.

EXIT-STACK-CONTEXT

Python introduces ExitStack as (the following is a direct quote from Python contextlib documentation) a context manager that is designed to make it easy to programmatically combine other context managers and cleanup functions, especially those that are optional or otherwise driven by input data.

For example, a set of files may easily be handled in a single with statement as follows:

(with stack = (exit-stack) do
  (let* ((files (mapcar (lambda (fname)
                          (enter-context stack (open fname)))
                         *filenames*)))

    ;; Hold on to the new exit stack (not the method pointe as in the
    ;; Python example), but don't call its UNWIND method

    (setf *close-files* (pop-all stack))

    ;; If opening any file fails, all previously opened files will be
    ;; closed automatically. If all files are opened successfully,
    ;; they will remain open even after the with statement ends.
    ;;
    ;;    (unwind *close-files*)
    ;;
    ;; can then be invoked explicitly to close them all.

    ;; ...
    )

Each instance maintains a stack of registered callbacks that are called in reverse order when the instance is closed (either explicitly or implicitly at the end of a WITH statement).

Documentation

Please refer to the full documentation of the with-contexts library for more details.

A NOTE ON FORKING

Of course you are free to fork the project subject to the current licensing scheme. However, before you do so, I ask you to consider plain old "cooperation" by asking me to become a developer. It helps keeping the entropy level at an acceptable level.


Enjoy!

Marco Antoniotti 20201212


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 with-contexts

Author

Marco Antoniotti <mantoniotti@common-lisp.net>

License

BSD

Description

The WITH-CONTEXT System.

A system providing a WITH macro and ’context’ualized objects handled by a ENTER/HANDLE/EXIT protocol in the spirit of Python’s WITH macro.

Only better, or, at a minimum different, of course.

Source

with-contexts.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

3 Modules

Modules are listed depth-first from the system components tree.


Previous: , Up: Modules   [Contents][Index]

3.1 with-contexts/library

Dependencies
Parent

with-contexts (system)

Location

library/

Components

Next: , Previous: , Up: Top   [Contents][Index]

4 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

4.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.1 with-contexts.asd

Location

with-contexts.asd

Systems

with-contexts (system)


Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.2 with-contexts/with-contexts-pkg.lisp

Parent

with-contexts (system)

Location

with-contexts-pkg.lisp

Packages

it.unimib.disco.ma.cl.ext.dacf.with-contexts


Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.3 with-contexts/contexts.lisp

Dependency

with-contexts-pkg.lisp (file)

Parent

with-contexts (system)

Location

contexts.lisp

Exported Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.4 with-contexts/with-cl.lisp

Dependencies
Parent

with-contexts (system)

Location

with-cl.lisp

Exported Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.5 with-contexts/library/with-open-file.lisp

Parent

library (module)

Location

library/with-open-file.lisp

Exported Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.6 with-contexts/library/exit-stack-context.lisp

Parent

library (module)

Location

library/exit-stack-context.lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.7 with-contexts/library/suppress-context.lisp

Parent

library (module)

Location

library/suppress-context.lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.8 with-contexts/library/null-context.lisp

Parent

library (module)

Location

library/null-context.lisp

Exported Definitions
Internal Definitions

enter-result (method)


Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.9 with-contexts/library/delegate-context.lisp

Parent

library (module)

Location

library/delegate-context.lisp

Exported Definitions
Internal Definitions

enter-result (method)


Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.10 with-contexts/library/redirect-context.lisp

Parent

library (module)

Location

library/redirect-context.lisp

Exported Definitions
Internal Definitions

Previous: , Up: Lisp files   [Contents][Index]

4.1.11 with-contexts/library/managed-resource-context.lisp

Parent

library (module)

Location

library/managed-resource-context.lisp

Exported Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

5.1 it.unimib.disco.ma.cl.ext.dacf.with-contexts

The CL Contexts Package.

The package containing and exporting the names relating to the implementation of the WITH macro and ’contexts’ in Common Lisp.

Source

with-contexts-pkg.lisp (file)

Nicknames
Use List

common-lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

6 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

6.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

6.1.1 Macros

Macro: with &rest WITH-SPEC

The WITH Macro.

The actual syntax of the WITH macro is the following:

with [VAR ’=’] CTXT-ITEM ’do’ CODE

Description:

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 to the (first) value of applying the generic function ENTER to CTXT-ITEM and it is available within CODE. If VAR is supplied, it ’escapes’ the with construct as if SETQed in the enclosind environment.

The WITH macro guarantees that the generic function EXIT is called as the cleanup form in an UNWIND-PROTECT before returning the values generated by CODE of after error conditions are signaled by it. EXIT is called with VAR

Errors generated by CODE are passed alogside VAR to the generic function HANDLE. This is done in a HANDLER-CASE within the UNWIND-PROTECT that wraps CODE and uses the EXIT generic function as cleanup form.

The value(s) returned by EXIT are effectively ignored.

Notes:

The inspiration for this macro comes from Python, which reinvented and expanded the concept from Common Lisp or Pascal or even somewhere else. Julia may have something similar with its ’do’ blocks.

Note that, unlike Python, Common Lisp does not have a "yield" statement or (delimited) continuations; therefore, the mapping with Python code cannot be one-to-one.

Exceptional Situations:

If an error occurs while evaluating CTXT-ITEM, then HANDLE is not called, while EXIT is called with NIL as argument.

See Also:

ENTER, HANDLE, EXIT, WITH-OPEN-FILE

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

with-cl.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

6.1.2 Functions

Function: condition-ignoring-context-p X

Returns T if X is a CONDITION-IGNORING-CONTEXT, NIL otherwise.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

suppress-context.lisp (file)

Function: context-p X

Returns T if the argument X is a CONTEXT; NIL otherwise.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

contexts.lisp (file)

Function: delegate &optional ENTER-RESULT

Creates a DELEGATE-CONTEXT stashing ENTER-RESULT for ENTER.

A subsequent call to ENTER on the instance will extract ENTER-RESULT and return it.

See Also:

ENTER, HANDLE, EXIT, WITH, DELEGATE-CONTEXT (Class)

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

delegate-context.lisp (file)

Function: delegate-context-p X
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

delegate-context.lisp (file)

Function: error-output-redirection STREAM
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

redirect-context.lisp (file)

Function: exit-stack ()

Constructor for an EXIT-STACK-CONTEXT.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)

Function: exit-stack-context-p X

Returns T when the argument X is and EXIT-CONTEXT; NIL otherwise.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)

Function: ignored CONDITIONS &key SUBTYPEP &allow-other-keys

Returns a CONDITION-IGNORING-CONTEXT.

The argument CONDITIONS is a list of CONDITION designators (or a single CONDITION designator) to be ingnored by the HANDLE method within a WITH context macro.

If SUBTYPEP is T any condition/error that is a subtype/subclass of any member in CONDITIOS will be ignored/suppressed by the HANDLE method, otherwse only instances of the exact CONDITIONS member will be ignored.

See Also:

ENTER, HANDLE, EXIT, SUPPRESSED

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

suppress-context.lisp (file)

Function: managed-resource ID &key &allow-other-keys

Constructs a MANAGED-RESOURCE.

The only declared parameter, ID, should be a unique identified for the resource.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

managed-resource-context.lisp (file)

Function: managed-resource-context-p X

Returns T if the argument X is a MANAGED-RESOURCE-CONTEXT.

Notes:

This function is a synonim of IS-MANAGED-RESOURCE-CONTEXT.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

managed-resource-context.lisp (file)

Function: null-context &optional ENTER-RESULT

Creates a NULL-CONTEXT stashing ENTER-RESULT for ENTER.

A subsequent call to ENTER on the instance will extract ENTER-RESULT and return it.

See Also:

ENTER, HANDLE, EXIT, WITH, NULL-CONTEXT (Class)

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

null-context.lisp (file)

Function: null-context-p X
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

null-context.lisp (file)

Function: redirect-context-p X

Returns T if the argument X is a REDIRECT-CONTEXT.

Notes:

This is a synonym of IS-REDIRECT-CONTEXT.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

redirect-context.lisp (file)

Function: standard-input-redirection STREAM
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

redirect-context.lisp (file)

Function: standard-output-redirection STREAM
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

redirect-context.lisp (file)

Function: suppressed CONDITIONS &key SUBTYPEP &allow-other-keys

Returns a CONDITION-IGNORING-CONTEXT.

This constructor is a synonim for IGNORED.

See Also:

IGNORED, ENTER, HANDLE, EXIT

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

suppress-context.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

6.1.3 Generic functions

Generic Function: acquire MR &key

Acquires a MANAGED-RESOURCE.

This generic function is the ’entry’ point of the ACQUIRE/RELEASE protocol.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

managed-resource-context.lisp (file)

Methods
Method: acquire (MR managed-resource-context) &key
Generic Function: callback EXIT-STACK FUNCTION &rest ARGS

Adds a FUNCTION and its ARGS to an EXIT-STACK.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)

Methods
Method: callback (ES exit-stack-context) (F function) &rest ARGS
Generic Function: enter CONTEXT-ITEM &key

The ENTER Generic Function.

The methods of this function establish a ’context’ that can be used by the ENTER/HANDLE/EXIT protocol within the WITH context macro.

The main and simplest method is an identity operation which just returns the argument.

Exceptional Situations:

If this method generates an error, then HANDLE is not called and EXIT is called with NIL as an argument.

Notes:

Because of this "interpretation" of the ENTER method, NULL-CONTEXTS become a bit redundant, but they are provided for completeness.

See Also:

HANDLE, EXIT, NULL-CONTEXT

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

with-cl.lisp (file)

Methods
Method: enter (MR managed-resource-context) &key
Source

managed-resource-context.lisp (file)

Method: enter (RIC redirect-input-context) &key after
Source

redirect-context.lisp (file)

Method: enter (REOC redirect-error-output-context) &key after
Source

redirect-context.lisp (file)

Method: enter (RSOC redirect-standard-output-context) &key after
Source

redirect-context.lisp (file)

Method: enter (NC delegate-context) &key
Source

delegate-context.lisp (file)

Method: enter (NC null-context) &key
Source

null-context.lisp (file)

Method: enter (IGN condition-ignoring-context) &key
Source

suppress-context.lisp (file)

Method: enter (ES exit-stack-context) &key
Source

exit-stack-context.lisp (file)

Method: enter (CONTEXT-ITEM stream) &key
Source

with-open-file.lisp (file)

Method: enter CONTEXT-ITEM &key
Generic Function: enter-context EXIT-STACK CONTEXT-MANAGER

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.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)

Methods
Method: enter-context (ES exit-stack-context) (CM context)
Generic Function: exit CONTEXT-ITEM &key

The EXIT Generic Function.

The methods of this function dispatch on a CONTEXT-ITEM and are always called as ’cleanup forms’ of an UNWIND-PROTECT. The values reurned by this generic function are therefore ignored.

The main method dispatching on NIL is called when ENTER generates errors.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

with-cl.lisp (file)

Methods
Method: exit (MR managed-resource-context) &key
Source

managed-resource-context.lisp (file)

Method: exit (RIC redirect-input-context) &key after
Source

redirect-context.lisp (file)

Method: exit (REOC redirect-error-output-context) &key after
Source

redirect-context.lisp (file)

Method: exit (RSOC redirect-standard-output-context) &key after
Source

redirect-context.lisp (file)

Method: exit (NC delegate-context) &key
Source

delegate-context.lisp (file)

Method: exit (NC null-context) &key
Source

null-context.lisp (file)

Method: exit (IGN condition-ignoring-context) &key
Source

suppress-context.lisp (file)

Method: exit (ES exit-stack-context) &key
Source

exit-stack-context.lisp (file)

Method: exit (CONTEXT-ITEM stream) &key
Source

with-open-file.lisp (file)

Method: exit CONTEXT-ITEM &key
Method: exit (CONTEXT-ITEM null) &key
Generic Function: handle CONTEXT-ITEM CONDITION &key

The HANDLE Generic Function.

The methods of this function dispatch on a CONTEXT-ITEM and a CONDITION. In this way, within the confines of the the WITH macro, there is a decoupled way of handling different exceptions.

The main and simpler method of this generic function simply re-signals the condition.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

with-cl.lisp (file)

Methods
Method: handle (MR managed-resource-context) (E error) &key
Source

managed-resource-context.lisp (file)

Method: handle (RC redirect-context) (E error) &key
Source

redirect-context.lisp (file)

Method: handle (NC delegate-context) (E error) &key
Source

delegate-context.lisp (file)

Method: handle (NC null-context) (E error) &key
Source

null-context.lisp (file)

Method: handle (IGN condition-ignoring-context) (E error) &key
Source

suppress-context.lisp (file)

Method: handle (ES exit-stack-context) (E error) &key
Source

exit-stack-context.lisp (file)

Method: handle (CONTEXT-ITEM stream) (E error) &key
Source

with-open-file.lisp (file)

Method: handle CONTEXT-ITEM (CONDITION error) &key
Generic Function: is-condition-ignoring-context X

Returns T if X is a CONDITION-IGNORING-CONTEXT, NIL otherwise.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

suppress-context.lisp (file)

Methods
Method: is-condition-ignoring-context (X condition-ignoring-context)
Method: is-condition-ignoring-context X
Generic Function: is-context X

Returns T if the argument X is a CONTEXT; NIL otherwise.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

contexts.lisp (file)

Methods
Method: is-context (C context)
Method: is-context C
Generic Function: is-delegate-context X
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

delegate-context.lisp (file)

Methods
Method: is-delegate-context (X delegate-context)
Method: is-delegate-context X
Generic Function: is-exit-stack-context X

Returns T when the argument X is and EXIT-CONTEXT; NIL otherwise.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)

Methods
Method: is-exit-stack-context (X exit-stack-context)
Method: is-exit-stack-context X
Generic Function: is-managed-resource-context X

Returns T if the argument X is a MANAGED-RESOURCE-CONTEXT.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

managed-resource-context.lisp (file)

Methods
Method: is-managed-resource-context (X managed-resource-context)
Method: is-managed-resource-context X
Generic Function: is-null-context X
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

null-context.lisp (file)

Methods
Method: is-null-context (X null-context)
Method: is-null-context X
Generic Function: is-redirect-context X

Returns T if the argument X is a REDIRECT-CONTEXT.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

redirect-context.lisp (file)

Methods
Method: is-redirect-context (X redirect-context)
Method: is-redirect-context X
Generic Function: pop-all EXIT-STACK-CONTEXT

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.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)

Methods
Method: pop-all (ES exit-stack-context)
Generic Function: push-context EXIT-STACK CONTEXT-MANAGER

Pushes a CONTEXT-MANAGER on the callback stack of EXIT-MANAGER.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)

Methods
Method: push-context (ES exit-stack-context) (CM context)
Generic Function: redirection OBJECT
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Methods
Method: redirection (REDIRECT-CONTEXT redirect-context)

automatically generated reader method

Source

redirect-context.lisp (file)

Generic Function: release MR &key

Releases a MANAGED-RESOURCE.

This generic function is the ’exit’ point of the ACQUIRE/RELEASE protocol.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

managed-resource-context.lisp (file)

Methods
Method: release (MR managed-resource-context) &key
Generic Function: unwind EXIT-STACK

The callback stack of the EXIT-STACK are popped and called.

Notes:

This is the method ’close()’ in Python. The name ’UNWIND’ was chosen to be more ’lispy’ and to avoid conclictsa with CL:CLOSE.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)

Methods
Method: unwind (ES exit-stack-context)

Previous: , Up: Exported definitions   [Contents][Index]

6.1.4 Classes

Class: condition-ignoring-context ()

The Condition-ignoring Context Class.

Instances of this class are used to ignore/suppress errors within a WITH context macro.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

suppress-context.lisp (file)

Direct superclasses

context (class)

Direct methods
Direct slots
Slot: conditions
Initargs

:conditions

Readers

ignored-conditions (generic function)

Slot: check-subtypep
Initargs

:subtypep

Readers

check-subtypep (generic function)

Direct Default Initargs
InitargValue
:subtypepnil
Class: context ()

The Context Class.

A class that can be used in conjunction with the WITH macro. This class is the top of the hierarchy of "context" classes. It shuld not be directly instantiated.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

contexts.lisp (file)

Direct superclasses

standard-object (class)

Direct subclasses
Direct methods
Class: delegate-context ()

The Delegate Context Class.

A context that just wraps a value to which it delegates its behavior.

Notes:

This context it necessary in Common Lisp as the ENTER/HANDLE/EXIT protocol can be implemented indipendently of ’being a context’.

See Also:

ENTER, HANDLE, EXIT, WITH, DELEGATE-CONTEXT (Function)

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

delegate-context.lisp (file)

Direct superclasses

context (class)

Direct methods
Direct slots
Slot: enter-result
Initargs

:enter-result

Readers

enter-result (generic function)

Direct Default Initargs
InitargValue
:enter-resultnil
Class: exit-stack-context ()

The Exit Stack Class.

A class that serves to collect and unwind code (callbacks) that are collected within a WITH macro body. The methods of this class provide more control over what happens with errors that may happen within ENTER calls in non-straightforward contexts.

Notes:

This class provides much of the functionalities displayed in the Python examples.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)

Direct superclasses

context (class)

Direct methods
Direct slots
Slot: callback-stack
Type

list

Readers

callback-stack (generic function)

Writers

set-callback-stack (generic function)

Class: managed-resource-context ()

The Managed Resource Context Class.

A placeholder class showing how to render, more or less, the Python examples in Common Lisp.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

managed-resource-context.lisp (file)

Direct superclasses

context (class)

Direct methods
Direct slots
Slot: resource
Initargs

:resource

Class: null-context ()

The Null Context Class.

A context that just wraps a value that it is then returned by ENTER.

See Also:

ENTER, HANDLE, EXIT, WITH, NULL-CONTEXT (Function)

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

null-context.lisp (file)

Direct superclasses

context (class)

Direct methods
Direct slots
Slot: enter-result
Initargs

:enter-result

Readers

enter-result (generic function)

Direct Default Initargs
InitargValue
:enter-resultnil
Class: redirect-context ()

The Redirect Context Class.

This is the context superclass for redirecting I/O. The library creates instances of this class subclasses.

See Also:

REDIRECT-OUTPUT-CONTEXT, REDIRECT-INPUT-CONTEXT, REDIRECT-STANDARD-OUTPUT-CONTEXT, REDIRECT-ERROR-OUTPUT-CONTEXT, ENTER, HANDLE, EXIT, WITH

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

redirect-context.lisp (file)

Direct superclasses

context (class)

Direct subclasses
Direct methods
Direct slots
Slot: stream
Type

stream

Initargs

:stream

Readers

redirection (generic function)

Slot: saved-stream
Type

stream

Readers

%%saved-stream (generic function)

Writers

(setf %%saved-stream) (generic function)

Class: redirect-error-output-context ()
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

redirect-context.lisp (file)

Direct superclasses

redirect-output-context (class)

Direct methods
Class: redirect-input-context ()
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

redirect-context.lisp (file)

Direct superclasses

redirect-context (class)

Direct methods
  • exit (method)
  • enter (method)
  • initialize-instance (method)
Class: redirect-output-context ()
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

redirect-context.lisp (file)

Direct superclasses

redirect-context (class)

Direct subclasses
Direct methods

initialize-instance (method)

Class: redirect-standard-output-context ()
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

redirect-context.lisp (file)

Direct superclasses

redirect-output-context (class)

Direct methods

Previous: , Up: Definitions   [Contents][Index]

6.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

6.2.1 Functions

Function: error-context ITEM ERROR

Constructor for an EXIT-STACK-CONTEXT.

Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)

Function: error-context-p X
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

6.2.2 Generic functions

Generic Function: %%saved-stream OBJECT
Generic Function: (setf %%saved-stream) NEW-VALUE OBJECT
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Methods
Method: %%saved-stream (REDIRECT-CONTEXT redirect-context)

automatically generated reader method

Source

redirect-context.lisp (file)

Method: (setf %%saved-stream) NEW-VALUE (REDIRECT-CONTEXT redirect-context)

automatically generated writer method

Source

redirect-context.lisp (file)

Generic Function: callback-stack OBJECT
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Methods
Method: callback-stack (EXIT-STACK-CONTEXT exit-stack-context)

automatically generated reader method

Source

exit-stack-context.lisp (file)

Generic Function: check-subtypep OBJECT
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Methods
Method: check-subtypep (CONDITION-IGNORING-CONTEXT condition-ignoring-context)

automatically generated reader method

Source

suppress-context.lisp (file)

Generic Function: enter-result OBJECT
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Methods
Method: enter-result (DELEGATE-CONTEXT delegate-context)

automatically generated reader method

Source

delegate-context.lisp (file)

Method: enter-result (NULL-CONTEXT null-context)

automatically generated reader method

Source

null-context.lisp (file)

Generic Function: error-context-condition OBJECT
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Methods
Method: error-context-condition (ERROR-CONTEXT error-context)

automatically generated reader method

Source

exit-stack-context.lisp (file)

Generic Function: error-context-item OBJECT
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Methods
Method: error-context-item (ERROR-CONTEXT error-context)

automatically generated reader method

Source

exit-stack-context.lisp (file)

Generic Function: ignored-conditions OBJECT
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Methods
Method: ignored-conditions (CONDITION-IGNORING-CONTEXT condition-ignoring-context)

automatically generated reader method

Source

suppress-context.lisp (file)

Generic Function: is-error-context X
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)

Methods
Method: is-error-context (X error-context)
Method: is-error-context X
Generic Function: set-callback-stack NEW-VALUE OBJECT
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Methods
Method: set-callback-stack NEW-VALUE (EXIT-STACK-CONTEXT exit-stack-context)

automatically generated writer method

Source

exit-stack-context.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

6.2.3 Classes

Class: error-context ()
Package

it.unimib.disco.ma.cl.ext.dacf.with-contexts

Source

exit-stack-context.lisp (file)

Direct superclasses

context (class)

Direct methods
Direct slots
Slot: ctx
Initargs

:item

Readers

error-context-item (generic function)

Slot: cnd
Initargs

:condition, :error

Readers

error-context-condition (generic function)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   F   L   M   W  
Index Entry  Section

F
File, Lisp, with-contexts.asd: The with-contexts․asd file
File, Lisp, with-contexts/contexts.lisp: The with-contexts/contexts․lisp file
File, Lisp, with-contexts/library/delegate-context.lisp: The with-contexts/library/delegate-context․lisp file
File, Lisp, with-contexts/library/exit-stack-context.lisp: The with-contexts/library/exit-stack-context․lisp file
File, Lisp, with-contexts/library/managed-resource-context.lisp: The with-contexts/library/managed-resource-context․lisp file
File, Lisp, with-contexts/library/null-context.lisp: The with-contexts/library/null-context․lisp file
File, Lisp, with-contexts/library/redirect-context.lisp: The with-contexts/library/redirect-context․lisp file
File, Lisp, with-contexts/library/suppress-context.lisp: The with-contexts/library/suppress-context․lisp file
File, Lisp, with-contexts/library/with-open-file.lisp: The with-contexts/library/with-open-file․lisp file
File, Lisp, with-contexts/with-cl.lisp: The with-contexts/with-cl․lisp file
File, Lisp, with-contexts/with-contexts-pkg.lisp: The with-contexts/with-contexts-pkg․lisp file

L
Lisp File, with-contexts.asd: The with-contexts․asd file
Lisp File, with-contexts/contexts.lisp: The with-contexts/contexts․lisp file
Lisp File, with-contexts/library/delegate-context.lisp: The with-contexts/library/delegate-context․lisp file
Lisp File, with-contexts/library/exit-stack-context.lisp: The with-contexts/library/exit-stack-context․lisp file
Lisp File, with-contexts/library/managed-resource-context.lisp: The with-contexts/library/managed-resource-context․lisp file
Lisp File, with-contexts/library/null-context.lisp: The with-contexts/library/null-context․lisp file
Lisp File, with-contexts/library/redirect-context.lisp: The with-contexts/library/redirect-context․lisp file
Lisp File, with-contexts/library/suppress-context.lisp: The with-contexts/library/suppress-context․lisp file
Lisp File, with-contexts/library/with-open-file.lisp: The with-contexts/library/with-open-file․lisp file
Lisp File, with-contexts/with-cl.lisp: The with-contexts/with-cl․lisp file
Lisp File, with-contexts/with-contexts-pkg.lisp: The with-contexts/with-contexts-pkg․lisp file

M
Module, with-contexts/library: The with-contexts/library module

W
with-contexts.asd: The with-contexts․asd file
with-contexts/contexts.lisp: The with-contexts/contexts․lisp file
with-contexts/library: The with-contexts/library module
with-contexts/library/delegate-context.lisp: The with-contexts/library/delegate-context․lisp file
with-contexts/library/exit-stack-context.lisp: The with-contexts/library/exit-stack-context․lisp file
with-contexts/library/managed-resource-context.lisp: The with-contexts/library/managed-resource-context․lisp file
with-contexts/library/null-context.lisp: The with-contexts/library/null-context․lisp file
with-contexts/library/redirect-context.lisp: The with-contexts/library/redirect-context․lisp file
with-contexts/library/suppress-context.lisp: The with-contexts/library/suppress-context․lisp file
with-contexts/library/with-open-file.lisp: The with-contexts/library/with-open-file․lisp file
with-contexts/with-cl.lisp: The with-contexts/with-cl․lisp file
with-contexts/with-contexts-pkg.lisp: The with-contexts/with-contexts-pkg․lisp file

Jump to:   F   L   M   W  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   %   (  
A   C   D   E   F   G   H   I   M   N   P   R   S   U   W  
Index Entry  Section

%
%%saved-stream: Internal generic functions
%%saved-stream: Internal generic functions

(
(setf %%saved-stream): Internal generic functions
(setf %%saved-stream): Internal generic functions

A
acquire: Exported generic functions
acquire: Exported generic functions

C
callback: Exported generic functions
callback: Exported generic functions
callback-stack: Internal generic functions
callback-stack: Internal generic functions
check-subtypep: Internal generic functions
check-subtypep: Internal generic functions
condition-ignoring-context-p: Exported functions
context-p: Exported functions

D
delegate: Exported functions
delegate-context-p: Exported functions

E
enter: Exported generic functions
enter: Exported generic functions
enter: Exported generic functions
enter: Exported generic functions
enter: Exported generic functions
enter: Exported generic functions
enter: Exported generic functions
enter: Exported generic functions
enter: Exported generic functions
enter: Exported generic functions
enter: Exported generic functions
enter-context: Exported generic functions
enter-context: Exported generic functions
enter-result: Internal generic functions
enter-result: Internal generic functions
enter-result: Internal generic functions
error-context: Internal functions
error-context-condition: Internal generic functions
error-context-condition: Internal generic functions
error-context-item: Internal generic functions
error-context-item: Internal generic functions
error-context-p: Internal functions
error-output-redirection: Exported functions
exit: Exported generic functions
exit: Exported generic functions
exit: Exported generic functions
exit: Exported generic functions
exit: Exported generic functions
exit: Exported generic functions
exit: Exported generic functions
exit: Exported generic functions
exit: Exported generic functions
exit: Exported generic functions
exit: Exported generic functions
exit: Exported generic functions
exit-stack: Exported functions
exit-stack-context-p: Exported functions

F
Function, condition-ignoring-context-p: Exported functions
Function, context-p: Exported functions
Function, delegate: Exported functions
Function, delegate-context-p: Exported functions
Function, error-context: Internal functions
Function, error-context-p: Internal functions
Function, error-output-redirection: Exported functions
Function, exit-stack: Exported functions
Function, exit-stack-context-p: Exported functions
Function, ignored: Exported functions
Function, managed-resource: Exported functions
Function, managed-resource-context-p: Exported functions
Function, null-context: Exported functions
Function, null-context-p: Exported functions
Function, redirect-context-p: Exported functions
Function, standard-input-redirection: Exported functions
Function, standard-output-redirection: Exported functions
Function, suppressed: Exported functions

G
Generic Function, %%saved-stream: Internal generic functions
Generic Function, (setf %%saved-stream): Internal generic functions
Generic Function, acquire: Exported generic functions
Generic Function, callback: Exported generic functions
Generic Function, callback-stack: Internal generic functions
Generic Function, check-subtypep: Internal generic functions
Generic Function, enter: Exported generic functions
Generic Function, enter-context: Exported generic functions
Generic Function, enter-result: Internal generic functions
Generic Function, error-context-condition: Internal generic functions
Generic Function, error-context-item: Internal generic functions
Generic Function, exit: Exported generic functions
Generic Function, handle: Exported generic functions
Generic Function, ignored-conditions: Internal generic functions
Generic Function, is-condition-ignoring-context: Exported generic functions
Generic Function, is-context: Exported generic functions
Generic Function, is-delegate-context: Exported generic functions
Generic Function, is-error-context: Internal generic functions
Generic Function, is-exit-stack-context: Exported generic functions
Generic Function, is-managed-resource-context: Exported generic functions
Generic Function, is-null-context: Exported generic functions
Generic Function, is-redirect-context: Exported generic functions
Generic Function, pop-all: Exported generic functions
Generic Function, push-context: Exported generic functions
Generic Function, redirection: Exported generic functions
Generic Function, release: Exported generic functions
Generic Function, set-callback-stack: Internal generic functions
Generic Function, unwind: Exported generic functions

H
handle: Exported generic functions
handle: Exported generic functions
handle: Exported generic functions
handle: Exported generic functions
handle: Exported generic functions
handle: Exported generic functions
handle: Exported generic functions
handle: Exported generic functions
handle: Exported generic functions

I
ignored: Exported functions
ignored-conditions: Internal generic functions
ignored-conditions: Internal generic functions
is-condition-ignoring-context: Exported generic functions
is-condition-ignoring-context: Exported generic functions
is-condition-ignoring-context: Exported generic functions
is-context: Exported generic functions
is-context: Exported generic functions
is-context: Exported generic functions
is-delegate-context: Exported generic functions
is-delegate-context: Exported generic functions
is-delegate-context: Exported generic functions
is-error-context: Internal generic functions
is-error-context: Internal generic functions
is-error-context: Internal generic functions
is-exit-stack-context: Exported generic functions
is-exit-stack-context: Exported generic functions
is-exit-stack-context: Exported generic functions
is-managed-resource-context: Exported generic functions
is-managed-resource-context: Exported generic functions
is-managed-resource-context: Exported generic functions
is-null-context: Exported generic functions
is-null-context: Exported generic functions
is-null-context: Exported generic functions
is-redirect-context: Exported generic functions
is-redirect-context: Exported generic functions
is-redirect-context: Exported generic functions

M
Macro, with: Exported macros
managed-resource: Exported functions
managed-resource-context-p: Exported functions
Method, %%saved-stream: Internal generic functions
Method, (setf %%saved-stream): Internal generic functions
Method, acquire: Exported generic functions
Method, callback: Exported generic functions
Method, callback-stack: Internal generic functions
Method, check-subtypep: Internal generic functions
Method, enter: Exported generic functions
Method, enter: Exported generic functions
Method, enter: Exported generic functions
Method, enter: Exported generic functions
Method, enter: Exported generic functions
Method, enter: Exported generic functions
Method, enter: Exported generic functions
Method, enter: Exported generic functions
Method, enter: Exported generic functions
Method, enter: Exported generic functions
Method, enter-context: Exported generic functions
Method, enter-result: Internal generic functions
Method, enter-result: Internal generic functions
Method, error-context-condition: Internal generic functions
Method, error-context-item: Internal generic functions
Method, exit: Exported generic functions
Method, exit: Exported generic functions
Method, exit: Exported generic functions
Method, exit: Exported generic functions
Method, exit: Exported generic functions
Method, exit: Exported generic functions
Method, exit: Exported generic functions
Method, exit: Exported generic functions
Method, exit: Exported generic functions
Method, exit: Exported generic functions
Method, exit: Exported generic functions
Method, handle: Exported generic functions
Method, handle: Exported generic functions
Method, handle: Exported generic functions
Method, handle: Exported generic functions
Method, handle: Exported generic functions
Method, handle: Exported generic functions
Method, handle: Exported generic functions
Method, handle: Exported generic functions
Method, ignored-conditions: Internal generic functions
Method, is-condition-ignoring-context: Exported generic functions
Method, is-condition-ignoring-context: Exported generic functions
Method, is-context: Exported generic functions
Method, is-context: Exported generic functions
Method, is-delegate-context: Exported generic functions
Method, is-delegate-context: Exported generic functions
Method, is-error-context: Internal generic functions
Method, is-error-context: Internal generic functions
Method, is-exit-stack-context: Exported generic functions
Method, is-exit-stack-context: Exported generic functions
Method, is-managed-resource-context: Exported generic functions
Method, is-managed-resource-context: Exported generic functions
Method, is-null-context: Exported generic functions
Method, is-null-context: Exported generic functions
Method, is-redirect-context: Exported generic functions
Method, is-redirect-context: Exported generic functions
Method, pop-all: Exported generic functions
Method, push-context: Exported generic functions
Method, redirection: Exported generic functions
Method, release: Exported generic functions
Method, set-callback-stack: Internal generic functions
Method, unwind: Exported generic functions

N
null-context: Exported functions
null-context-p: Exported functions

P
pop-all: Exported generic functions
pop-all: Exported generic functions
push-context: Exported generic functions
push-context: Exported generic functions

R
redirect-context-p: Exported functions
redirection: Exported generic functions
redirection: Exported generic functions
release: Exported generic functions
release: Exported generic functions

S
set-callback-stack: Internal generic functions
set-callback-stack: Internal generic functions
standard-input-redirection: Exported functions
standard-output-redirection: Exported functions
suppressed: Exported functions

U
unwind: Exported generic functions
unwind: Exported generic functions

W
with: Exported macros

Jump to:   %   (  
A   C   D   E   F   G   H   I   M   N   P   R   S   U   W  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   C   E   R   S  
Index Entry  Section

C
callback-stack: Exported classes
check-subtypep: Exported classes
cnd: Internal classes
conditions: Exported classes
ctx: Internal classes

E
enter-result: Exported classes
enter-result: Exported classes

R
resource: Exported classes

S
saved-stream: Exported classes
Slot, callback-stack: Exported classes
Slot, check-subtypep: Exported classes
Slot, cnd: Internal classes
Slot, conditions: Exported classes
Slot, ctx: Internal classes
Slot, enter-result: Exported classes
Slot, enter-result: Exported classes
Slot, resource: Exported classes
Slot, saved-stream: Exported classes
Slot, stream: Exported classes
stream: Exported classes

Jump to:   C   E   R   S  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   C   D   E   I   M   N   P   R   S   W  
Index Entry  Section

C
Class, condition-ignoring-context: Exported classes
Class, context: Exported classes
Class, delegate-context: Exported classes
Class, error-context: Internal classes
Class, exit-stack-context: Exported classes
Class, managed-resource-context: Exported classes
Class, null-context: Exported classes
Class, redirect-context: Exported classes
Class, redirect-error-output-context: Exported classes
Class, redirect-input-context: Exported classes
Class, redirect-output-context: Exported classes
Class, redirect-standard-output-context: Exported classes
condition-ignoring-context: Exported classes
context: Exported classes

D
delegate-context: Exported classes

E
error-context: Internal classes
exit-stack-context: Exported classes

I
it.unimib.disco.ma.cl.ext.dacf.with-contexts: The it․unimib․disco․ma․cl․ext․dacf․with-contexts package

M
managed-resource-context: Exported classes

N
null-context: Exported classes

P
Package, it.unimib.disco.ma.cl.ext.dacf.with-contexts: The it․unimib․disco․ma․cl․ext․dacf․with-contexts package

R
redirect-context: Exported classes
redirect-error-output-context: Exported classes
redirect-input-context: Exported classes
redirect-output-context: Exported classes
redirect-standard-output-context: Exported classes

S
System, with-contexts: The with-contexts system

W
with-contexts: The with-contexts system

Jump to:   C   D   E   I   M   N   P   R   S   W