<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Mdemare's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 06 Oct 2008 17:02:49 GMT</pubDate>
    <description>DZone Snippets: Mdemare's Code Snippets</description>
    <item>
      <title>Rubylike slice for strings and lists</title>
      <link>http://snippets.dzone.com/posts/show/5055</link>
      <description>(slice "hello" 2 4) =&gt; "ll"&lt;br /&gt;Comparable to: "hello"[2...4]&lt;br /&gt;&lt;br /&gt;(slice "hello" 2 -1) =&gt; "ll"&lt;br /&gt;Comparable to: "hello"[2...-1]&lt;br /&gt;&lt;br /&gt;(slice "hello" '(2 2)) =&gt; "ll"&lt;br /&gt;Comparable to: "hello"[2,2]&lt;br /&gt;&lt;br /&gt;(slice "hello" 1) =&gt; "ello"&lt;br /&gt;Comparable to: "hello"[2..-1]&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;(def slice (str x (o y))&lt;br /&gt;  (if (atom x)&lt;br /&gt;    (if &lt;br /&gt;      ; (slice "hello" 1) =&gt; "ello"&lt;br /&gt;      (no y) &lt;br /&gt;        (subseq str x)&lt;br /&gt;      ; (slice "hello" 2 -1) =&gt; "ll"&lt;br /&gt;      (&lt; y 0) &lt;br /&gt;        (subseq str x (+ (len str) y))&lt;br /&gt;      ; (slice "hello" 2 4) =&gt; "ll"&lt;br /&gt;      (subseq str x y))&lt;br /&gt;    ; (slice "hello" '(2 2)) =&gt; "ll"&lt;br /&gt;    (subseq str (car x) (+ (car x) (cadr x)))))&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 30 Jan 2008 13:26:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5055</guid>
      <author>mdemare (Michiel de Mare)</author>
    </item>
  </channel>
</rss>
