<?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: Standard Prelude</title>
	<atom:link href="http://programmingpraxis.com/contents/standard-prelude/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingpraxis.com</link>
	<description>A collection of etudes, updated weekly, for the education and enjoyment of the savvy programmer</description>
	<lastBuildDate>Mon, 28 May 2012 03:30:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: programmingpraxis</title>
		<link>http://programmingpraxis.com/contents/standard-prelude/#comment-2791</link>
		<dc:creator><![CDATA[programmingpraxis]]></dc:creator>
		<pubDate>Sat, 02 Apr 2011 00:41:07 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?page_id=187#comment-2791</guid>
		<description><![CDATA[The original version of &lt;code&gt;ipow&lt;/code&gt;, which appears below, was not tail-recursive; it has been replaced with a version that is properly tail-recursive:

&lt;code&gt;(define (ipow b e)
&#160;&#160;(cond ((zero? e) 1)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;((even? e) (ipow (* b b) (&#047; e 2)))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(else (* b (ipow (* b b) (&#047; (- e 1) 2))))))&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>The original version of <code>ipow</code>, which appears below, was not tail-recursive; it has been replaced with a version that is properly tail-recursive:</p>
<p><code>(define (ipow b e)<br />
&nbsp;&nbsp;(cond ((zero? e) 1)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((even? e) (ipow (* b b) (&#047; e 2)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(else (* b (ipow (* b b) (&#047; (- e 1) 2))))))</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: programmingpraxis</title>
		<link>http://programmingpraxis.com/contents/standard-prelude/#comment-2790</link>
		<dc:creator><![CDATA[programmingpraxis]]></dc:creator>
		<pubDate>Sat, 02 Apr 2011 00:22:17 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?page_id=187#comment-2790</guid>
		<description><![CDATA[The Standard Prelude at one time included a function to generate the permutations of a list.  That function has been removed because it is too specific for a general-purpose Standard Prelude.  The original function, with its description, appears below:

It is sometimes useful to generate a list of the permutations of a list. The function below is from Shmuel Zaks, A new algorithm for generation of permutations, Technical Report 220, Technion-Israel Institute of Technology, 1981:

&lt;code&gt;(define (permutations xs)
&#160;&#160;(define (rev xs n ys)
&#160;&#160;&#160;&#160;(if (zero? n) ys
&#160;&#160;&#160;&#160;&#160;&#160;(rev (cdr xs) (- n 1) (cons (car xs) ys))))
&#160;&#160;(let ((xs xs) (perms (list xs)))
&#160;&#160;&#160;&#160;(define (perm n)
&#160;&#160;&#160;&#160;&#160;&#160;(if (&gt; n 1)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(do ((j (- n 1) (- j 1)))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;((zero? j) (perm (- n 1)))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(perm (- n 1))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(set! xs (rev xs n (list-tail xs n)))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(set! perms (cons xs perms)))))
&#160;&#160;&#160;&#160;(perm (length xs))
&#160;&#160;&#160;&#160;perms))&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>The Standard Prelude at one time included a function to generate the permutations of a list.  That function has been removed because it is too specific for a general-purpose Standard Prelude.  The original function, with its description, appears below:</p>
<p>It is sometimes useful to generate a list of the permutations of a list. The function below is from Shmuel Zaks, A new algorithm for generation of permutations, Technical Report 220, Technion-Israel Institute of Technology, 1981:</p>
<p><code>(define (permutations xs)<br />
&nbsp;&nbsp;(define (rev xs n ys)<br />
&nbsp;&nbsp;&nbsp;&nbsp;(if (zero? n) ys<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(rev (cdr xs) (- n 1) (cons (car xs) ys))))<br />
&nbsp;&nbsp;(let ((xs xs) (perms (list xs)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;(define (perm n)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(if (&gt; n 1)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(do ((j (- n 1) (- j 1)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((zero? j) (perm (- n 1)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(perm (- n 1))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(set! xs (rev xs n (list-tail xs n)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(set! perms (cons xs perms)))))<br />
&nbsp;&nbsp;&nbsp;&nbsp;(perm (length xs))<br />
&nbsp;&nbsp;&nbsp;&nbsp;perms))</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: programmingpraxis</title>
		<link>http://programmingpraxis.com/contents/standard-prelude/#comment-1548</link>
		<dc:creator><![CDATA[programmingpraxis]]></dc:creator>
		<pubDate>Wed, 04 Aug 2010 13:17:27 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?page_id=187#comment-1548</guid>
		<description><![CDATA[The original version of &lt;code&gt;isqrt&lt;/code&gt;, shown below, has been replaced by a version due to Henri Cohen (see algorithm 1.7.1 of his textbook &lt;em&gt;A Course in Computational Algebraic Number Theory&lt;/em&gt;) which is prettier, faster, and generates less garbage:

&lt;code&gt;(define (isqrt n)
&#160;&#160;(let loop ((x n) (y (quotient (+ n 1) 2)))
&#160;&#160;&#160;&#160;(if (&lt;= 0 (- y x) 1) x
&#160;&#160;&#160;&#160;&#160;&#160;(loop y (quotient (+ y (quotient n y)) 2)))))&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>The original version of <code>isqrt</code>, shown below, has been replaced by a version due to Henri Cohen (see algorithm 1.7.1 of his textbook <em>A Course in Computational Algebraic Number Theory</em>) which is prettier, faster, and generates less garbage:</p>
<p><code>(define (isqrt n)<br />
&nbsp;&nbsp;(let loop ((x n) (y (quotient (+ n 1) 2)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;(if (&lt;= 0 (- y x) 1) x<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(loop y (quotient (+ y (quotient n y)) 2)))))</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: programmingpraxis</title>
		<link>http://programmingpraxis.com/contents/standard-prelude/#comment-1276</link>
		<dc:creator><![CDATA[programmingpraxis]]></dc:creator>
		<pubDate>Tue, 25 May 2010 15:59:21 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?page_id=187#comment-1276</guid>
		<description><![CDATA[The &lt;code&gt;rand&lt;/code&gt; and &lt;code&gt;randint&lt;/code&gt; functions were previously given as shown below; those versions are now deprecated in favor of the random-number generator provided by Donald Knuth in the &lt;em&gt;Stanford GraphBase&lt;/em&gt;:

&lt;code&gt;(define rand
&#160;&#160;(let* ((a 3141592653) (c 2718281829)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(m (expt 2 35)) (x 5772156649)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(next (lambda ()
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(let ((x-prime (modulo (+ (* a x) c) m)))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(set! x x-prime) x-prime)))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(k 103)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(v (list-&gt;vector (reverse
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(let loop ((i k) (vs (list x)))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(if (= i 1) vs
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(loop (- i 1) (cons (next) vs)))))))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(y (next))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(init (lambda (s)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(set! x s) (vector-set! v 0 x)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(do ((i 1 (+ i 1))) ((= i k))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(vector-set! v i (next))))))
&#160;&#160;&#160;&#160;(lambda seed
&#160;&#160;&#160;&#160;&#160;&#160;(cond ((null? seed)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(let* ((j (quotient (* k y) m))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(q (vector-ref v j)))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(set! y q)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(vector-set! v j (next)) (&#047; y m)))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;((eq? (car seed) &#039;get) (list a c m x y k v))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;((eq? (car seed) &#039;set)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(let ((state (cadr seed)))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(set! a (list-ref state 0))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(set! c (list-ref state 1))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(set! m (list-ref state 2))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(set! x (list-ref state 3))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(set! y (list-ref state 4))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(set! k (list-ref state 5))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(set! v (list-ref state 6))))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(else (init (modulo (numerator
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(inexact-&gt;exact (car seed))) m))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(rand))))))&lt;/code&gt;

&lt;code&gt;(define (randint . args)
&#160;&#160;(cond ((null? (cdr args))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(floor (* (rand) (car args))))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;((&lt; (car args) (cadr args))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(+ (floor (* (rand) (- (cadr args) (car args)))) (car args)))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(else (+ (ceiling (* (rand) (- (cadr args) (car args)))) (car args)))))&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>The <code>rand</code> and <code>randint</code> functions were previously given as shown below; those versions are now deprecated in favor of the random-number generator provided by Donald Knuth in the <em>Stanford GraphBase</em>:</p>
<p><code>(define rand<br />
&nbsp;&nbsp;(let* ((a 3141592653) (c 2718281829)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(m (expt 2 35)) (x 5772156649)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(next (lambda ()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(let ((x-prime (modulo (+ (* a x) c) m)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(set! x x-prime) x-prime)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(k 103)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(v (list-&gt;vector (reverse<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(let loop ((i k) (vs (list x)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(if (= i 1) vs<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(loop (- i 1) (cons (next) vs)))))))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(y (next))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(init (lambda (s)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(set! x s) (vector-set! v 0 x)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(do ((i 1 (+ i 1))) ((= i k))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(vector-set! v i (next))))))<br />
&nbsp;&nbsp;&nbsp;&nbsp;(lambda seed<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(cond ((null? seed)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(let* ((j (quotient (* k y) m))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(q (vector-ref v j)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(set! y q)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(vector-set! v j (next)) (&#047; y m)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((eq? (car seed) &#039;get) (list a c m x y k v))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((eq? (car seed) &#039;set)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(let ((state (cadr seed)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(set! a (list-ref state 0))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(set! c (list-ref state 1))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(set! m (list-ref state 2))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(set! x (list-ref state 3))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(set! y (list-ref state 4))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(set! k (list-ref state 5))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(set! v (list-ref state 6))))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(else (init (modulo (numerator<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(inexact-&gt;exact (car seed))) m))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(rand))))))</code></p>
<p><code>(define (randint . args)<br />
&nbsp;&nbsp;(cond ((null? (cdr args))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(floor (* (rand) (car args))))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((&lt; (car args) (cadr args))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(+ (floor (* (rand) (- (cadr args) (car args)))) (car args)))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(else (+ (ceiling (* (rand) (- (cadr args) (car args)))) (car args)))))</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: programmingpraxis</title>
		<link>http://programmingpraxis.com/contents/standard-prelude/#comment-1213</link>
		<dc:creator><![CDATA[programmingpraxis]]></dc:creator>
		<pubDate>Mon, 03 May 2010 16:19:07 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?page_id=187#comment-1213</guid>
		<description><![CDATA[The &lt;code&gt;ilog&lt;/code&gt; function was previously

&lt;code&gt;(define (ilog b n)
&#160;&#160;(if (zero? n) -1
&#160;&#160;&#160;&#160;(+ (ilog b (quotient n b)) 1)))&lt;/code&gt;

That function has been deprecated in favor of this new version

&lt;code&gt;(define (ilog b n)
&#160;&#160;(let loop1 ((lo 0) (b^lo 1) (hi 1) (b^hi b))
&#160;&#160;&#160;&#160;(if (&lt; b^hi n) (loop1 hi b^hi (* hi 2) (* b^hi b^hi))
&#160;&#160;&#160;&#160;&#160;&#160;(let loop2 ((lo lo) (b^lo b^lo) (hi hi) (b^hi b^hi))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(if (&lt;= (- hi lo) 1) (if (= b^hi n) hi lo)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(let* ((mid (quotient (+ lo hi) 2))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(b^mid (* b^lo (expt b (- mid lo)))))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(cond ((&lt; n b^mid) (loop2 lo b^lo mid b^mid))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;((&lt; b^mid n) (loop2 mid b^mid hi b^hi))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(else mid))))))))&lt;/code&gt;

The original was O(n), the replacement is O(log n).  &lt;code&gt;Loop1&lt;/code&gt; calculates the initial bounds for a binary search, which is performed by &lt;code&gt;loop2&lt;/code&gt;.]]></description>
		<content:encoded><![CDATA[<p>The <code>ilog</code> function was previously</p>
<p><code>(define (ilog b n)<br />
&nbsp;&nbsp;(if (zero? n) -1<br />
&nbsp;&nbsp;&nbsp;&nbsp;(+ (ilog b (quotient n b)) 1)))</code></p>
<p>That function has been deprecated in favor of this new version</p>
<p><code>(define (ilog b n)<br />
&nbsp;&nbsp;(let loop1 ((lo 0) (b^lo 1) (hi 1) (b^hi b))<br />
&nbsp;&nbsp;&nbsp;&nbsp;(if (&lt; b^hi n) (loop1 hi b^hi (* hi 2) (* b^hi b^hi))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(let loop2 ((lo lo) (b^lo b^lo) (hi hi) (b^hi b^hi))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(if (&lt;= (- hi lo) 1) (if (= b^hi n) hi lo)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(let* ((mid (quotient (+ lo hi) 2))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(b^mid (* b^lo (expt b (- mid lo)))))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(cond ((&lt; n b^mid) (loop2 lo b^lo mid b^mid))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((&lt; b^mid n) (loop2 mid b^mid hi b^hi))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(else mid))))))))</code></p>
<p>The original was O(n), the replacement is O(log n).  <code>Loop1</code> calculates the initial bounds for a binary search, which is performed by <code>loop2</code>.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

