<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Viamentis Blog &#187; Scheme</title>
	<atom:link href="http://blog.viamentis.com/articles/category/scheme/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.viamentis.com</link>
	<description>Curious About Everything</description>
	<lastBuildDate>Mon, 12 Jul 2010 11:16:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Functional programing with DrScheme</title>
		<link>http://blog.viamentis.com/articles/2008/02/15/functional-programing-with-drscheme/</link>
		<comments>http://blog.viamentis.com/articles/2008/02/15/functional-programing-with-drscheme/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 12:37:17 +0000</pubDate>
		<dc:creator>divya</dc:creator>
				<category><![CDATA[Scheme]]></category>
		<category><![CDATA[DrScheme functional programming interpreter chaosgame]]></category>

		<guid isPermaLink="false">http://blog.viamentis.com/articles/2008/02/15/functional-programing-with-drscheme/</guid>
		<description><![CDATA[First of all i am thanking my guru Mr.Pramod .C.E , for his article in Linux Gazette from where i got the idea of DrScheme. DrScheme is an interactive, integrated, graphical programming environment for the Scheme, a functional programming language,which is similar to LISP. Drscheme can be downloaded and Installed from http://www.plt-scheme.org/software/drscheme/ A script will [...]]]></description>
			<content:encoded><![CDATA[<p>First of all i am thanking my guru Mr.Pramod .C.E , for his article in Linux Gazette from where i got the idea of DrScheme.<br />
DrScheme is an interactive, integrated, graphical programming environment for the Scheme, a functional programming language,which is similar to LISP.</p>
<p>Drscheme can be downloaded and Installed from <code>http://www.plt-scheme.org/software/drscheme/</code>  A script will be available there, running which will install DrScheme and along with it, pl- games (some games in Scheme), scheme web server etc.</p>
<p>Now run the command <strong>&#8220;drscheme&#8221; </strong>, to start the program. Then choose scheme as our language. Try the basic built in functions like + , -,*  etc. Then try writing custom functions like factorial.</p>
<p>DrScheme is an excellent tool for learning programming.For a beginner it will be very easy to go deeply into recursive function executions using the built in &#8220;stepper&#8221;. For using the stepper you need to change the mode as &#8220;intermediate student&#8221; in the Language menu.Now you will have the STEPPING button on the window, with which you can trace your function execution, and will be able to understand how control is moving in your code.This can be very helpful for a beginner in functional programming.</p>
<p>Language menu can set high privileges like advanced student option , so that we have the flexibility to define functions like this</p>
<p><a href="http://blog.viamentis.com/wp-content/uploads/2008/02/screenshot-choose-language.png" title="privileges"><img src="http://blog.viamentis.com/wp-content/uploads/2008/02/screenshot-choose-language.thumbnail.png" alt="privileges" /></a></p>
<p><code>(define (my-cube x) (* x x x))<br />
(define (fun f x) (f x))<br />
(fun my-cube 3)</code></p>
<p>here fun will replace f as my-cube function with a argument of 3 and returns you 27</p>
<p>We can also use lambda ie to call anonymous functions and define local variables inside a function.</p>
<p>Ex <code>(define (fun x y)<br />
(let ((p (* x y))<br />
(q (+ x y)))<br />
(* p q)))</code></p>
<p>(fun 2 3) ; evaluates to 30<br />
The general syntax of â€˜letâ€™ is:</p>
<p><code>(let ( (var1 exprn1) (var2 exprn2) ... (varn exprn) ) body)</code></p>
<p>The three fundamental operations on a list are car, cdr and cons. Let try it in scheme.</p>
<p><code>(define a (list 1 2 3 4)) ; create a list (1 2 3 4) and bind it to â€˜aâ€™<br />
(define b '(1 2 3 4 5)) ; same as above; note the use of the quote<br />
(empty? b) ; returns false<br />
'() ; empty list<br />
(cons 1 '(2 3 4)) ; yields '(1 2 3 4)<br />
(car '(4 1 2 3)) ; yields 4<br />
(first '(1 2 3)) ;  yields 1<br />
(cdr '(1 4 2 3)) ; yields '(4 2 3)<br />
(rest '(1 2 3)) ;  yields'(2 3)<br />
</code><br />
<strong>Bit of graphics</strong><br />
We can move on to simple graphic functions by loading teaching packs such as graphing.ss , draw.ss etc .Here we can write small code fragment to draw a line .</p>
<p>Ex:</p>
<p><code>(start 100 100) ; opens a window<br />
(define p (make-posn 0 0)) ; creates a â€˜posnâ€™ structure<br />
(define q (make-posn 50 50))<br />
(draw-solid-line p q 'blue) ; which will draw a line from p to q in color blue</code></p>
<p>Also we can simulate a game called The Chaos Game , to get code for this click here <a href="(http://linuxgazette.net/119/misc/pramode/listing1.txt)">program</a><br />
Here is the screen shot of it.<br />
<a href="http://blog.viamentis.com/wp-content/uploads/2008/02/screenshot-canvas-vp-g49323.png" title="chaosgame"><img src="http://blog.viamentis.com/wp-content/uploads/2008/02/screenshot-canvas-vp-g49323.thumbnail.png" alt="chaosgame" /></a></p>
<p>Also i wished to do some turtle graphics programming stuffs in scheme but unfortunately i couldn&#8217;t able to load the library (turtle.ss) successfully. Hope i can do it next time <img src='http://blog.viamentis.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="pfButton"><a href="http://blog.viamentis.com/articles/2008/02/15/functional-programing-with-drscheme/?pfstyle=wp" title="Print an optimized version of this web page"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-button-both.gif" alt="Print"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.viamentis.com/articles/2008/02/15/functional-programing-with-drscheme/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Exploring SICP</title>
		<link>http://blog.viamentis.com/articles/2006/04/30/exploring-sicp/</link>
		<comments>http://blog.viamentis.com/articles/2006/04/30/exploring-sicp/#comments</comments>
		<pubDate>Sun, 30 Apr 2006 13:58:00 +0000</pubDate>
		<dc:creator>Vamsee</dc:creator>
				<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[This book totally rocks. And it kinda makes me depressed. Some exercises are really tough, and it&#8217;s putting me through all kinds of grief. But heck, I&#8217;m getting a kick out of learning this stuff. Kinda like going back to college and getting all the stuff right. But you need to have a lot of [...]]]></description>
			<content:encoded><![CDATA[<p>This book totally rocks. And it kinda makes me depressed. Some exercises are really tough, and it&#8217;s putting me through all kinds of grief. But heck, I&#8217;m getting a kick out of learning this stuff. Kinda like going back to college and getting all the stuff right. But you need to have a lot of patience. You need to unlearn some concepts. Anyways, to console myself, I have done one of the easier exercises (1.8). Here&#8217;s how you calculate a cube root (apologies to non-geeks &#8211; the posts in the coming days/weeks would be full of this):</p>
<pre>
(define (cuberoot-iter guess x)
  (if (good-enough? guess x)
      guess
      (cuberoot-iter (improve guess x)
             x)))

(define (improve guess x)
  (/ (+ (/ x (square guess)) (* 2 guess)) 3))

(define (good-enough? guess x)
  (&lt; (abs (- (cubed guess) x)) 0.001))

(define (cubed x)
  (* x (* x x)))

(define (cuberoot x)
  (cuberoot-iter 1.0 x))

Evals to (using mit-scheme):

(cuberoot 27)
;Value: 3.0000005410641766
</pre>
<div id="pfButton"><a href="http://blog.viamentis.com/articles/2006/04/30/exploring-sicp/?pfstyle=wp" title="Print an optimized version of this web page"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-button-both.gif" alt="Print"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.viamentis.com/articles/2006/04/30/exploring-sicp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
