From cbe382f6b3291faf6746b0e006398d19979f8cc5 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 7 Mar 2014 19:29:48 +0100 Subject: info: example of ordered and unordered join switches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- info/join-python.texinfo | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/info/join-python.texinfo b/info/join-python.texinfo index aef6641..4902787 100644 --- a/info/join-python.texinfo +++ b/info/join-python.texinfo @@ -230,6 +230,43 @@ the returned value is a tuple of the index of the selected join case (fragment group) and what @code{join} returned for that fragment group. +@cartouche +@example +>>> from join import * +>>> +>>> @@fragment +>>> def f1(): +>>> pass +>>> +>>> @@fragment +>>> def f2(): +>>> pass +>>> +>>> @@fragment +>>> def f3(): +>>> pass +>>> +>>> def ordered(): +>>> (case, (_jargs, _jkwargs, _jrc)) = ordered_join((f1,), (f2,), (f3,)) +>>> return case +>>> +>>> def unordered(): +>>> (case, (_jargs, _jkwargs, _jrc)) = unordered_join((f1,), (f2,), (f3,)) +>>> return case +>>> +>>> def switch(f): +>>> f1() +>>> f2() +>>> f3() +>>> return f() +>>> +>>> print([switch(ordered) for _ in range(10)]) +>>> print([switch(unordered) for _ in range(10)]) +[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] +[2, 2, 1, 0, 1, 2, 0, 1, 1, 2] # uniformally random +@end example +@end cartouche + @node GNU Free Documentation License -- cgit v1.2.3-70-g09d2