Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| doc:plans [2014/01/13 10:07] – [with-policy] winkler | doc:plans [2015/05/11 17:06] (current) – gkazhoya | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | //**Note:** this page is deprecated. Please use [[tutorials: | ||
| + | |||
| ====== Writing Plans ====== | ====== Writing Plans ====== | ||
| Line 21: | Line 23: | ||
| <code lisp> | <code lisp> | ||
| (define-policy my-policy (max-num match-num) | (define-policy my-policy (max-num match-num) | ||
| - | | + | "This is an example policy." |
| (:init (format t " | (:init (format t " | ||
| t) | t) | ||
| Line 43: | Line 45: | ||
| | | ||
| </ | </ | ||
| + | |||
| + | === Exception handling === | ||
| + | When policies are used, multiple failures can be signalled. The most meaningful of those are | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | If one wants to monitor the triggering of a policy' | ||
| + | <code lisp> | ||
| + | (top-level | ||
| + | (with-failure-handling | ||
| + | ((policy-check-condition-met (f) | ||
| + | | ||
| + | | ||
| + | | ||
| + | (with-named-policy ' | ||
| + | (loop do (format t "Main loop cycle.~%" | ||
| + | | ||
| + | </ | ||
| + | |||
| + | === Using multiple policies at once === | ||
| + | When multiple policies are to be used (either a mix of different policies, or the same policy multiple times, each with different parameters), | ||
| + | |||
| + | When policy instances by the names '' | ||
| + | <code lisp> | ||
| + | (with-policies | ||
| + | ((my-policy-object (3 1)) | ||
| + | | ||
| + | | ||
| + | (body-code)) | ||
| + | </ | ||
| + | In this example, the resulting code will be equivalent to the following: | ||
| + | <code lisp> | ||
| + | (with-policy my-policy-object (3 1) | ||
| + | (with-policy my-policy-object (100 4) | ||
| + | (with-policy my-other-policy-object (" | ||
| + | (body-code)))) | ||
| + | </ | ||
| + | |||
| + | The same princple applies to '' | ||
| + | <code lisp> | ||
| + | (with-named-policies | ||
| + | ((' | ||
| + | | ||
| + | | ||
| + | (body-code)) | ||
| + | </ | ||
| + | This results in the same behavior as: | ||
| + | <code lisp> | ||
| + | (with-named-policy ' | ||
| + | (with-named-policy ' | ||
| + | (with-named-policy ' | ||
| + | (body-code)))) | ||
| + | </ | ||
| + | |||
| + | === Built-in Policies === | ||
| + | == timeout-policy == | ||
| + | When a piece of code only has a limited maximum amount of time for execution (and must be aborted after that duration), the '' | ||
| + | |||
| + | Use it like this: | ||
| + | <code lisp> | ||
| + | (with-policy cpl: | ||
| + | (body-code-goes-here)) | ||
| + | </ | ||
| + | And for catching the check condition when the timeout actually happens: | ||
| + | <code lisp> | ||
| + | (with-failure-handling | ||
| + | ((policy-check-condition-met (f) | ||
| + | (declare (ignore f)) | ||
| + | (handle-error-here-and-maybe-retry))) | ||
| + | (with-policy cpl: | ||
| + | (body-code-goes-here))) | ||
| + | </ | ||
| + | The '' | ||

