From 9224412274e1e1a31a959083bb257a7d6ab2b113 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 19 Aug 2016 20:40:12 -0400 Subject: Add Sly manual. --- manuals/sly/Coroutines.html | 134 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 manuals/sly/Coroutines.html (limited to 'manuals/sly/Coroutines.html') diff --git a/manuals/sly/Coroutines.html b/manuals/sly/Coroutines.html new file mode 100644 index 0000000..26e5c73 --- /dev/null +++ b/manuals/sly/Coroutines.html @@ -0,0 +1,134 @@ + + + + + +Sly: Coroutines + + + + + + + + + + + + + + + + + + + + +
+

+Next: , Previous: , Up: Time   [Contents][Index]

+
+
+ +

4.3.2 Coroutines

+ +
+
(use-modules (sly coroutine))
+
+ +

Coroutines are the building block for cooperative multitasking. When +used with agendas, they are a powerful mechanism for writing +algorithms that span multiple clock ticks in a straightforward, linear +fashion. Sly’s coroutines are built on top of Guile’s delimited +continuations, called prompts. +

+

To run a procedure as a coroutine, use the call-with-coroutine +procedure. Once inside the coroutine prompt, the yield +procedure can be used to pause the procedure and pass its continuation +to a callback procedure. The callback may call the continuation at +its convenience, resuming the original procedure. +

+

Coroutines are particularly useful in conjunction with Agendas. +

+
+
Scheme Procedure: call-with-coroutine thunk
+

Apply thunk within a coroutine prompt. +

+ +
+
Scheme Syntax: coroutine body
+

Evaluate body within a coroutine prompt. +

+ +
+
Scheme Syntax: colambda args body
+

Syntacic sugar for a lambda expression whose body is run +within a coroutine prompt. +

+ +
+
Scheme Syntax: codefine (name formals …) body
+

Syntacic sugar for defining a procedure called name with formal +arguments formals whose body is run within a coroutine +prompt. +

+ +
+
Scheme Syntax: codefine* (name formals …) body
+

Syntacic sugar for defining a procedure called name with +optional and keyword arguments formals whose body is run +within a coroutine prompt. +

+ +
+
Scheme Procedure: yield callback
+

Yield continuation to the procedure callback. +

+ + + + + + -- cgit v1.2.3