Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > e3918135d52936bad0ecc8654eedea12 > files > 57

Falcon-doc-0.9.6.8-1.fc15.noarch.rpm

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
<head><meta content="text/html;charset=&amp;quot;utf-8&amp;quot;" http-equiv="Content-type"/><link href="faldoc.css" rel="stylesheet" type="text/css"/><title> - Class Sequence</title></head><body class="faldoc"><ul class="navi_top"><li class="top"><a href="index.html">Top: Table of contents</a></li>
         <li class="up"><a href="core.html">Up: The core module</a></li>
         <li class="prev"><a href="core_Path.html">Previous: Class Path</a></li>
         <li class="next"><a href="core_Set.html">Next: Class Set</a></li>
         <li class="clear"></li>
         </ul><div id="page_body"><h1><span class="toc_number">1.32</span>Class Sequence</h1><p class="brief">Base abstract class for VM assisted sequences. </p>
         <pre class="prototype">Class Sequence</pre>
         <p>This class is meant to provide common methods to VM-assisted (that is, language level) sequence classes. You can't derive directly from this class unless you're writing a native module, but you can derive from script-visible classes children of this one. </p>
<table class="members">
         <tbody><tr class="member_type"><td class="member_type" colspan="2">Methods</td></tr>
               <tr><td><a href="#append">append</a></td><td>Adds an item at the end of the sequence. </td></tr>
               <tr><td><a href="#back">back</a></td><td>Returns the last item in the Sequence. </td></tr>
               <tr><td><a href="#clear">clear</a></td><td>Removes all the items from the Sequence. </td></tr>
               <tr><td><a href="#comp">comp</a></td><td>Appends elements to this sequence through a filter. </td></tr>
               <tr><td><a href="#empty">empty</a></td><td>Checks if the Sequence is empty or not. </td></tr>
               <tr><td><a href="#first">first</a></td><td>Returns an iterator to the first element of the Sequence. </td></tr>
               <tr><td><a href="#front">front</a></td><td>Returns the first item in the Sequence. </td></tr>
               <tr><td><a href="#last">last</a></td><td>Returns an iterator to the last element of the Sequence. </td></tr>
               <tr><td><a href="#mcomp">mcomp</a></td><td>Appends elements to this sequence from multiple sources. </td></tr>
               <tr><td><a href="#mfcomp">mfcomp</a></td><td>Appends elements to this sequence from multiple sources through a filter. </td></tr>
               <tr><td><a href="#prepend">prepend</a></td><td>Adds an item in front of the sequence </td></tr>
               </tbody>
            </table>
         <h2>Methods</h2><h3><a name="append">append</a></h3><p class="brief">Adds an item at the end of the sequence. </p>
         <pre class="prototype">Sequence.append( item )</pre>
         <table class="prototype">
         <tbody><tr class="param"><td class="name">item</td><td class="content"> The item to be added. </td></tr>
               </tbody>
            </table>
         <p>If the sequence is sorted, the position at which the <b>item</b> is inserted is determined by the internal ordering; otherwise the <b>item</b> is appended at the end of the sequence. </p>
<h3><a name="back">back</a></h3><p class="brief">Returns the last item in the Sequence. </p>
         <pre class="prototype">Sequence.back()</pre>
         <table class="prototype">
         <tbody><tr class="return"><td class="name">Return</td><td class="content">The last item in the Sequence. </td></tr>
               <tr class="raise"><td class="name">Raise</td><td class="content"><table>
                     <tbody><tr><td class="name"><a href="core_AccessError.html">AccessError</a></td><td class="content"> if the Sequence is empty. </td></tr>
                           </tbody>
                        </table>
                     </td></tr>
               </tbody>
            </table>
         <p>This method overloads the BOM method <b>back.</b> If the Sequence is not empty, it returns the last element. </p>
<h3><a name="clear">clear</a></h3><p class="brief">Removes all the items from the Sequence. </p>
         <pre class="prototype">Sequence.clear()</pre>
         <h3><a name="comp">comp</a></h3><p class="brief">Appends elements to this sequence through a filter. </p>
         <pre class="prototype">Sequence.comp( source, [filter] )</pre>
         <table class="prototype">
         <tbody><tr class="param"><td class="name">source</td><td class="content"> A sequence, a range or a callable generating items. </td></tr>
               <tr class="optparam"><td class="name">filter</td><td class="content"> A filtering function receiving one item at a time. </td></tr>
               <tr class="return"><td class="name">Return</td><td class="content">This sequence. </td></tr>
               </tbody>
            </table>
         <p>This method adds one item at a time to this Sequence. </p>
