<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Comments on snippet: 'list-index (Scheme)'</title>
<link>http://snipplr.com</link>
<description>Snipplr comments feed'</description>
<language>en-us</language>
<pubDate>Mon, 20 May 2013 05:30:38 GMT</pubDate>
<item>
<title>random_number said on 12/13/09</title>
<link>http://snipplr.com/view/4576/listindex-scheme/</link>
<description><![CDATA[ switch the order of the first two conditional pairs so (empty? los) is checked before (first los) ]]></description>
<pubDate>Sun, 13 Dec 2009 00:21:40 GMT</pubDate>
<guid>http://snipplr.com/view/4576/listindex-scheme/</guid>
</item>
<item>
<title>random_number said on 12/12/09</title>
<link>http://snipplr.com/view/4576/listindex-scheme/</link>
<description><![CDATA[ Both versions could result in repeated recursion if los contains s as res has to be fully evaluated in order to determine if it equals -1. A helper function would come in handy. In Clojure:

<pre>
`
    (defn list-index  
      ([s los] (list-index 0 s los))  
      ([i s los]  
        (cond  
          (= (first los) s) i  
          (empty? los) -1  
          :else (recur (inc i) s (rest los)))))  
`
</pre> ]]></description>
<pubDate>Sat, 12 Dec 2009 23:03:36 GMT</pubDate>
<guid>http://snipplr.com/view/4576/listindex-scheme/</guid>
</item>
<item>
<title>the_coder said on 6/4/08</title>
<link>http://snipplr.com/view/4576/listindex-scheme/</link>
<description><![CDATA[ <p>Slightly better:</p>

<pre><code>(define (list-index s los)

  (cond ((null? los) -1)

        ((eq? s (car los)) 0)

        (else

         (let ((res (list-index s (cdr los))))

           (if (= res -1)

               -1

               (+ res 1))))))
</code></pre> ]]></description>
<pubDate>Wed, 04 Jun 2008 22:47:32 GMT</pubDate>
<guid>http://snipplr.com/view/4576/listindex-scheme/</guid>
</item>
</channel>
</rss>