1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
<!--
# VIP @lib/vip/html.l
# 10oct25 Software Lab. Alexander Burger
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Y</title>
<link rel="stylesheet" href="doc.css" type="text/css">
</head>
<body>
<h1>Y</h1>
<dl>
<dt><a id="yield"><code>(yield 'any ['any2] [. prg]) -> any</code></a></dt>
<dd>Transfers control from the current <a
href="ref.html#coroutines">coroutine</a> back to the caller (when the
<code>any2</code> tag is not given), or to some other coroutine
(specified by <code>any2</code>) to continue execution at the point
where that coroutine had called <code>yield</code> before. In the first
case, the value <code>any</code> will be returned from the corresponding
<code><a href="refC.html#co">co</a></code> call, in the second case it
will be the return value of that <code>yield</code> call. If
<code>prg</code> is given, it is executed in the destination environment
before the coroutine resumes execution. See also <code><a
href="refS.html#stack">stack</a></code>, <code><a
href="refC.html#catch">catch</a></code> and <code><a
href="refT.html#throw">throw</a></code>.
<pre>
: (co "rt1" # Start first routine
(msg (yield 1) " in rt1 from rt2") # Return '1', wait for value from "rt2"
7 ) # Then return '7'
-> 1
: (co "rt2" # Start second routine
(yield 2 "rt1") ) # Send '2' to "rt1"
2 in rt1 from rt2
-> 7
: (co 'a (let N 0 (loop (yield (inc 'N))))) # Incrementing coroutine
-> 1
: (co 'a T) # Next value
-> 2
: (yield NIL 'a (println N)) # Print value, then increment
2
-> 3
: (yield NIL 'a (println N))
3
-> 4
: (yield NIL 'a (yield N)) # Immediately yield back
-> 4 # Can be used to inspect a value
: (yield NIL 'a (yield N)) # in another coroutine
-> 4
: (co 'a T) # Next value
-> 5
: (yield NIL 'a (yield (env))) # Return the whole environment
</pre></dd>
<dt><a id="yoke"><code>(yoke 'any ..) -> any</code></a></dt>
<dd>Inserts one or several new elements <code>any</code> in front of the list in
the current <code><a href="refM.html#make">make</a></code> environment.
<code>yoke</code> returns the last inserted argument. See also <code><a
href="refL.html#link">link</a></code>, <code><a
href="refC.html#chain">chain</a></code> and <code><a
href="refM.html#made">made</a></code>.
<pre>
: (make (link 2 3) (yoke 1) (link 4))
-> (1 2 3 4)
</pre></dd>
</dl>
</body>
</html>
|