<p>If <b>source</b> is a range, (must not be open), all the values generated by the range will be appended, considering range direction and step. </p>
<p>If <b>source</b> is a sequence (array, dictionary, or any other object providing the sequence interface), all the values in the item will be appended to this Sequence. </p>
<p>If <b>source</b> is a callable item, it is called repeatedly to generate the sequence. All the items it returns will be appended, until it declares being terminated by returning an oob(0). Continuation objects are also supported. </p>
<p>If a <b>filter</b> callable is provided, all the items that should be appended are first passed to to it; the item returned by the callable will be used instead of the item provided in <b>source.</b> The <b>filter</b> may return an out of band 1 to skip the item from <b>source,</b> or an out of band 0 to stop the processing altogether. The  <b>filter</b> callable receives also the forming sequence as the second parameter so that it account for it or manage it dynamically during the filter step. </p>
<p>For example, the following comprehension creates a dictionary associating a letter of the alphabet to each element in the source sequence, discarding elements with spaces and terminating when a "<end>" mark is found. The <b>filter</b> function uses the second parameter to determine how many items have been added, and return a different element each time. </p>
<pre>

      dict = [=&gt;].comp(
         // the source
         .[ 'bananas' 'skip me' 'apples' 'oranges' '&lt;end&gt;' 'melons' ],
         // the filter
         { element, dict =&gt;
           if " " in element: return oob(1)
           if "&lt;end&gt;" == element: return oob(0)
           return [ "A" / len(dict), element ]   // (1)
         }
      )

      // (1): "A" / number == chr( ord("A") + number )
</pre><p>This method actually adds each item in the comprehension to the sequence or sequence-compatible item in self. This means that comprehension needs not to be performed on a new, empty sequence; it may be also used to integrate more data in already existing sequences. </p>
<p class="see_also">See also: <a href="core_Array.html">Array</a>, <a href="core_Dictionary.html">Dictionary</a>, <a href="core_Object.html">Object</a>.</p>
         <h3><a name="empty">empty</a></h3><p class="brief">Checks if the Sequence is empty or not. </p>
         <pre class="prototype">Sequence.empty()</pre>
         <table class="prototype">
         <tbody><tr class="return"><td class="name">Return</td><td class="content">True if the Sequence is empty, false if contains some elements. </td></tr>
               </tbody>
            </table>
         <h3><a name="first">first</a></h3><p class="brief">Returns an iterator to the first element of the Sequence. </p>
         <pre class="prototype">Sequence.first()</pre>
         <table class="prototype">
         <tbody><tr class="return"><td class="name">Return</td><td class="content">An iterator. </td></tr>
               </tbody>
            </table>
         <p>Returns an iterator to the first element of the Sequence. If the Sequence is empty, an invalid iterator will be returned, but an insertion on that iterator will succeed and append an item to the Sequence. </p>
<h3><a name="front">front</a></h3><p class="brief">Returns the first item in the Sequence. </p>
         <pre class="prototype">Sequence.front()</pre>
         <table class="prototype">
         <tbody><tr class="return"><td class="name">Return</td><td class="content">The first item in the Sequence. </td></tr>
               <tr class="raise"><td class="name">Raise</td><td class="content"><table>
                     <tbody><tr><td class="name"><a href="core_AccessError.html">AccessError</a></td><td class="content"> if the Sequence is empty. </td></tr>
                           </tbody>
                        </table>
                     </td></tr>
               </tbody>
            </table>
         <p>This method overloads the BOM method <b>front.</b> If the Sequence is not empty, it returns the first element. </p>
<h3><a name="last">last</a></h3><p class="brief">Returns an iterator to the last element of the Sequence. </p>
         <pre class="prototype">Sequence.last()</pre>
         <table class="prototype">
         <tbody><tr class="return"><td class="name">Return</td><td class="content">An iterator. </td></tr>
               </tbody>
            </table>
         <p>Returns an iterator to the last element of the Sequence. If the Sequence is empty, an invalid iterator will be returned, but an insertion on that iterator will succeed and append an item to the Sequence. </p>
<h3><a name="mcomp">mcomp</a></h3><p class="brief">Appends elements to this sequence from multiple sources. </p>
         <pre class="prototype">Sequence.mcomp( ... )</pre>
         <table class="prototype">
         <tbody><tr class="param"><td class="name">...</td><td class="content"> One or more sequences, ranges or callables generating items. </td></tr>
               <tr class="return"><td class="name">Return</td><td class="content">This sequence. </td></tr>
               </tbody>
            </table>
         <p>This method works as <a href="core_Sequence.html#comp">Sequence.comp</a> but it's possible to specify more items and sequences. Each element in the result set is an array of items in which each element extracted from a source or returned by a generator is combined with all the others. </p>
<p>For example, the following operation: </p>
<pre>

      [].mcomp( [1,2], [3,4] )
</pre><p>results in: </p>
<pre>

      [ [1,3], [1,4], [2,3], [2,4] ]
</pre><p>Generators are called repeatedly until they exhaust all the items they can generate, in the same order as they are declared in the <b>mcomp</b> call. </p>
<p>For example: </p>
<pre>

      [].mcomp( alphagen, betagen )
