<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Scheme code kata</title>
	<atom:link href="http://programming-musings.org/2006/02/07/scheme-code-kata/feed/" rel="self" type="application/rss+xml" />
	<link>http://programming-musings.org/2006/02/07/scheme-code-kata/</link>
	<description>random thoughts on programming and programming languages</description>
	<lastBuildDate>Sun, 22 Apr 2012 00:53:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Richard Loveland</title>
		<link>http://programming-musings.org/2006/02/07/scheme-code-kata/#comment-31372</link>
		<dc:creator><![CDATA[Richard Loveland]]></dc:creator>
		<pubDate>Sat, 25 Feb 2012 13:41:26 +0000</pubDate>
		<guid isPermaLink="false">http://jaortega.wordpress.com/2006/02/07/scheme-code-kata/#comment-31372</guid>
		<description><![CDATA[Many years later, I&#039;ve discovered this post. My solution (inspired by Brian Harvey&#039;s from the abovementioned thread in c.l.s):

(define (p-&gt;a p)
  (cond ((null? p) &#039;())
	((symbol? (car p))
	 (cons (list (car p)
		     (gather-next-batch number? (cdr p)))
               (p-&gt;a (cdr p))))
	(else (p-&gt;a (cdr p)))))

(define (gather-next-batch pred seq)
  (cond ((null? seq) &#039;())
        ((pred (car seq))
         (cons (car seq)
               (gather-next-batch pred (cdr seq))))
        (else &#039;())))]]></description>
		<content:encoded><![CDATA[<p>Many years later, I&#8217;ve discovered this post. My solution (inspired by Brian Harvey&#8217;s from the abovementioned thread in c.l.s):</p>
<p>(define (p-&gt;a p)<br />
  (cond ((null? p) &#8216;())<br />
	((symbol? (car p))<br />
	 (cons (list (car p)<br />
		     (gather-next-batch number? (cdr p)))<br />
               (p-&gt;a (cdr p))))<br />
	(else (p-&gt;a (cdr p)))))</p>
<p>(define (gather-next-batch pred seq)<br />
  (cond ((null? seq) &#8216;())<br />
        ((pred (car seq))<br />
         (cons (car seq)<br />
               (gather-next-batch pred (cdr seq))))<br />
        (else &#8216;())))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A Scheme Code Kata &#171; the logic grimoire</title>
		<link>http://programming-musings.org/2006/02/07/scheme-code-kata/#comment-31371</link>
		<dc:creator><![CDATA[A Scheme Code Kata &#171; the logic grimoire]]></dc:creator>
		<pubDate>Fri, 24 Feb 2012 14:37:08 +0000</pubDate>
		<guid isPermaLink="false">http://jaortega.wordpress.com/2006/02/07/scheme-code-kata/#comment-31371</guid>
		<description><![CDATA[[...] beware! This is a meta-creature, a post about a post about a post. By way of comp.lang.scheme, the musings of the great jao (who incidentally is the Wizard behind Geiser (which is the way to Scheme with Emacs these days)), [...]]]></description>
		<content:encoded><![CDATA[<p>[...] beware! This is a meta-creature, a post about a post about a post. By way of comp.lang.scheme, the musings of the great jao (who incidentally is the Wizard behind Geiser (which is the way to Scheme with Emacs these days)), [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: msingh</title>
		<link>http://programming-musings.org/2006/02/07/scheme-code-kata/#comment-17454</link>
		<dc:creator><![CDATA[msingh]]></dc:creator>
		<pubDate>Wed, 23 May 2007 07:16:50 +0000</pubDate>
		<guid isPermaLink="false">http://jaortega.wordpress.com/2006/02/07/scheme-code-kata/#comment-17454</guid>
		<description><![CDATA[; i noticed that the reverse is nicer to work with:
; [4]&gt; (reverse &#039;(a 1 2 3 b 4 5 c d 8 9 e))
;                (E 9 8 D C 5 4 B 3 2 1 A)

(defun kata (list)
  (let ((list* (nreverse list))  
	(block)    
	(kata))
    (dolist (x list* kata) 
      (cond ((symbolp x)
	     (push (list x block) kata)
	     (setf block nil))
	    (t (push x block))))))

CL-USER&gt; (kata &#039;(a 1 2 3 b 4 5 c d 8 9 e))
((A (1 2 3)) (B (4 5)) (C NIL) (D (8 9)) (E NIL))]]></description>
		<content:encoded><![CDATA[<p>; i noticed that the reverse is nicer to work with:<br />
; [4]&gt; (reverse &#8216;(a 1 2 3 b 4 5 c d 8 9 e))<br />
;                (E 9 8 D C 5 4 B 3 2 1 A)</p>
<p>(defun kata (list)<br />
  (let ((list* (nreverse list))<br />
	(block)<br />
	(kata))<br />
    (dolist (x list* kata)<br />
      (cond ((symbolp x)<br />
	     (push (list x block) kata)<br />
	     (setf block nil))<br />
	    (t (push x block))))))</p>
<p>CL-USER&gt; (kata &#8216;(a 1 2 3 b 4 5 c d 8 9 e))<br />
((A (1 2 3)) (B (4 5)) (C NIL) (D (8 9)) (E NIL))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anthony</title>
		<link>http://programming-musings.org/2006/02/07/scheme-code-kata/#comment-5597</link>
		<dc:creator><![CDATA[Anthony]]></dc:creator>
		<pubDate>Sat, 25 Nov 2006 14:27:27 +0000</pubDate>
		<guid isPermaLink="false">http://jaortega.wordpress.com/2006/02/07/scheme-code-kata/#comment-5597</guid>
		<description><![CDATA[Hey!!!
Everybody..
Is there anybody that can give some tips in parogramming using scheme...
This is my subject this schoolyear..
Please!!!1]]></description>
		<content:encoded><![CDATA[<p>Hey!!!<br />
Everybody..<br />
Is there anybody that can give some tips in parogramming using scheme&#8230;<br />
This is my subject this schoolyear..<br />
Please!!!1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: siktir a.q.</title>
		<link>http://programming-musings.org/2006/02/07/scheme-code-kata/#comment-120</link>
		<dc:creator><![CDATA[siktir a.q.]]></dc:creator>
		<pubDate>Thu, 16 Mar 2006 16:13:37 +0000</pubDate>
		<guid isPermaLink="false">http://jaortega.wordpress.com/2006/02/07/scheme-code-kata/#comment-120</guid>
		<description><![CDATA[amınıza koyim sizin]]></description>
		<content:encoded><![CDATA[<p>amınıza koyim sizin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian G</title>
		<link>http://programming-musings.org/2006/02/07/scheme-code-kata/#comment-103</link>
		<dc:creator><![CDATA[Ian G]]></dc:creator>
		<pubDate>Tue, 28 Feb 2006 14:36:07 +0000</pubDate>
		<guid isPermaLink="false">http://jaortega.wordpress.com/2006/02/07/scheme-code-kata/#comment-103</guid>
		<description><![CDATA[Okay, here&#039;s a different take. Could be made shorter if you used let-values but this is the R5RS version.

&lt;pre&gt;
(define (plist-&gt;alist lst)
  (define (reduce l)
    (if (null? l)
        (values () ())
        (let ((head (car l))
              (tail (cdr l)))
          (call-with-values
              (lambda () (reduce tail))
            (lambda (non-symbols tail)
              (if (symbol? head)
                  (values ()
                          (cons (list head non-symbols) tail))
                  (values (cons head non-symbols) tail)))))))
  (call-with-values (lambda () (reduce lst))
    (lambda (ignore result) result)))
&lt;/pre&gt;
]]></description>
		<content:encoded><![CDATA[<p>Okay, here&#8217;s a different take. Could be made shorter if you used let-values but this is the R5RS version.</p>
<pre>
(define (plist->alist lst)
  (define (reduce l)
    (if (null? l)
        (values () ())
        (let ((head (car l))
              (tail (cdr l)))
          (call-with-values
              (lambda () (reduce tail))
            (lambda (non-symbols tail)
              (if (symbol? head)
                  (values ()
                          (cons (list head non-symbols) tail))
                  (values (cons head non-symbols) tail)))))))
  (call-with-values (lambda () (reduce lst))
    (lambda (ignore result) result)))
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Buchholz</title>
		<link>http://programming-musings.org/2006/02/07/scheme-code-kata/#comment-89</link>
		<dc:creator><![CDATA[Greg Buchholz]]></dc:creator>
		<pubDate>Mon, 13 Feb 2006 20:57:54 +0000</pubDate>
		<guid isPermaLink="false">http://jaortega.wordpress.com/2006/02/07/scheme-code-kata/#comment-89</guid>
		<description><![CDATA[The Haskell language list library has an interesting function &lt;a href=&quot;http://www.haskell.org/onlinereport/list.html&quot; rel=&quot;nofollow&quot;&gt;&quot;groupBy&quot;&lt;/a&gt;with a nice concise definition.  You&#039;d use it like...

&lt;code&gt;
import Data.List

data Sym = A &#124; B &#124; C &#124; D &#124; E deriving Show
data Foo = S Sym &#124; N Integer 

instance Show Foo where
    show (S x) = show x
    show (N x) = show x

main = print $ 
        map (\x -&gt; (head x, tail x))
            (groupBy nums [ S A, N 1, N 2, N 3,       
                            S B, N 4, N 5,
                            S C,
                            S D, N 8, N 9,
                            S E                 ])

nums (S _) (N _) = True  --A symbol followed by a number is good group
nums (N _) (N _) = True  --A number followed by a number is good group
nums _     _     = False --Anything else needs a new grouping

&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>The Haskell language list library has an interesting function <a href="http://www.haskell.org/onlinereport/list.html" rel="nofollow">&#8220;groupBy&#8221;</a>with a nice concise definition.  You&#8217;d use it like&#8230;</p>
<p><code><br />
import Data.List</p>
<p>data Sym = A | B | C | D | E deriving Show<br />
data Foo = S Sym | N Integer </p>
<p>instance Show Foo where<br />
    show (S x) = show x<br />
    show (N x) = show x</p>
<p>main = print $<br />
        map (\x -&gt; (head x, tail x))<br />
            (groupBy nums [ S A, N 1, N 2, N 3,<br />
                            S B, N 4, N 5,<br />
                            S C,<br />
                            S D, N 8, N 9,<br />
                            S E                 ])</p>
<p>nums (S _) (N _) = True  --A symbol followed by a number is good group<br />
nums (N _) (N _) = True  --A number followed by a number is good group<br />
nums _     _     = False --Anything else needs a new grouping</p>
<p></code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Greer</title>
		<link>http://programming-musings.org/2006/02/07/scheme-code-kata/#comment-88</link>
		<dc:creator><![CDATA[Kevin Greer]]></dc:creator>
		<pubDate>Mon, 13 Feb 2006 15:18:06 +0000</pubDate>
		<guid isPermaLink="false">http://jaortega.wordpress.com/2006/02/07/scheme-code-kata/#comment-88</guid>
		<description><![CDATA[Here&#039;s my solution which is O(n) and doesn&#039;t  use any built-in list processing functions like reverse, append, map, fold, etc.  Just cons, car, and cdr.

&lt;pre&gt;
(define (plist-&gt;alist l)
  (define (f l)
        (if (null? l)
           &#039;(())
           (let* ((rest (f (cdr l)))
                  (cur  (cons (cons (car l) (car rest)) (cdr rest))))
                      (if (symbol? (car l)) (cons &#039;() cur) cur))))
  (cdr (f l)))
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Here&#8217;s my solution which is O(n) and doesn&#8217;t  use any built-in list processing functions like reverse, append, map, fold, etc.  Just cons, car, and cdr.</p>
<pre>
(define (plist->alist l)
  (define (f l)
        (if (null? l)
           '(())
           (let* ((rest (f (cdr l)))
                  (cur  (cons (cons (car l) (car rest)) (cdr rest))))
                      (if (symbol? (car l)) (cons '() cur) cur))))
  (cdr (f l)))
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andi</title>
		<link>http://programming-musings.org/2006/02/07/scheme-code-kata/#comment-79</link>
		<dc:creator><![CDATA[Andi]]></dc:creator>
		<pubDate>Thu, 09 Feb 2006 20:51:33 +0000</pubDate>
		<guid isPermaLink="false">http://jaortega.wordpress.com/2006/02/07/scheme-code-kata/#comment-79</guid>
		<description><![CDATA[relatively new to scheme, judging by some c.l.s submissions i am not thinking functional enough just yet:

&lt;pre&gt;
(define (bucketize lis)
  (cond ((null? lis) &#039;())
        ((not (symbol? (car lis))) (error &quot;expected a symbol&quot;))
        (else
         (let LOOP ((args &#039;()) (lis2 (cdr lis)))
           (cond ((null? lis2) (list (list (car lis) (reverse args))))
                 ((symbol? (car lis2)) (cons (list (car lis) (reverse args)) (bucketize lis2)))
                 (else (LOOP (cons (car lis2) args) (cdr lis2))))))))
&lt;/pre&gt;
]]></description>
		<content:encoded><![CDATA[<p>relatively new to scheme, judging by some c.l.s submissions i am not thinking functional enough just yet:</p>
<pre>
(define (bucketize lis)
  (cond ((null? lis) '())
        ((not (symbol? (car lis))) (error "expected a symbol"))
        (else
         (let LOOP ((args '()) (lis2 (cdr lis)))
           (cond ((null? lis2) (list (list (car lis) (reverse args))))
                 ((symbol? (car lis2)) (cons (list (car lis) (reverse args)) (bucketize lis2)))
                 (else (LOOP (cons (car lis2) args) (cdr lis2))))))))
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: willyh</title>
		<link>http://programming-musings.org/2006/02/07/scheme-code-kata/#comment-72</link>
		<dc:creator><![CDATA[willyh]]></dc:creator>
		<pubDate>Tue, 07 Feb 2006 20:23:07 +0000</pubDate>
		<guid isPermaLink="false">http://jaortega.wordpress.com/2006/02/07/scheme-code-kata/#comment-72</guid>
		<description><![CDATA[Okay, here&#039;s mine:

&lt;pre&gt;
(define (segregate-list l)
  (let segregate ((key (car l))
                  (test-pred? number?)
                  (input-list (cdr l))
                  (key-list &#039;())
                  (output-list &#039;()))
    (if (null? input-list)
      (reverse (cons (cons key (list (reverse key-list))) output-list))
      (if (not (test-pred? (car input-list)))
          (segregate (car input-list)
                     test-pred?
                     (cdr input-list)
                     &#039;()
                     (cons (cons key (list (reverse key-list)))
                           output-list))
          (segregate key
                     test-pred?
                     (cdr input-list)
                     (cons (car input-list) key-list)
                     output-list)))))
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Okay, here&#8217;s mine:</p>
<pre>
(define (segregate-list l)
  (let segregate ((key (car l))
                  (test-pred? number?)
                  (input-list (cdr l))
                  (key-list '())
                  (output-list '()))
    (if (null? input-list)
      (reverse (cons (cons key (list (reverse key-list))) output-list))
      (if (not (test-pred? (car input-list)))
          (segregate (car input-list)
                     test-pred?
                     (cdr input-list)
                     '()
                     (cons (cons key (list (reverse key-list)))
                           output-list))
          (segregate key
                     test-pred?
                     (cdr input-list)
                     (cons (car input-list) key-list)
                     output-list)))))
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>

