<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: excerpt code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 06 Sep 2008 17:15:33 GMT</pubDate>
    <description>DZone Snippets: excerpt code</description>
    <item>
      <title>excerpt function</title>
      <link>http://snippets.dzone.com/posts/show/1131</link>
      <description>&lt;code&gt;&lt;br /&gt;    ;-- collect-based EXCERPT ----------------------------------&lt;br /&gt;    ; Could also change EXTRACT to accept a block value for WIDTH&lt;br /&gt;    ; (renamed to, e.g., SPEC).&lt;br /&gt;    ; The dialect allows you to use commas in the block, but how they&lt;br /&gt;    ; are interpreted is not how you might think. Coming after a number,&lt;br /&gt;    ; they are a valid lexical form, but they denote a decimal! rather&lt;br /&gt;    ; than being seen as a separator, which means you can't use them too&lt;br /&gt;    ; flexibly.&lt;br /&gt;    excerpt: func [&lt;br /&gt;        {Returns the specified items and/or ranges from the series.}&lt;br /&gt;        series  [series!]&lt;br /&gt;        offsets [block!] {Offsets of the items to extract; dialected.}&lt;br /&gt;        /only "return sub-block ranges as blocks"&lt;br /&gt;        /local&lt;br /&gt;            emit-range rules&lt;br /&gt;            from* to* index*    ; parse vars&lt;br /&gt;    ][&lt;br /&gt;        ; always uses ONLY right now; it's a prototype.&lt;br /&gt;        collect/only val [&lt;br /&gt;            emit-range: func [start end] [&lt;br /&gt;                start: to integer! start&lt;br /&gt;                if number? end [end: to integer! end - start + 1]&lt;br /&gt;                val: either end = 'end [copy at series start][&lt;br /&gt;                    copy/part at series start end&lt;br /&gt;                ]&lt;br /&gt;            ]&lt;br /&gt;            rules: [&lt;br /&gt;                some [&lt;br /&gt;                    opt 'from set from* number! 'to set to* number! (&lt;br /&gt;                        emit-range from* to*&lt;br /&gt;                    )&lt;br /&gt;                  | opt 'from set from* number! 'to 'end (emit-range from* 'end)&lt;br /&gt;                  | 'to set to* number! (emit-range 1 to*)&lt;br /&gt;                  | set index* number!  (val: pick series index*)&lt;br /&gt;                  | into rules&lt;br /&gt;                ]&lt;br /&gt;            ]&lt;br /&gt;            parse offsets rules&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;    comment {&lt;br /&gt;        b: [1 2 3 4 5 6 7 8 9 10 11 12 13 14]&lt;br /&gt;        excerpt b [1 3 5]&lt;br /&gt;        excerpt b [1 3 to 6 8]&lt;br /&gt;        excerpt/only b [1, 3 to 6, 8]&lt;br /&gt;        excerpt b [1 [5 to 7] 8]&lt;br /&gt;        excerpt/only b [1 (from 5 to 7) 8]&lt;br /&gt;        excerpt b [(to 2) [4 to 6] 8, 10, from 12 to end]&lt;br /&gt;        excerpt/only b [to 2, 4 to 6, 8, 10, (12 to end)]&lt;br /&gt;        ; Can't use a comma after 'end&lt;br /&gt;        excerpt/only b [to 2 to 6 8 10 to end 12 to end]&lt;br /&gt;        excerpt/only b [to 2, to 6, 8 [10 to end] 12 to end]&lt;br /&gt;        excerpt/only trim {&lt;br /&gt;            REBOL is my favorite language&lt;br /&gt;        } [&lt;br /&gt;            to 5, 10 to 11, 13, 14, 15, 22 to end&lt;br /&gt;        ]&lt;br /&gt;        excerpt/only to binary! {REBOL is my favorite language} [&lt;br /&gt;            to 5, 10 to 11, 13, 14, 15, 22 to end&lt;br /&gt;        ]&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 10 Jan 2006 06:27:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1131</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
  </channel>
</rss>