</pre><p>will first call alphagen until it returns an oob(0), and then call betagen repeatedly. </p>
<p class='note'><b>Note:</b> Calls in this context are not atomic. Suspension, sleep, I/O, and continuations are allowed and supported. </p>
<p>After all the generators are called, the collected data is mixed with static data coming from other sources. For example: </p>
<pre>

      function make_gen( count, name )
         i = 0
         return {=&gt;
            if i == count: return oob(0)
            &gt; name, ": ", i
            return i++
            }
      end

      &gt; [].mcomp( ["a","b"], make_gen(2, "first"), make_gen(2, "second") ).describe()
</pre><p>will generate the following output: </p>
<pre>

      first: 0
      first: 1
      second: 0
      second: 1
      [ [ "a", 0, 0], [ "a", 0, 1], [ "a", 1, 0], [ "a", 1, 1],
         [ "b", 0, 0], [ "b", 0, 1], [ "b", 1, 0], [ "b", 1, 1]]
</pre><p class='note'><b>Note:</b> The <a href="core_Sequence.html#mfcomp">Sequence.mfcomp</a> provides a more flexible approach. </p>
<p class="see_also">See also: <a href="core_Array.html">Array</a>, <a href="core_Dictionary.html">Dictionary</a>, <a href="core_Object.html">Object</a>.</p>
         <h3><a name="mfcomp">mfcomp</a></h3><p class="brief">Appends elements to this sequence from multiple sources through a filter. </p>
         <pre class="prototype">Sequence.mfcomp( filter, ... )</pre>
         <table class="prototype">
         <tbody><tr class="param"><td class="name">filter</td><td class="content"> A filtering function receiving one item at a time. </td></tr>
               <tr class="param"><td class="name">...</td><td class="content"> One or more sequences, ranges or callables generating items. </td></tr>
               <tr class="return"><td class="name">Return</td><td class="content">This sequence. </td></tr>
               </tbody>
            </table>
         <p>This function works exactly as <a href="core_Sequence.html#mcomp">Sequence.mcomp</a>, with the difference that the elements generated are passed to a filter function for final delivery to the target sequence. </p>
<p class='note'><b>Note:</b> The <b>filter</b> parameter is optional; if <b>nil</b> is passed to it, this method works exactly as <a href="core_Sequence.html#mcomp">Sequence.mcomp</a>. </p>
<p>For example, the math set operation </p>
<pre>

      { x*y for x in 1,2,3 and y in 4,5,6 }
</pre><p>can be written using mfcomp like the following: </p>
<pre>

      [].mfcomp( {x, y =&gt; x*y}, .[1 2 3], .[4 5 6] )
</pre><p>which results in </p>
<pre>

        [ 4, 5, 6, 8, 10, 12, 12, 15, 18]
</pre><p>The as for <a href="core_Sequence.html#comp">Sequence.comp</a>, filter receives an extra parameter which is the sequence itself. For example, the following code: </p>
<pre>

      &gt; [].mfcomp( {x, y, seq =&gt;
                     printl( "Seq is now long: " + seq.len() )
                     return [seq.len(), x*y]
                     },
                  .[1 2 3], .[4 5 6]
                  ).describe()
</pre><p>generates this output: </p>
<pre>

      Seq is now long: 0
      Seq is now long: 1
      Seq is now long: 2
      Seq is now long: 3
      Seq is now long: 4
      Seq is now long: 5
      Seq is now long: 6
      Seq is now long: 7
      Seq is now long: 8
      [ [ 0, 4], [ 1, 5], [ 2, 6], [ 3, 8], [ 4, 10], [ 5, 12], [ 6, 12], [ 7, 15], [ 8, 18]]
</pre><p>Notice that it is possible to modify the sequence inside the filter, in case it's needed. </p>
<p>The filter may return an oob(1) to skip the value, and an oob(0) to terminate the operation. For example, the following code s </p>
<p class='note'><b>Note:</b> The call Sequence.mfcomp( filter, seq ) is equivalent to Sequence.comp( seq, filter ). </p>
<p class="see_also">See also: <a href="core_Array.html">Array</a>, <a href="core_Dictionary.html">Dictionary</a>, <a href="core_Object.html">Object</a>.</p>
         <h3><a name="prepend">prepend</a></h3><p class="brief">Adds an item in front of the sequence </p>
         <pre class="prototype">Sequence.prepend( item )</pre>
         <table class="prototype">
         <tbody><tr class="param"><td class="name">item</td><td class="content"> The item to be added. </td></tr>
               </tbody>
            </table>
         <p>If the sequence is sorted, the position at which the <b>item</b> is inserted is determined by the internal ordering; otherwise the <b>item</b> is prepended in front of the sequence. </p>
</div><ul class="navi_bottom"><li class="top"><a href="index.html">Top: Table of contents</a></li>
         <li class="up"><a href="core.html">Up: The core module</a></li>
         <li class="prev"><a href="core_Path.html">Previous: Class Path</a></li>
         <li class="next"><a href="core_Set.html">Next: Class Set</a></li>
         <li class="clear"></li>
         </ul><div class="signature">Made with <a href="faldoc 3.0">http://www.falconpl.org</a></div></body></html>