<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-1369853434158175571</atom:id><lastBuildDate>Sun, 22 Jan 2012 18:52:25 +0000</lastBuildDate><category>SBCL</category><category>shindig</category><category>Mathematics</category><category>personal</category><category>SLIME</category><category>Diophantine Equation</category><category>Arc</category><category>macro</category><category>mvn</category><category>Lambda Calculus</category><category>Windows</category><category>JavaScript</category><category>common lisp</category><category>general</category><category>Elisp</category><category>Programming</category><category>opensocial</category><title>Samik's Restless Rants</title><description>Randomization of thoughts and programming</description><link>http://lispsamik.blogspot.com/</link><managingEditor>noreply@blogger.com (samik chakraborty)</managingEditor><generator>Blogger</generator><openSearch:totalResults>29</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/blogspot/lispsamik" /><feedburner:info uri="blogspot/lispsamik" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-3392328385834196523</guid><pubDate>Tue, 17 May 2011 07:18:00 +0000</pubDate><atom:updated>2011-05-19T23:25:01.678-07:00</atom:updated><title>Lets Un-Uncomplicate</title><description>The world is a beautiful place if you can see things simply. But once you are in the software it becomes ugly and you start seeing things in a completely different way. I have seen thing happening so may times – that I felt like writing this one out.&lt;br /&gt;&lt;br /&gt;Its story time here – so enjoy!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The “Hello! World”&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You must have written a “hello world” program in your life. It’s the simplest program that you can write in a programming language . So I will tell you a story with “Hello! World”.&lt;br /&gt;&lt;br /&gt;In a software company, “ComplicateSoft” (henceforth called as “CS” – for simplification!), there was a requirement from a customer to write a program which will print “Hello! World”. But as with any customer, there is a catch – they did not know where will it be getting printed or how many times will it be getting printed. So they said the “Archie” of “CS” make something generic. Actually the customer said “make something which will do the job in most cases”, the “Archie” documented it as “generic”.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The Dev-Archie meet&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;“We will do it the proper way”, said Archie.&lt;br /&gt;&lt;br /&gt;Dev guy, “Yeah, makes sense – cool.”&lt;br /&gt;&lt;br /&gt;So the dev guy wrote a good old Java class, which has a simple method which prints “Hello! World”.&lt;br /&gt;&lt;br /&gt;Dev was happy as he never got a easier project than this. So he even wrote it in TDD.&lt;br /&gt;&lt;br /&gt;Archie came along and saw that piece of code and said, “Okay, but that’s not generic enough. Dude, make the string “Hello! World” externalized”.&lt;br /&gt;&lt;br /&gt;So the dev guy, did.&lt;br /&gt;&lt;br /&gt;Next, Archie said, “Dude we do not know where this will get printed no sys-out. Take a output stream instead!”&lt;br /&gt;&lt;br /&gt;Well this should be all. The dev guy did that.&lt;br /&gt;&lt;br /&gt;Next, Archie said, “This class is doesn’t have any state so lets make it a Singleton.”&lt;br /&gt;&lt;br /&gt;The dev guy thought wow! I will implement a design pattern now on this – cool.&lt;br /&gt;&lt;br /&gt;The Archie said, “Now we have to make sure that if someone request this as service over the web, do a WSDL for it and test it with a client.”&lt;br /&gt;&lt;br /&gt;Dev guy did that!!!&lt;br /&gt;&lt;br /&gt;Now Archie thought about the requirement once more and remembered the phrase, “don’t know how many times will it get printed.”&lt;br /&gt;&lt;br /&gt;If it needs to printed multiple times with a distributed file system?&lt;br /&gt;&lt;br /&gt;He asked his dev guy a final thing – “Can you make this class support Hadoop map-reduce”&lt;br /&gt;&lt;br /&gt;The dev guy ….&lt;br /&gt;&lt;br /&gt;The end.&lt;br /&gt;&lt;br /&gt;Hope you enjoyed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-3392328385834196523?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/C0W-Epu8KWU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/C0W-Epu8KWU/lets-un-uncomplicate.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>1</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2011/05/lets-un-uncomplicate.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-609979715580582270</guid><pubDate>Tue, 01 Mar 2011 07:52:00 +0000</pubDate><atom:updated>2011-02-28T23:53:13.802-08:00</atom:updated><title>Why is it harder to read the code than writing it?</title><description>It is harder to read a code than to write it.&lt;br /&gt;&lt;br /&gt;In a meeting where a team is deciding whether to write the code a fresh, this is the reason given in favor of writing it all over again. With this reason we sometimes add seasonings like: we will design it better, we will write in TDD, blah, blah and blah.&lt;br /&gt;&lt;br /&gt;But if you think very closely you will come to know why you are re-writing the code. If you are re-writing a code from language X to Y. There must be some very good reason behind it. Like if you have a old C code which you want to re-write in Java your list of reason could be: portability, multi threading, OOPs design, security etc.&lt;br /&gt;&lt;br /&gt;But if you have decided to re-write the entire code in the same language you are doing so because:&lt;br /&gt;It is harder to read a code than to write it.&lt;br /&gt;&lt;br /&gt;Now stop think about the part:&lt;br /&gt;&lt;br /&gt; It is harder to read a code&lt;br /&gt;&lt;br /&gt;Why is it harder to read the code?&lt;br /&gt;&lt;br /&gt;Answer the following questions:&lt;br /&gt;&lt;br /&gt;1.    Is there a high level documentation to follow the code flow?&lt;br /&gt;&lt;br /&gt;2.    If I put a break point in main (for C/C++/Java – you can think of the name of the entry point method in your project. In a web development you can think of a Servlet also.) can I follow it?&lt;br /&gt;&lt;br /&gt;3.    Are all the “if statements” (even assert statements for debug) is well commented?&lt;br /&gt;&lt;br /&gt;4.    Can I test all the methods for their side effects and returned values?&lt;br /&gt;&lt;br /&gt;5.    Can I look at the output of the program and get to know which paths are involved to produce any part of the output?&lt;br /&gt;&lt;br /&gt;If your answers are mostly “No”. You need re-organization of your code – not a full blown re-write. That re-organization can be: adding comments to full refactoring of the code. But here I will tell you a little bit more about each point that I have mentioned above.&lt;br /&gt;&lt;br /&gt;•    High level program flow is very crucial for understanding of the software. A full-blown call graph tree is perfect. But at least all programmers in a project should be able to draw the high level program flow easily. Now let me tell you that this high level is not a one block with input to output. It has to be at least describes all the major boxes in the system. It should show the interaction with various modules, including internal and third party modules used.&lt;br /&gt;&lt;br /&gt;•    One should be able to go though the whole system effortlessly when she has put a break point at the beginning. Now if you have multiple entry point (one for one feature), one should not look out for an entry point for particular feature more than one documentation file. If you do not have it – do it now.&lt;br /&gt;&lt;br /&gt;•    The branching statements in a code are very important. This is the place where business logic is implemented. So they must be documented – and the documentation is in the code as comments. You do not want your programmer to look for the spec while debugging any feature. Any changes to the business requirement should be tracked in the code comment. If any of the method is going to change the state of some variables or objects which impacts the overall behavior you should document that also, again in the code comment.&lt;br /&gt;&lt;br /&gt;•    Nothing is like a unit testing but that is less for automation and more for human understanding. Any developer in the team should know where the unit test case resides for the method that he is working on. A new developer should start by doing the unit tests first. Sometimes in old code we do not have unit test cases for historic reasons. If that has state changes going around we should provide the developer a way to understand the state and state changes.&lt;br /&gt;&lt;br /&gt;•    This one is important! Look at your output and tell me which code or code path is responsible for this output. Like if you are showing a count of students in a class you should be able to trace that front end to the back end code till the DB.&lt;br /&gt;&lt;br /&gt;If you do all that you should be in a good position to understand the code and work with it rather than dispose it off. If you anyway decide to follow the re-write make sure the documentation points that I have mentioned here. Do the docs for this re-write else you will drop this code some day with the reason:&lt;br /&gt;&lt;br /&gt;It is harder to read a code than to write it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-609979715580582270?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/ZSm85QmlESU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/ZSm85QmlESU/why-is-it-harder-to-read-code-than.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2011/02/why-is-it-harder-to-read-code-than.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-1305322756680426065</guid><pubDate>Fri, 18 Feb 2011 06:22:00 +0000</pubDate><atom:updated>2011-02-17T22:29:18.169-08:00</atom:updated><title>10 Things to Keep in Mind while depeloping a Web App</title><description>What should I ensure before I start developing a web application? So here is my humble list of things that I must do (don’t) in the future:&lt;br /&gt;&lt;br /&gt;1.    There is a need for authentication so figure that out first. Use a well know library for it – like if you are using Java use Spring Security.&lt;br /&gt;&lt;br /&gt;2.    Do not write your backend first. Especially for Ajax based web apps. You will need to add or change the API with the page design changes.&lt;br /&gt;&lt;br /&gt;3.    Do not return HTML from any Ajax API ever. Use JSON. [If you do this with # 2 you are doomed]&lt;br /&gt;&lt;br /&gt;4.     In your HTML, JSP (or ASP) or XSLT - do not write the style attribute (in HTML tags) to save time today. Instead add a class in your style.css file. It will save a lot of time in the future. Like if you want to change the color of the whole page you can work with one css file instead of all your ASPs and JSPs.&lt;br /&gt;&lt;br /&gt;5.    Have one entry point for all services – use a dispatcher. What I mean by this is make your web app configuration lean (for Java world it is web.xml).&lt;br /&gt;&lt;br /&gt;6.    Keep the logged in user in a secured URL like HTTPS. Never transport password over HTTP.&lt;br /&gt;&lt;br /&gt;7.     Try to standardize the JSON response. If you need to render something from JSON data this will help you a lot. You can write one helper JS function which will take care of it.&lt;br /&gt;&lt;br /&gt;8.    Follow css box model always. No excuse.&lt;br /&gt;&lt;br /&gt;9.    Divide the web page into multiple parts. Each part should be working fine. I mean as much as possible.&lt;br /&gt;&lt;br /&gt;10.    Build a feature a close it for today’s requirement. Do not jump to a feature without finishing the one in hand – it will bite your ass later.&lt;br /&gt;&lt;br /&gt;10 + 1. Test in a lot of browsers (IE7+, FF, Opera, Chrome)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-1305322756680426065?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/oPd_0tsKBcc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/oPd_0tsKBcc/10-things-to-keep-in-mind-while.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>1</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2011/02/10-things-to-keep-in-mind-while.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-9057502131343224362</guid><pubDate>Mon, 28 Jun 2010 12:34:00 +0000</pubDate><atom:updated>2010-06-28T05:38:28.680-07:00</atom:updated><title>Reading Cricekt - A Fun full Learning</title><description>Cricket is a game where you play either as a batting side or as a fielding side. Players from batting side try to score runs and the fielding side tries to stop the batsmen by getting them out. It sounds pretty similar to many games that are played worldwide, like baseball. But I am not going to blog about a game that’s played out door. I am blogging about an indoor game that I learnt during my school days. It is an amazing game where cricket is mixed with reading habit. It’s called Reading Cricket – conceptualized and invented by our Bengali language teacher Mr. Tejesh Adhikari.&lt;br /&gt;&lt;br /&gt;This game is very simple to play – especially in a class room situation. So how is it played?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The “Rules”&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;There will be two teams of course. One will bat the other will bowl. But instead of bat and ball they will have the same book. Like the history book that is used by all students in the classroom. The team which is batting will be reading from the book. One of the team members will be reading the book aloud so that the other team can listen. The fun begins now. &lt;br /&gt;&lt;br /&gt;1. If the batsman (the guy who is reading the book) can complete a line (note – a line not a sentence) will be awarded 1 run.&lt;br /&gt;&lt;br /&gt;2. If the line contains just one word which is foreign and is not part of the normal vocabulary of the original language of the book, or is written in a different language alphabet. If the batsman reads that line with proper pronunciation, he will score 2 runs for that line. &lt;br /&gt;&lt;br /&gt;3. Consider the point# 2 for multiple words but not the whole line. In this case the batsman will score 4 runs.&lt;br /&gt;&lt;br /&gt;4. Now consider if the whole line is written in the foreign language – the bats man get 6 runs. &lt;br /&gt;&lt;br /&gt;5. Now for all 2,3 and 4 the batsman should know beforehand and he can declare that he does not know the language. No one can penalize him for that.&lt;br /&gt;&lt;br /&gt;6. So what the fielding team is going to do? They will listen carefully each word of the batsman. If any of the fielders finds that the batsman has mispronounced any one of the word according to the convention learned by the students in the school – he can appeal for an out. If the teacher thinks that the appeal is correct he gets out.&lt;br /&gt;&lt;br /&gt;There were so many other things in it. But the above mentioned are the gist of what I can recall. &lt;br /&gt;&lt;br /&gt;What an effect that it used to have when we used to do it in the school. The guys who never gave attention to anything used to glue to the pages and follow the batsman when they used to field. It is an amazing way to learn how to read, understand and possibly remember. &lt;br /&gt;&lt;br /&gt;Like the best bridge players – who never forget a mistake that he has made in a deal or like a chess player who always remember the blunder that he had made, we used to remember our mistakes while reading.&lt;br /&gt;&lt;br /&gt;I just thought this game might help a lot of people who works with young learners, who are dedicated to bring out the best in our young – if they know about it, they can try it.&lt;br /&gt;&lt;br /&gt;If you try it please let me through your comments. If you want to know more about it – please ask me any question.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-9057502131343224362?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/XuD81FCQa6I" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/XuD81FCQa6I/reading-cricekt-fun-full-learning.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2010/06/reading-cricekt-fun-full-learning.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-7896609208797678895</guid><pubDate>Thu, 25 Mar 2010 06:36:00 +0000</pubDate><atom:updated>2010-03-24T23:38:36.988-07:00</atom:updated><title>Come Back!!!</title><description>“We're getting close to the end of my blog. After today's entry, I only have three left to write. After that, I'll only blog anonymously or (more likely) not at all.” – Steve Yegge&lt;br /&gt;&lt;br /&gt;“programming is rather thankless. you see your works become replaced by superior works in a year. unable to run at all in a few more.” - _why&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So people do like to disappear from the web world. I really do not know why a person like Steve wants to stop blogging; _Why likes to stop contributing to the programming language he loved. &lt;br /&gt;&lt;br /&gt;We all need time to do things that we must, should and have to do. I must spend quality time with my family; I should spend an hour or two with Concrete Mathematics; I have to keep my day job (hey I love my day job – please don’t take it in the other sense.) so that I can pay the bills.  &lt;br /&gt;&lt;br /&gt;But it seems strange that one day one may decide to go in the clouds and never come back. If someone really does that, whom should we blame? Why some people really wanted to know the so called “real” person behind _Why? Some people think that’s may be the reason for the drastic step that _Why took. If you do not agree with what someone has to say about something (like Marijuana) – why do we always have to hit that guy?&lt;br /&gt;&lt;br /&gt;Yeah! We are intelligent beings – and have big fat ego like – I know this stuff better than you and I can show how great I am in…. but hey dude. You are just good at criticizing and nothing else. You know pointless criticism is pointless! FLAT POINTLESS – don’t do it! &lt;br /&gt;&lt;br /&gt;I do not know why the hell these guys disappeared. But I want them to come back. But why should you come back? These thankless people will never stop. They will always come back and hound you guys. I am just thinking about people who really go inspiration from you guys. An email, blog post or code snippet can clarify an air of uncertainty in our mind. For ruthless, restless and may be “I know all” types all you have to do is “ignore” them. They will always be there as their existence depends on it. They will not practice agile for 2 years and come back and say “Hey Steve, you missed out these (or that point) in why Agile suck.”&lt;br /&gt;&lt;br /&gt;You know I am may be just ranting for no reason at all. I know this will not change your mind sets. Just one request to you guys. Do not punish all for a few!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-7896609208797678895?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/uicPNwAZjp8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/uicPNwAZjp8/come-back.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2010/03/come-back.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-4245507878444005691</guid><pubDate>Wed, 27 Jan 2010 07:22:00 +0000</pubDate><atom:updated>2010-01-26T23:34:40.415-08:00</atom:updated><title>Caveat - The Name has Changed</title><description>After almost three years of blogging, I am changing the title and subtitle of my blog. It will no longer be called as lisp any more. Why? Of late I was not writing enough about (or on) lisp. It is more and more becoming my restless rants that I do out of desperate need to fulfill my alter-ego of creativity. I gave it a long thought and paused for several minutes before I changed it. I was thinking that some people who read this blog may feel that it has changed from what it was previously. Do not worry – it is impossible to change an opinion, let alone a personality.&lt;br /&gt;&lt;br /&gt;My obligation was not only to my reader but also to the people who lands on my blog. They shouldn’t be misguided to a belief that it is a blog purely for Lisp. Hope this will clear some clouds – hope you will enjoy it as before. &lt;br /&gt;&lt;br /&gt;Oh I almost forgot to mention! I will definitely write about lisp and lisp related articles in the future.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-4245507878444005691?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/wnq4afTNabo" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/wnq4afTNabo/caveat-name-has-changed.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2010/01/caveat-name-has-changed.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-4716631262860168581</guid><pubDate>Wed, 20 Jan 2010 05:21:00 +0000</pubDate><atom:updated>2010-03-08T01:36:37.777-08:00</atom:updated><title>Loooopy</title><description>&lt;b&gt;How Tortoise Taught Recursion to Achilles&lt;/b&gt; &lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;hr/&gt;&lt;br /&gt;&lt;br /&gt;This post was there with me for quite some time - but couldn't complete it for almost six months. At last its done! Hope you will enjoy it.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;One should read the dialog in Lewis Carroll writing or Godel, Escher, Bach.&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/What_the_Tortoise_Said_to_Achilles"&gt;Here is the dialog that I have referred to from Wikipedia.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr/&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;[Achilles and Tortoise meet at a coffee shop after a long break.]&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: It has been long that we have met.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: Yeah! But the good thing is that, here we are together; once again. So what have you been doing all these days?&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: Nothing! &lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: So it must have been boring for you. &lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: Oh no, no! It was not boring at all. I have learnt programming of late and I was playing with couple of programming languages. Like I was figuring out how I can model all that we have discussed previously. Especially the one that you and I got into endless thousand page ranting on with A, B, C … to prove Z. You remember?&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: Yes, I do in fact! That was a fun! I hope you understand that it is very difficult to prove that uh!&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: You should learn programming and you will come to know that what you did was an infinite loop. You would have understood the loop will go on and on.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: Loop?&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: Yes my dear friend – loop. &lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: So what is this “Loop” is all about?&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;[Achilles smiles and continues, after a sip of cappuccino]&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: You see loops are very simple. If you want to do something repeatedly you just say that. &lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: Elaborate please.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: Like say you want to add all the integers from 1 to 10. You start a loop, let x equals to 1 and sum equals 0. Add sum and x and assign the result to sum, after that you increase x by 1 and do this till x is less than 11; you see you want to add all integers till 10. Pretty simple, huh?&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Code snippet:&lt;br /&gt;  int sum = 0;&lt;br /&gt;  for (int x = 0; x &lt; 11 ; x++) {&lt;br /&gt;   sum += x;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt; &lt;/pre&gt;&lt;br /&gt; &lt;br/&gt;&lt;br /&gt;Tortoise: Fine! But looks odd to me!&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: Why? Is there anything wrong?&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: You know my friend; you have learnt a programming language but I am a little handicapped with that, i.e. “programming language”, but I feel I have a different way of understanding this one.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: How?&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: Do you know the mathematical concept of function? Like F(x, y) = x + y?&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: Yes I do.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: Great! We can represent the solution like the following function in mathematics:&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;       F(x, y) = y + x; if x = 10   … (RULE 1)&lt;br /&gt;         = F(x+1, y+x); 1 &lt;= x &lt;= 9  … (RULE 2)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;O mighty Achilles! How will you write this in your programming language?&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: I see! Let me tell you how to do that in programming language. [Achilles shows the code snippet]&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; public int sum(int x,int y) {&lt;br /&gt;  if (x == 10) {&lt;br /&gt;   return y+x;&lt;br /&gt;  } else {&lt;br /&gt;   return sum(x+1,y+x);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: I knew this from my advance classes in programming – it is called recursion. But how do you explain this.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: Very simple my friend! The RULE 1 says that if the variable x is equal to 10 you are going to produce the summation of x and sum as result else it will keep on calling itself with an incremented value of x and summation of  x and the y variables. It’s very basic math you see.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: But you need to have a termination rule to complete the task! How would you explain that A, B and Z proposition problem with recursion? It was an endless loop right? No terminating condition.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: Really? But I knew that there was a terminating condition there too! It was your last proposition. If I would have accepted it – the so called loop was over. But I did not accept it I just kept on adding one more layer in between the final and penultimate statement. So the final statement was the terminating condition. &lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: But as you see now, in this example we have a terminating condition as 10…&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: That need not to be 10, we can introduce a third variable say z or we can call it terminator if you like it. We can rewrite the function definition as follows:&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;       F(x, y, z) = y + x; if x = z   … (RULE 1)&lt;br /&gt;            = F(x+1, y+x, z); 1 &lt;= x &lt;= 9  … (RULE 2)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;And this one should work for any integer value of z – isn’t it?&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: Yes it would and the program would look like:&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; public int sum(int x, int y, int z) {&lt;br /&gt;  if (x == z) {&lt;br /&gt;   return y+x;&lt;br /&gt;  } else {&lt;br /&gt;   return sum(x+1, y+x, z);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;And we could invoke this with something like: sum(1, 0, 10) and it works. But, tortoise, it is still does not create an infinite loop like what you had created.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: Yes, Achilles it can but needs a little imagination. I created something like this:&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;       F(x, y, z) = y + x; if x = z   … (RULE 1)&lt;br /&gt;            = F(x+1, y+x, x+2); 1 &lt;= x &lt;= 9 … (RULE 2)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Look closely, warrior; I have introduced a never reaching fallacy in the RULE 2 function. Instead of z I am passing x+2 as the last argument. This will prevent the condition for RULE 1 and it will remain like that illusive last statement. &lt;br /&gt;&lt;br/&gt;&lt;br /&gt;[Tortoise paused for a moment]&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: Now you see it!&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: Yes.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Tortoise: I am going home – would you like to join?&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: No!&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;[Tortoise leaves slowly. Achilles looks at the paper and nods his head in disbelieve.]&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Achilles: Waiter! Get me a java green please.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;The java code for this never ending recursion would look like:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class Recursionist {&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * @param args&lt;br /&gt;  */&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  Recursionist r = new Recursionist();&lt;br /&gt;  System.out.println(r.sum(1,0,100));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public int sum(int x,int sum,int termination) {&lt;br /&gt;  if (x == termination) {&lt;br /&gt;   return sum+x;&lt;br /&gt;  } else {&lt;br /&gt;   return sum(x+1,sum+x,x+2);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;OUTPUT: A stack overflow exception - at some point of time I gusse.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Moreover you do not do all these for Arithmetic Progression you just use the formula.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-4716631262860168581?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/Dj4FmNIj6Xg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/Dj4FmNIj6Xg/loooopy.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2010/01/loooopy.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-3233522655064655693</guid><pubDate>Sun, 17 Jan 2010 06:53:00 +0000</pubDate><atom:updated>2010-01-19T03:10:24.526-08:00</atom:updated><title>Weekend Programming Excursion - 1</title><description>&lt;p&gt;&lt;br /&gt;  So I have joined a new company on 30th December 2009. I am now working for Thomson-Reuters. As always the blog that I write here will not represent in any manner what so ever my new employer’s views, these are just my technological rants that I always write. I do not even know whether these are read or not, but just in case you are among those people who surf around and read this blog (either occasionally or regularly) be assured that I will eventually write something in here.&lt;br /&gt;  &lt;/p&gt;&lt;p&gt;&lt;br /&gt;So, gosh what new year it was – leaving one company and joining another, I didn’t even got a chance to work on anything (other than all the pending items that I had on my plate with my previous employer, writing a good-bye mail, meeting people who wanted to wish me luck for my new venture and of course the team send off dinner) significant to write. It was all work and no play with my laptop.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;As some of you may have noticed in this blogs that Lisp is not the programming language that I am working now.  I am no longer in those fortunate few who get paid for learning Lisp, working with Lisp and writing Lisp codes. But that said nobody stopped me from learning a new programming language – but as you can guess from my worthless rants that I have not even scratched the surface of it.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;On a boring weekend you usually start the day with your home stuff like laundry. However, if you are a programmer who cannot live without coding something or the other in a day, you also code. That kind of coding I call a “weekend excursion into programming”. Most of the times one tends to lose all the code that you have built over the time. This is especially true for me. So before I forget what I did I would like to put it in here. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;So what was that I did?&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;A class and an interface in Java! Yes you heard it correct just a class and an interface - an interface with one method signature and a class with one method (as of now). That’s it!&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;You must be wondering what the heck! 1 interface, 1 class and 1 method for each of them! &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;You may tell me, “Dude! You are not working hard.”&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;Point taken! No more blah, blah….&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;So here it is what I did.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;b&gt;The &lt;i&gt;One&lt;/i&gt; Interface&lt;/b&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;I bad at naming but I knew that the word “lambda” has to be there for this interface name. So in the kingdom of noun (i.e. Java) I have to use adjective for interfaces so the name of the interface is LambdaService.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;So what is there in this interface? Here is the code for you:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;div style="border:1px solid #6789B3;background-color:#CFCFCF;"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import java.util.List;&lt;br /&gt;public interface LambdaService&lt;T&gt; {&lt;br /&gt;&lt;br /&gt; T lambda(List&lt;T&gt; params );&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Pretty simple, huh! It takes a list of arguments of type T and returns an object of type T. If you are from some functional programming background, you already know this stuff. But for people who do not know how I am going to use it – hold on, you are in for a ride.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;b&gt;The &lt;i&gt;One&lt;/i&gt; Class&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Let me give you the class definition code also.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;div style="border:1px solid #6789B3;background-color:#CFCFCF;"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.List;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * @author samikc&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;public class Functional&lt;T&gt; {&lt;br /&gt;&lt;br /&gt; public static  &lt;T&gt; List&lt;T&gt; map(LambdaService&lt;T&gt; lambda,&lt;br /&gt;           List&lt;T&gt;... list) {&lt;br /&gt;  List&lt;T&gt; retList = new ArrayList&lt;T&gt;(); &lt;br /&gt;  List&lt;T&gt; params = new ArrayList&lt;T&gt;();&lt;br /&gt;  int iterCount = getShortestListSize(list);&lt;br /&gt;  for (int i = 0;i &lt; iterCount;i++) {&lt;br /&gt;    int paramCounter = 0;&lt;br /&gt;    for (List&lt;T&gt; l : list) {&lt;br /&gt;      params.add(paramCounter, l.get(i));&lt;br /&gt;      paramCounter++;&lt;br /&gt;    }&lt;br /&gt;    retList.add((T) lambda.lambda(params));&lt;br /&gt;  }&lt;br /&gt;  return retList;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private static &lt;T&gt; int &lt;br /&gt;                getShortestListSize(List&lt;T&gt;... list) {&lt;br /&gt;  List&lt;T&gt; retList = list[0];&lt;br /&gt;  for (List&lt;T&gt; l : list) {&lt;br /&gt;    if (l.size() &lt; retList.size()) {&lt;br /&gt;      retList = l;&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  return retList.size();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;So what this method map is doing here. Let me try to explain.  &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;In map you provide a lambda service (which is a method at the end of the day) and a list. The lambda service is nothing but a strategy pattern, I am allowing others to provide an option to provide an algorithm which will be applied to each member of the list provided and result will be collated in a &lt;b&gt;different list&lt;/b&gt;. &lt;br /&gt;Notice that I have made “different list” &lt;b&gt;bold&lt;/b&gt;.  Why? As I am applying the algorithm provided I am not changing the anything inside the actual list passed on. So it does not have a side-effect.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;The main is given below without any comments; I feel it’s very simple and intuitive.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;b&gt;The &lt;i&gt;*main*&lt;/i&gt; Story&lt;/b&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="border:1px solid #6789B3;background-color:#CFCFCF;"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.List;&lt;br /&gt;&lt;br /&gt;public class Main {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;        ArrayList&lt;Integer&gt; il1 = new ArrayList&lt;Integer&gt;();&lt;br /&gt;        il1.add(10);&lt;br /&gt; il1.add(20);&lt;br /&gt; il1.add(30);&lt;br /&gt; ArrayList&lt;Integer&gt; il2 = new ArrayList&lt;Integer&gt;();&lt;br /&gt; il2.add(10);&lt;br /&gt; il2.add(20);&lt;br /&gt; il2.add(30);&lt;br /&gt; il2.add(40);&lt;br /&gt; List&lt;Integer&gt; li = Functional.map(new LambdaService&lt;Integer&gt;() {&lt;br /&gt;  @Override&lt;br /&gt;  public Integer lambda(List&lt;Integer&gt; params) {&lt;br /&gt;    Integer i1 = params.get(0);&lt;br /&gt;    Integer i2 = params.get(1);&lt;br /&gt;    Integer ret = i1 + i2;&lt;br /&gt;    return ret;&lt;br /&gt;  }&lt;br /&gt; }, il1, il2);&lt;br /&gt;  &lt;br /&gt; for (Object o : li) {&lt;br /&gt;  System.out.println(o);&lt;br /&gt; }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Sample output:&lt;br /&gt;20&lt;br /&gt;40&lt;br /&gt;60&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-3233522655064655693?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/Sz8la77DuQg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/Sz8la77DuQg/weekend-programming-excursion-1.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2010/01/weekend-programming-excursion-1.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-491987534698402468</guid><pubDate>Tue, 29 Dec 2009 17:22:00 +0000</pubDate><atom:updated>2009-12-29T09:24:23.886-08:00</atom:updated><title>Last Day at Wipro</title><description>After working for almost four and half years I have left Wipro. Tomorrow I will join a new organization (will let you the name tomorrow). &lt;br /&gt;&lt;br /&gt;Great learning experience in Wipro.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-491987534698402468?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/r7LhzvVqgDc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/r7LhzvVqgDc/last-day-at-wipro.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>1</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2009/12/last-day-at-wipro.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-23225684285245058</guid><pubDate>Wed, 03 Jun 2009 05:57:00 +0000</pubDate><atom:updated>2009-06-03T22:31:21.233-07:00</atom:updated><title>JSON – Traps and How to Avoid Them</title><description>&lt;hr /&gt;&lt;br /&gt;&lt;i&gt;Disclaimer: This post is suggestive but not complete&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;When you are working with &lt;a href="http://www.json.org/"&gt;JSON&lt;/a&gt; there are plenty of chances that things may go wrong. We all know that when something can go wrong it will go wrong. JSON never mentions the data type or it does not get validated by existing JS engines that run on the browser – so the onus lies on the developer to make sure that the data that she has received is in correct format and if possible the value is correct.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Any one can think about whole bunch of defensive programming techniques to avoid such a scenario. But it is impossible to guess what all things can go wrong so we should be prepared as much as possible.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Never evaluate a JSON. It is as bad as it can be. Don’t do it. You do not what you have received in the JSON. If it is a malicious code it can do havoc on your DOM and JS environment. It can corrupt your JS name space, steal cookie information or even worse user information.  I know you must be thinking that we have to do it time and again, use &lt;a href="http://www.json.org/json2.js"&gt;json2.js&lt;/a&gt; library for this purpose – please do not repeat yourself with all the JSON string parsing again.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;JSON data access is where your code will break (I mean eventually). Say you have a JSON structure (produced by the server) like this one:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;div style="background-color:#a9a9a9;border:dashed 1px black;"&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;{ name :  {  first : “Joe”, middle : ”Moe” ,  last :  “Doe” },  age :  23 }&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Now you wrote the logic like this:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;div style="background-color:#a9a9a9;border:dashed 1px black;"&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var name = json.name.first + “ “+ json.name.middle +”  “+ json.name.last;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;This look pretty straight forward and you are sure nothing can go wrong with this simple code. But your server works with this logic: If there is a middle name then it adds middle name if it is not there it keeps mum about that. So the JSON comes like this:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;div style="background-color:#a9a9a9;border:dashed 1px black;"&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;{ name :  {  first : “Joe” ,  last :  “Doe” },  age :  23 }&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Your code now will not work as expected, the reason being the absence of name.middle object. This is undefined.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;So how do you make sure that it works as expected? Here is how:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;div style="background-color:#a9a9a9;border:dashed 1px black;"&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var name = “unknown”;&lt;br /&gt;If (json.name.first &amp;amp; json.name.middle &amp;amp; json.name.last) {&lt;br /&gt;name = json.name.first + “ “+ json.name.middle +”  “+ json.name.last;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;This is more important when it comes to calling some methods on a JavaScript object. If the object does not exist (i.e., undefined) then it will throw an error and your rest of the script won’t run.  So if you are working with some JSON and you expect some kind of an object check the type of the object before invoking the method on it. Like if you want to split some CSV (comma separated value) string check that the object is of string type.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;div style="background-color:#a9a9a9;border:dashed 1px black;"&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;if (csvObject instanceof String) {&lt;br /&gt;// Do your stuff here for string&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-23225684285245058?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/V5y5RiZLLPk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/V5y5RiZLLPk/json-traps-and-how-to-avoid-them.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2009/06/json-traps-and-how-to-avoid-them.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-1789524436847917138</guid><pubDate>Mon, 01 Dec 2008 13:25:00 +0000</pubDate><atom:updated>2008-12-01T06:02:27.991-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">shindig</category><category domain="http://www.blogger.com/atom/ns#">mvn</category><category domain="http://www.blogger.com/atom/ns#">opensocial</category><title>Building Shindig 101</title><description>&lt;b&gt;"Proxy" problem:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;While most of the world in enjoying the freedom of non-proxy Internet some people (like me) are behind a proxy server. Whatever, to get Maven working behind a proxy you need to go to your Maven installation folder and edit the file settings.xml in conf folder. What do you put in there?&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;settings&amp;gt;&lt;br /&gt;.&lt;br /&gt;&amp;lt;proxies&amp;gt;&lt;br /&gt; &amp;lt;proxy&amp;gt;&lt;br /&gt;    &amp;lt;active&amp;gt;true&amp;lt;/active&amp;gt;&lt;br /&gt;    &amp;lt;protocol&amp;gt;http&amp;lt;/protocol&amp;gt;&lt;br /&gt;    &amp;lt;host&amp;gt;proxy.somewhere.com&amp;lt;/host&amp;gt;&lt;br /&gt;    &amp;lt;port&amp;gt;8080&amp;lt;/port&amp;gt;&lt;br /&gt;    &amp;lt;username&amp;gt;proxyuser&amp;lt;/username&amp;gt;&lt;br /&gt;    &amp;lt;password&amp;gt;somepassword&amp;lt;/password&amp;gt;&lt;br /&gt;    &amp;lt;nonProxyHosts&amp;gt;proxyhost.somewhere.com&amp;lt;/nonProxyHosts&amp;gt;&lt;br /&gt;  &amp;lt;/proxy&amp;gt;&lt;br /&gt;&amp;lt;/proxies&amp;gt;&lt;br /&gt;.&lt;br /&gt;&amp;lt;/settings&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;Building Shindig - The canonical way:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Building shindig (I assume that you know how to get the code using Subversion) the canonical way is simple:&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;cd ~/src/shindig/&lt;br /&gt;mvn&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This should be enough for most of you but if you are unlucky like me. You may get variety of errors:&lt;br /&gt;&lt;br /&gt;1. Too many unapproved licenses: 12&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Some people get a different number (even 0 - see this mail trail: &lt;a href="http://www.mail-archive.com/shindig-dev@incubator.apache.org/msg07718.html"&gt;http://www.mail-archive.com/shindig-dev@incubator.apache.org/msg07718.html&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Test failure :&lt;br /&gt;&lt;br /&gt;May be one of the most frustrating thing is the test failures. They are hard to find and resolve sometimes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So the question is; what are the options that you can try while building Shindig (and if *something* goes wrong - the list is in no particular order):&lt;br /&gt;&lt;br /&gt;1. Delete your .m2/repository folder and retry - This will download all the required jar files once more. If you have missed something in the previous go you may get it (due to downtime to some download location). This is important if you get "Missing Artifacts" kind of an error.&lt;br /&gt;&lt;br /&gt;2. Try : mvn clean install [ This cleans old bad builds and gives you kind of a fresh start]&lt;br /&gt;&lt;br /&gt;3. Checkout or update the code from the Shindig repo once more.&lt;br /&gt;&lt;br /&gt;4. Update the code once more if the build fails badly as this can happen due to unintentional commit mishaps.&lt;br /&gt;&lt;br /&gt;5. If only the test fails and you are not patient enough to debug, use the following to suppress the error:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; mvn -Dmaven.test.failure.ignore=true&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;6. If you are too brave you can even try:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; mvn -Dmaven.test.failure.ignore=true -fn&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;[This worked for me when I got *too many unapproved licenses : 12*]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;all the failures are suppressed by this -fn  it will *NEVER* fail the build.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So that's about it while building Shindig. Hope this helps - if you have any other way of doing this let me know.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-1789524436847917138?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/muztgAvrBWQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/muztgAvrBWQ/building-shindig-101.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/12/building-shindig-101.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-5287455057746351325</guid><pubDate>Sat, 15 Nov 2008 09:55:00 +0000</pubDate><atom:updated>2008-11-19T00:34:31.827-08:00</atom:updated><title>Code and Data Equivalence</title><description>&lt;meta equiv="Content-Type" content="text/html; charset=utf-8"&gt;&lt;meta name="ProgId" content="Word.Document"&gt;&lt;meta name="Generator" content="Microsoft Word 11"&gt;&lt;meta name="Originator" content="Microsoft Word 11"&gt;&lt;link rel="File-List" href="file:///C:%5CDOCUME%7E1%5Csamikc%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C03%5Cclip_filelist.xml"&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;  &lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" latentstylecount="156"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} &lt;/style&gt; &lt;![endif]--&gt;&lt;meta equiv="Content-Type" content="text/html; charset=utf-8"&gt;&lt;meta name="ProgId" content="Word.Document"&gt;&lt;meta name="Generator" content="Microsoft Word 11"&gt;&lt;meta name="Originator" content="Microsoft Word 11"&gt;&lt;link rel="File-List" href="file:///C:%5CDOCUME%7E1%5Csamikc%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C03%5Cclip_filelist.xml"&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;  &lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" latentstylecount="156"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} &lt;/style&gt; &lt;![endif]--&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;That code and data are equivalent is a common idea in common lisp. However any programmer who has started his programming in any language other than lisp may find this idea alien to him. This happened to me, and it took me some time to understand the concept. This post is all about my understanding about “code data equivalence” in lisp. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;First of all what is code? Code is anything that can be executed in a computer. In other words code is what we write in a programming language. Code is as the text books suggest is a human readable representation of what computers going to execute. Like the famous hello world program that all of us has written at some point of our life.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;Data on the other hand is something which will be processed by the code. So the code will execute on a data and data change from one execution cycle to another. Data can be given to a code from various sources, like input from a user, file or even a program or code. So in our mind there is a difference. For example take the example of a function which will add two numbers passed to it.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;span style=""&gt;   &lt;/span&gt;int add(int a, int b) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;span style=""&gt;   &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;span style=""&gt; &lt;/span&gt;return a+b;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;span style=""&gt;   &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;In mathematics we know that the operation summation will do *something* with two (or more) numbers and will return a result. This result also will be a number. So the operation of addition is important than that of the data that it operates on. This creates a difference of treating data and code. This difference is the underpinning of treating data and code as separate entities which is true for most of the programming languages.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;div style="border-style: none none solid; padding: 0in 0in 1pt;"&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;But in case of lisp this is not true. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;In lisp anything that comes to the REPL is s-expression. What is s-expression? Sexp or s-expression is defined in lisp as an atom or list. Atoms are number, string, character etc. So when a input or data come to REPL it evaluates that as any one these alternatives. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;The code that we write in lisp is also s-expression. Now as in mathematics we know that:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;If A = B and C = B so A = C.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;For lisp:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;CODE = SEXP and DATA = SEXP so CODE = DATA&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; text-indent: 0.5in;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;QED.&lt;/span&gt;&lt;/p&gt;  &lt;/div&gt;    &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-5287455057746351325?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/yUTNRT1ipTw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/yUTNRT1ipTw/code-and-data-equivalence.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>1</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/11/code-and-data-equivalence.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-4680039936368257803</guid><pubDate>Wed, 18 Jun 2008 11:56:00 +0000</pubDate><atom:updated>2008-06-18T05:12:07.577-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">general</category><title>Why lisp is *Unpopular*</title><description>&lt;p class="MsoNormal"&gt;Lisp is a great programming language which has lot of power; however it is far from being most popular programming language. If you see lisp from a distance you will find:&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpFirst" style="margin-left: 0.75in; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;1.&lt;span style=""&gt;       &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;Orthogonal syntax&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="margin-left: 0.75in; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;2.&lt;span style=""&gt;       &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;Very quick to learn the basics&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="margin-left: 0.75in; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;3.&lt;span style=""&gt;       &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;Very power full when it is used in high level project&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpLast" style="margin-left: 0.75in; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;4.&lt;span style=""&gt;       &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;You write less code as it has most powerful macro system&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;But still lisp is not the language of choice. It is a fallacy of programming world. Why? This question has stumped me number of times. &lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;This post is my attempt to understand why it is so.&lt;/p&gt;  &lt;h1&gt;&lt;span style="font-size:100%;"&gt;Prefix notation&lt;/span&gt;&lt;/h1&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;Lisp is a programming language where prefix notations are used extensively. Prefix notations are good for computer but not for human being. From very old age human civilization and its mathematics is built on top of infix notation. We comprehend mathematical expressions in infix. You can argue with educational system but you cannot ask to change the year old mathematical notation to help a programming language to be understandable. That is simply not possible. This seems to me a perfect road block for lisp and it has to survive with that. &lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;It will not be out of the turn to tell you a story about my friend. She was looking at Practical Common Lisp, and told, “How do you write 4*3+6 in common lisp?”&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;I replied (in writing), “(+ (* 4 3) 6)”.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;She looked at it and closed the browser which was rendering “Practical Common Lisp”.&lt;/p&gt;  &lt;h1&gt;&lt;span style="font-size:100%;"&gt;Mathematics behind lisp&lt;/span&gt;&lt;/h1&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;Believe it or not all programmers do not like mathematics. They lie in the pantry, in conferences, in blogs. But the truth is a handful among us really like mathematics and care about it. Moreover it is not necessary to have deep understanding of mathematics to develop programs, or to be a programmer for that matter. &lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;But lisp is an exception to this idea. To have a fair idea about lisp you have to understand some mathematics, like higher order functions. To understand functional programming paradigm one have to devote some weeks to lambda calculus. If one does not understand this he can write programs in lisp but it will be distant from the lisp style. The very idea of Turing machine and lambda calculus is fundamental to computer science but at the real world of software development those ideas do not cross our mind. To be honest with everyone I learnt C programming language without any knowledge of both Turing machine or lambda calculus.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;There are self educated programmers who are very good in their trade and they care a damn about those theoretical computer science topics. &lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;So lisp (and proper lisp style) is beyond many programmers and the target audience is less.&lt;/p&gt;  &lt;h1&gt;&lt;span style="font-size:100%;"&gt;Programming language politics&lt;/span&gt;&lt;/h1&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;Politics is pervasive; programming languages are not an exception to it. Big corporation look for development environments which are well supported, backward compatible, developers are available, etc. This is true in all large organizations or profit making corporations. When you decide about writing software you try to find out a middle ground. Lisp is powerful, 100 java average programmers = 10 or 2 great lisp hackers, you write less code to get more out programming language – all of them so very true. But when I was asked, “Show me one problem that I cannot solve with Java/Ruby/C++/Python?” I knew as all of them are Turing complete, so there is no problem that cannot be solved by Java/Ruby/C++/Python. &lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;Although you have to learn more lexical separator in those programming languages than lisp still lisp looses. This is *PLP* - Programming Language Politics, we have to live with it. People will reject our ideas of development in lisp and the reason will never be purely technical; rather techno-political.&lt;/p&gt;  &lt;h1&gt;&lt;span style="font-size:100%;"&gt;Code – data Equivalence – Hard to understand&lt;/span&gt;&lt;/h1&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;I said, “In lisp code is data and data is code”.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;Ron said,”What?”&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;People do not understand code data equivalence, because they are tuned by other programming languages. Those programming languages are their bread and butter so the immortal suggestion of “Unlearn “is “Unreal”.&lt;span style=""&gt;  &lt;/span&gt;This is the bottom line of any lisper. This is *THE BASIS* of lisp macros. And it is so away from all other brick-mortar programming languages that no one understands its power without coding for many months and many macros. I got the feel of the matter when I read first ten chapters of Paul Graham’s “On Lisp”. This adds to another stiff cliff in any newbie’s learning curve. &lt;span style=""&gt; &lt;/span&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;/p&gt;  &lt;h1&gt;&lt;span style="font-size:100%;"&gt;Macros&lt;/span&gt; &lt;/h1&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;Lisp macros are different beast, a beast when under you command do wonderful job for you. As any other programmer, especially *I know all* programmer like me, need some time to understand that lisp macros are really different. &lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;It took me couple of week to realize that, when I realized it I felt like a stupid school kid with all red score card who has been slapped by his father for his exceptional result. Then I understood,”Oh! Yeah lisp macros are different.”&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;It opened my mind about programming as whole. Like when I learnt lisp – I learnt map, list, mapcar and all other cool lisp techniques. Before my lisp journey I was struggling with C++ STL concepts, after I learnt lisp all the things fell into place.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;But the point here is that lisp macros are the last challenge that one has to understand (if not master).&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;h1&gt;&lt;span style="font-size:100%;"&gt;Run-of-the-mill programmers&lt;/span&gt;&lt;/h1&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;In many places it has been mentioned that lispers are not *Run-of-the-mill* programmer. They are different (in some cases arrogant), may be programmer elite. But popularity of a programming language depends on the acceptability of the language not on its power. Natural languages evolve out of existing languages to a simpler but verbose form. The same is not true for programming languages. There is no programming linguistic tree which has a common root node for syntax or semantic or paradigm. Lisp’s elite status may be the singular disadvantage to the general programming cloud.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;We all play the role of *run-of-the-mill* programmer in any given project while it comes to coding and debugging. So *run-of-the-mill* programmers are necessary for any project to succeed and sustain. If your target is not *run-of-the-mill* guys you are bound to lose one day or the other.&lt;/p&gt;  &lt;h1&gt;&lt;span style="font-size:100%;"&gt;Undermining Microsoft Windows&lt;/span&gt;&lt;/h1&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;Not many lisp software works properly in Microsoft windows. The lion share of desktop application runs on windows box, but many lisp apps do not work. &lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;Lisper world over has to take up the challenge to support Microsoft version of all the application that they are going to release. The word support can be even this one liner: “I do not care about windows. If it works fine else just do not disturb me.” At least some who cares about Microsoft compatibility will not use your stuff in his software.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-indent: 0.5in;"&gt;Undermining Microsoft is bad, because Microsoft to computers is like photosynthesis to trees – it is a necessary evil.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-4680039936368257803?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/BiMLN_pgceo" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/BiMLN_pgceo/why-lisp-is-unpopular.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>8</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/06/why-lisp-is-unpopular.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-2023248245823266561</guid><pubDate>Fri, 13 Jun 2008 13:08:00 +0000</pubDate><atom:updated>2008-06-13T06:12:05.221-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">personal</category><category domain="http://www.blogger.com/atom/ns#">common lisp</category><title>Closure II and some future thought</title><description>My last post about closure in my blog and my query in the comp.lang.lisp have created some interesting debate among lispers and my friends. They have sugested their views about my posts. Some of them said that it was required and some said “I do not care about closure”. All in all I felt good about it. At least some people took a notice about closure and what it means.&lt;br /&gt;&lt;BR /&gt;&lt;br /&gt;&lt;br /&gt;To begin the post I must correct one program from my privious post:&lt;br /&gt;&lt;BR /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;(let ((s0 0) (s1 1) (state 0))&lt;br /&gt;  (defun input-action(in)&lt;br /&gt;    (if (eq state in)&lt;br /&gt; (setf state in)&lt;br /&gt;      (if (eq state s0)&lt;br /&gt;         (setf state s1)&lt;br /&gt;       (setf state s0)))))&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;BR /&gt;&lt;br /&gt;I was really busy with my work of late and could not find any time (or topic) to write. I am busy with javascript and I am very happy with that. So I feel that in next couple of blogs I will write about some of JavaScript.  For this I will go back to my school days and write programs which are like stack, queue and linked list. So that I can keep up with my old habits; what is it?&lt;br /&gt;&lt;BR /&gt;&lt;br /&gt;Programming.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-2023248245823266561?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/h1TWIxEkSeI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/h1TWIxEkSeI/closure-ii-and-some-future-thought.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/06/closure-ii-and-some-future-thought.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-2023339556689030921</guid><pubDate>Wed, 23 Apr 2008 05:10:00 +0000</pubDate><atom:updated>2008-04-22T22:25:36.317-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">common lisp</category><title>Closure</title><description>A closure can be a very deceptive concept that comes with programming languages like lisp, JavaScript etc. So what is a closure? Definition of closure from Wikipedia is like this:&lt;br /&gt;&lt;br /&gt; “a closure is a function that is evaluated in an environment containing one or more bound variables.” &lt;br /&gt;&lt;br /&gt;In closure we get an environment and a function in that environment. When the function gets evaluated it has the opportunity to play with the environment. In common practice we think that an environment is nothing but the state of execution of a program. Programs, as pointed out in the classic book “How to design Programs”, is variables plus functions. So we can say, in general, environment is nothing but current state of the variables.&lt;br /&gt;&lt;br /&gt;How we create closures? Here is an example:&lt;br /&gt;&lt;br /&gt;[1]&gt; (let ((x 1))&lt;br /&gt;       (defun foo(n)&lt;br /&gt;        (+ n x)))&lt;br /&gt;FOO&lt;br /&gt;&lt;br /&gt;Here x is the bound variable which has a value 1 and this makes the environment for function FOO. FOO will always get x as 1 in its execution. When we call FOO we get:&lt;br /&gt;&lt;br /&gt;[2]&gt; (foo 3)&lt;br /&gt;4&lt;br /&gt;&lt;br /&gt;With this as our base let’s explore a classic example of closure. Yeah! The same old make-adder example, what I am talking about.&lt;br /&gt;&lt;br /&gt;Here is the code for that:&lt;br /&gt;&lt;br /&gt;[4]&gt; (defun make-adder(n)&lt;br /&gt;       #'(lambda(x)(+ x n)))&lt;br /&gt;MAKE-ADDER&lt;br /&gt;&lt;br /&gt;[5]&gt; (setf add1 (make-adder 1))&lt;br /&gt;#&lt;function lambda="" x=""&gt;&lt;br /&gt;&lt;br /&gt;[6]&gt; (funcall add1 2)&lt;br /&gt;3&lt;br /&gt;&lt;br /&gt;When we defined make-adder we created a closure with variable n in lambda function with its own variable x. As we call make-adder and store the resultant function in variable add1 we created a closure where we will add 1 to the passed argument. Now that’s OK but how can I use it? This question I faced from many. Here is my use case.&lt;br /&gt;&lt;br /&gt;MOVE&lt;br /&gt;&lt;br /&gt;I (with my friends) developed a simulator for Intel 8085 microprocessor in C. later I tried to redo the code in lisp and found a very interesting application of make-adder closure. By this time I got familiar with IA-32 and Intel family of 80x86 processors where the logic MOVE have not changed but the number of bits (or bytes) to move has changed to match processor register size and architecture. That’s the “Aha!” moment for me. I wrote a function that will create a move as per the bytes to move. Here is the code for that (I have a move function which takes from-reg, to-reg for register purpose and number of bytes to move):&lt;br /&gt;&lt;br /&gt;  (defun make-mover(n)&lt;br /&gt;                  #'(move from-reg to-reg n))&lt;br /&gt;&lt;br /&gt;This solved (I hope) my problem for backward (or forward) compatibility issues as long as Intel does not change its MOVE.&lt;br /&gt;&lt;br /&gt;So now I can get MOVE8, MOVE16 and MOVE32 very easily. I should re-write the whole program like that starting from register class definition.&lt;br /&gt;&lt;br /&gt;STATE MACHINE&lt;br /&gt;&lt;br /&gt;In the beginning we found that closure has close relation with function and its environment. This fact intuitively gives us a ready made case for state machine implementations in closure.&lt;br /&gt;&lt;br /&gt;Consider the following state machine; it has two states S0 (represented as 0) and S1 (represented as 1). Here is the logic that it performs, if the current state of the machine is S0 and input is 0 it remains in S0 else machine goes to state S1. If the current state of the machine is S1 and input is 0 it changes the state to S0 else it remains in state S1. This machine accepts 1 and 0 as input. Also note that this machine initializes at state S0.&lt;br /&gt;&lt;br /&gt;Here is the code:&lt;br /&gt;&lt;br /&gt;(let ((s0 0) (s1 1) (state 0))&lt;br /&gt;        (defun input-action(in)&lt;br /&gt;       (if (eq state in)&lt;br /&gt;            state&lt;br /&gt;           (if (eq state s0)&lt;br /&gt;                s1&lt;br /&gt;                s0))))&lt;br /&gt;&lt;br /&gt;And here is two sample runs:&lt;br /&gt;[19]&gt; (list (input-action 0) (input-action 1) (input-action 0))&lt;br /&gt;(0 1 0)&lt;br /&gt;[20]&gt; (list (input-action 0) (input-action 1) (input-action 0) (input-action 1) (input-action 1))&lt;br /&gt;(0 1 0 1 1)&lt;br /&gt;&lt;br /&gt;That’s all I have understood about closures. Let me know if something wrong or you have better idea of closure and its uses.&lt;br /&gt;&lt;br /&gt;Thanks for reading.&lt;br /&gt;&lt;br /&gt;&lt;/function&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-2023339556689030921?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/3wn_jem9D84" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/3wn_jem9D84/closure.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/04/closure.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-565427211243579047</guid><pubDate>Thu, 06 Mar 2008 14:47:00 +0000</pubDate><atom:updated>2008-03-06T07:20:32.630-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">common lisp</category><title>On Parentheses</title><description>People think about lisp parentheses as most hard thing in the world. When I started learning lisp it was a bottleneck for me too. I used to think what you do with these parentheses? Why it is like this. But now when I have started feeling a bit confident about lisp parentheses I felt I should put a note for absolute beginners of the language.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Parentheses while coding lisp&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;While you are coding always use a lisp editor for your parentheses handling. Best option is Emacs or XEmacs. If you are using it in windows please install and configure your Emacs in Windows (for some idea you can see &lt;a href="http://lispsamik.blogspot.com/2007/09/slime-setup-for-windows.html"&gt;here&lt;/a&gt;). Understand that good editor (like Emacs) will not only help you in coding in lisp but will increase your speed of translating your idea into code.&lt;br /&gt;&lt;br /&gt;Use good key combinations to move around the parentheses as s-expression. Do not waste your time with bad editors which does not support any lisp mode; the faster you unlearn (thoes editors) the better you will be in coding lisp.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Parenthesis while reading lisp codes&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;There is no parentheses in the lisp code when you are reading a code. Yes, it may sound crazy for anyone starting out in lisp but it is true. Here is an example showing the concept:&lt;br /&gt;&lt;br /&gt;(defun show-file(filename)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(let ((in (open filename :if-does-not-exist nil)))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(when in&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(format t "~a~%" (read-line in))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(close in)))&lt;br /&gt;&lt;br /&gt;Here is what you get when you removed all the parentheses:&lt;br /&gt;&lt;br /&gt;defun show-file filename&lt;br /&gt;let in open filename :if-does-not-exist nil&lt;br /&gt;when in&lt;br /&gt;format t “~a~%” read-line in&lt;br /&gt;close in&lt;br /&gt;&lt;br /&gt;It reads like:&lt;br /&gt;&lt;br /&gt;Define function show-file which will take filename as argument&lt;br /&gt;Let in be the file handler with filename; if the file does not exist do nothing&lt;br /&gt;When there is a file handler in “in”&lt;br /&gt;Format output as each line in the file comes&lt;br /&gt;And yes close the file “in” before quitting.&lt;br /&gt;&lt;br /&gt;That’s all! I hope this will help.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-565427211243579047?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/tkw73g0Q3W8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/tkw73g0Q3W8/on-parenthesis.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>1</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/03/on-parenthesis.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-673075168630042232</guid><pubDate>Fri, 29 Feb 2008 08:22:00 +0000</pubDate><atom:updated>2008-03-03T08:31:17.535-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><title>Imperative Programming:What is *Wrong*?</title><description>&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;What is *wrong* with the imperative programming? That’s the question that came up in a discussion where I was part; the dicussion group comprised of people from diverse software background and most of them has their lineage to C or C++. The points that came up during that discussion were well spread over the day to day activities of the programmers working in various types of projects. &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;?xml:namespace prefix = o /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;Actually if you see from a distance it is absolutely ok to write a piece of code in your favorite imperative language, but if you take some time and code the software in your favorite functional programming language it feels and looks better; of course your choice of functional programming language has to be good. &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="FONT-WEIGHT: bold"&gt;&lt;span style="font-size:85%;"&gt;Side Effects&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;Side effects make lot of problems while coding in imperative languages. Say you have a program that runs into several functions and as imperative language like C does not support higher order functions (in true sense) your functions are dependent on what we know as *GLOBAL VARIABLES*(to preserve the global state). Lets assume that you set an error flag if something has gone wrong in some function. As each function is interlinked in producer-consumer relationship with each other, once a function has done its job you have to see whether there is any error set or not. So your code will be sprinkled with codes like this:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;br /&gt;&lt;/p&gt;&lt;center&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;i =&lt;span style="font-size:+0;"&gt; &lt;/span&gt;fn1();&lt;/span&gt; &lt;p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;if( !errorset())&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;fn2();&lt;/span&gt;&lt;/p&gt;&lt;/center&gt;&lt;p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;This is not only bad while typing but also an example how a programmer loose his ability to think. How? As our example goes if you do it in several files and several functions; one fine morning loose the intent to think what may go wrong in simple function which is just checking whether a file exists or not! And I can tell you this happens because this happened with me. &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;Other than this, think about the time that I spent error handling. People might say that this is because you are using a programming language which does not support better error handling mechanisms to help the programmer. I agree, but as we know the imperative programming languages will always depend on Hoare Logic, i.e. it will have the notion of pre and post conditions. If we see both the paradigms of programming (lambda calculi and Turing machines) depends on those conditions but pure functional programming does not have side effects as it does not change (although lisp programs can do that) the values of its parameter. &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;But when I code in lisp I know that if I need an output from one function to another I will using the first one as a higher order function to the later. Then the second function only need to know what it expected out of the calling function if something goes wrong in the higher function it can handle it then and there and end the execution flow gracefully. &lt;span style="font-size:+0;"&gt;&lt;/span&gt;This brings me to next topic execution flow.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="FONT-WEIGHT: bold"&gt;&lt;span style="font-size:85%;"&gt;Execution flow: Where am I?&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;Yup! This is a nightmare for any programmer in the imperative programming world; a bunch of programmer I knew once wrote a simulation program for Intel 8085 microprocessor but after each cycle of execution they didn’t know from where the program exited. It used to exit with unhandled error each time in Windows. If you think who they were I can tell you I was in that group. It took us some effort to fill that gap.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;Now you might say that boy that doesn’t happen in real world! Oh yes that does not happen but we always have way to complete the process and most of the time the process is return-return-return till you come to main and then do simple check up and clean up of your mess with memory and then die by returning 0. No problems with that but think that if an execution starts and you know from the first command line checking itself that the user has made a mistake but you still follow your way of closing after eating some good processor time. &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;But in lisp you can’t loose your track! Even if you want you can’t, simple. How? If you are creating a properly designed lisp code with functional style you will be calling functions on top of one another so it will go on till the boundary of your hardware! It may fail some times but you will not be loosing your track. Even in error without any extra effort from your side you will be getting messages like: “Debugger invoked on ….”! I say, it’s just cool.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="FONT-WEIGHT: bold"&gt;&lt;span style="font-size:85%;"&gt;LOC – Yeah the greatest enemy of code!&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;I think Steve has given enough reason in his post so I need not prove this. But yes if I look at my C code some times I cry! How much I have typed for so little. Take the famous, old and boring “Hello World” program. In C you have to type at least 5 lines. In lisp REPL it’s only “Hello World”. Even a fancy function will be 2 lines. So you save 60% of typing effort while working with “Hello world” program.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;And as the saying goes with lazy programmer I feel good while I use my “TAB” key for auto complete in XEmacs. &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;It happens especially if you need to work with raw data. By the time I finish structure filling code in C, I bet will be able to complete a subset of other tasks like some parsing also.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;The crux of the matter is doing more out of less. If this is not good enough for you rethink about becoming a programmer.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="FONT-WEIGHT: bold"&gt;&lt;span style="font-size:85%;"&gt;Macros&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;My first impression about C macros was, “Here is subject which I need to learn because I really do not know what is wrong with my code when I use them.” The best macro I have used in my C code:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;# define&lt;span style="font-size:+0;"&gt; &lt;/span&gt;PRINTLN&lt;span style="font-size:+0;"&gt; &lt;/span&gt;printf(“\n”);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;And believe me it worked wonderfully for me. People in that discussion never understood what I was talking about when I said “function returning macro” or “code writing macros”. Because they do not know what a power a macro can have if you are programming lisp.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;(I can go on talking about macros but I should refrain as this is not a sub-topic but requires major effort and can span several posts.)&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-673075168630042232?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/ZL3UJ7rvN_k" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/ZL3UJ7rvN_k/imperative-programmingwhat-is-wrong.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>4</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/02/imperative-programmingwhat-is-wrong.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-6487062991548204229</guid><pubDate>Tue, 19 Feb 2008 06:48:00 +0000</pubDate><atom:updated>2012-01-22T10:52:25.897-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Mathematics</category><category domain="http://www.blogger.com/atom/ns#">common lisp</category><category domain="http://www.blogger.com/atom/ns#">Diophantine Equation</category><title>A Small Mathematical Project</title><description>&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;Some times back I received an invitation to join an online community on Diophantine equations and related mathematical group in my Orkut account. I did not join the group for quite some time as I am very irregular in Orkut. But at last I when I wanted to join the group it is no longer there, this group’s moderator, a student of Indian Institute of Technology, wanted to run the community as complete mathematical community, unfortunately he decided to close the group.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;When I learned about Diophantine equations in little details, I felt that how about writing a small common lisp utility to get going in this field. There were challenges to do that and more for a person like me who likes to work on his own code rather than using library in hobby projects. This post is all about what I felt during that development. I made a point of writing some lines while coding. Not as a comment but as a thought process.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;How can I create a set (list) of values starting from one number and ending at another number? This question came to my mind first and the solution is writing a function which will give me a list like that on demand. It is intuitive that the arguments in this function would be a starting number, an end number and an incremental element which will increment the starting number till the end number or less. Moreover Diophantine equation demands that variables needs to integers.&lt;/span&gt;&lt;/p&gt;&lt;center  style="font-family:georgia;"&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;!--?xml:namespace prefix = o /--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(defun diophantine-create-set(start end)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(loop for n from start to end&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;while(&amp;lt;= n end) collect n))&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/center&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:georgia;font-size:85%;"&gt;Once I got that I have to think how I can represent a Diophantine equation in common lisp. The first thing that I felt is this has to be small so it will be a two unknown argument equation not an n-unknown Diophantine. At this point my imaginary linear Diophantine looked something like:&lt;/span&gt; &lt;center  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;Ax + By = K&lt;br /&gt;&lt;/span&gt;&lt;/center&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;Here I have to get the constant values from the user. That is good enough but another step needs to be done in this, which re-writing the equation,&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;center&gt;&lt;span style="font-size:85%;"&gt;y = (K – Ax) / B&lt;br /&gt;&lt;/span&gt;&lt;/center&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;Once I got this form of the equation I can write something like:&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;center&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(lambda (x)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(/ (- k (* a x)) b))&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/center&gt;&lt;span style="font-size:85%;"&gt;So now how do I do this? I have come with this macro:&lt;/span&gt;&lt;br /&gt;&lt;center&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(defmacro diophantine-equation (a b k s e)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;`(mapcar #'(lambda(x) (/ (- ,k (* ,a x)) ,b)) (diophantine-create-set ,s ,e)))&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/center&gt;&lt;span style="font-size:85%;"&gt;Following are some evaluation of this macro:&lt;br /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="COLOR: rgb(153,51,102);font-size:85%;" &gt;CL-USER&amp;gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (diophantine-equation 1 1 10 1 100)&lt;br /&gt;(9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90)&lt;/span&gt;&lt;span style="COLOR: rgb(153,51,102);font-size:85%;" &gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="COLOR: rgb(153,51,102);font-size:85%;" &gt;CL-USER&amp;gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (diophantine-equation 2 1 10 1 100)&lt;br /&gt;(8 6 4 2 0 -2 -4 -6 -8 -10 -12 -14 -16 -18 -20 -22 -24 -26 -28 -30 -32 -34 -36&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-38 -40 -42 -44 -46 -48 -50 -52 -54 -56 -58 -60 -62 -64 -66 -68 -70 -72 -74&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-76 -78 -80 -82 -84 -86 -88 -90 -92 -94 -96 -98 -100 -102 -104 -106 -108 -110&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-112 -114 -116 -118 -120 -122 -124 -126 -128 -130 -132 -134 -136 -138 -140&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-142 -144 -146 -148 -150 -152 -154 -156 -158 -160 -162 -164 -166 -168 -170&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-172 -174 -176 -178 -180 -182 -184 -186 -188 -190)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;Looks fine till now but see what you get from the following evaluation:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(153,51,102);font-size:85%;" &gt;CL-USER&amp;gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (diophantine-equation 2 5 10 1 100)&lt;br /&gt;(8/5 6/5 4/5 2/5 0 -2/5 -4/5 -6/5 -8/5 -2 -12/5 -14/5 -16/5 -18/5 -4 -22/5&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-24/5 -26/5 -28/5 -6 -32/5 -34/5 -36/5 -38/5 -8 -42/5 -44/5 -46/5 -48/5 -10&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-52/5 -54/5 -56/5 -58/5 -12 -62/5 -64/5 -66/5 -68/5 -14 -72/5 -74/5 -76/5&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-78/5 -16 -82/5 -84/5 -86/5 -88/5 -18 -92/5 -94/5 -96/5 -98/5 -20 -102/5&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-104/5 -106/5 -108/5 -22 -112/5 -114/5 -116/5 -118/5 -24 -122/5 -124/5 -126/5&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-128/5 -26 -132/5 -134/5 -136/5 -138/5 -28 -142/5 -144/5 -146/5 -148/5 -30&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-152/5 -154/5 -156/5 -158/5 -32 -162/5 -164/5 -166/5 -168/5 -34 -172/5 -174/5&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;-176/5 -178/5 -36 -182/5 -184/5 -186/5 -188/5 -38)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;Now the main aim of diophantine equations is failing, as only the integer solutions are accepted as per Diophantine analysis. In the last evaluation we have some integer solution but this list has both integers as well as fractions. This to me is simply “Not acceptable!”&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;"&gt;Moreover I can bet that it will not be acceptable in mathematics community. &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;At this point of development I had to put some more code in my diophantine-equation macro, it has to check whether a solution is integer or not. I will map the list and create a list of solutions with integers if it exists. To achieve this I introduced another macro because I wanted to keep diophantine-equation macro as it is. Here is the macro:&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;center&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;(defmacro diophantine-solutions(a b k s e)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;`(remove nil (mapcar #'(lambda(x)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(when (integerp x)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;x))&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(diophantine-equation ,a ,b ,k ,s ,e))))&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/center&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;Let’s see what kind of output I have from this macro:&lt;/span&gt; &lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="COLOR: rgb(153,51,102);font-size:85%;" &gt;CL-USER&amp;gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (diophantine-solutions 2 5 10 1 100)&lt;br /&gt;(0 -2 -4 -6 -8 -10 -12 -14 -16 -18 -20 -22 -24 -26 -28 -30 -32 -34 -36 -38)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;Now as we have built this basic framework for Diophantine analysis, let’s put this to some test. I know that I may not be able to answer a lot of questions asked in Diophantine analysis. But this small framework can answer a basic question right now. The first question that is asked in Diophantine analysis is, “Are there any solutions?” of course I have to reframe the question as per my framework as “Are there any solution between the range that I have mentioned?” it looks something like this in the REPL.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="COLOR: rgb(153,51,102);font-size:85%;" &gt;CL-USER&amp;gt;&lt;/span&gt; (if (eq nil (diophantine-solutions 2 5 10 1 100))&lt;br /&gt;nil&lt;br /&gt;t)&lt;span style="font-size:85%;"&gt;&lt;br /&gt;T&lt;br /&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(153,51,102);font-size:85%;" &gt;CL-USER&amp;gt;&lt;/span&gt; (if (eq nil (diophantine-solutions 2 5 10 1 4))&lt;br /&gt;nil&lt;br /&gt;t)&lt;br /&gt;&lt;span style="font-size:85%;"&gt;NIL&lt;br /&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(153,51,102);font-size:85%;" &gt;CL-USER&amp;gt;&lt;/span&gt; (if (eq nil (diophantine-solutions 2 5 10 1 1))&lt;br /&gt;nil&lt;br /&gt;t)&lt;br /&gt;&lt;span style="font-size:85%;"&gt;NIL&lt;br /&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(153,51,102);font-size:85%;" &gt;CL-USER&amp;gt;&lt;/span&gt; (if (eq nil (diophantine-solutions 2 5 10 1 10))&lt;br /&gt;nil&lt;br /&gt;t)&lt;br /&gt;&lt;span style="font-size:85%;"&gt;T&lt;/span&gt; &lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;This utility has only one function and two macros. &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;I hope you like this blog; however if you think that there is a better way (which I am sure would be) of doing some things that I have done here or if you find any bug please feel free comment on it. &lt;b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;Thanks for reading.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;Disclaimer: This is a hobby project not for any production use.&lt;span style="font-size:-0;"&gt; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-6487062991548204229?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/SGfcU3uqYV4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/SGfcU3uqYV4/small-mathematical-project.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/02/small-mathematical-project.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-1442541543688424747</guid><pubDate>Sat, 16 Feb 2008 11:33:00 +0000</pubDate><atom:updated>2008-02-20T22:24:31.522-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Lambda Calculus</category><category domain="http://www.blogger.com/atom/ns#">common lisp</category><title>Lambda Calculus and Common Lisp</title><description>&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Warning: If you do not like mathematics this post may not be interesting to you.&lt;span style="font-size:+0;"&gt; &lt;/span&gt;&lt;?xml:namespace prefix = o /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;When we talk about lisp or any dialect of it we come across the term &lt;a href="http://en.wikipedia.org/wiki/Functional_programming"&gt;&lt;span style="color:blue;"&gt;functional programming&lt;/span&gt;&lt;/a&gt;. So what is functional programming any way and where it all started? If you ever have thought about such things here is my small attempt to answer some very fundamental questions in functional programming.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;So what are the functions? Here are some basics. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;In mathematics functions is some kind of relation between two things. But wait a minute isn’t functions are some code snippet that does some tasks? After all we programmers know functions that way. Yeah, both are correct and they do not have any difference. Like a function, which increments a variable by one, can be represented in following way:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;f(x) = x + 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;So we can write a lot of functions like this in mathematic and solve them for a value. However there was no such concept as function in the begging of computer science instead there were just Turing machines which used to change state to provide result and solve problems by means of its states; this is such a great system that it can solve all computational problems. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Then &lt;?xml:namespace prefix = st1 /&gt;&lt;st1:place st="on"&gt;&lt;st1:placename st="on"&gt;Alonzo&lt;/st1:placename&gt; &lt;st1:placetype st="on"&gt;Church&lt;/st1:placetype&gt;&lt;/st1:place&gt; came up with lambda calculus and revolutionizes the whole concept of representing and solving problems. He wanted to solve some mathematical paradox (if you want to know about them see &lt;span style="COLOR: rgb(51,102,255)"&gt;&lt;a href="http://en.wikipedia.org/wiki/Russell"&gt;here&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Kleene-Rosser_paradox"&gt;here&lt;/a&gt;&lt;/span&gt;); unfortunately that was not solved but we got our base for functional programming.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;I think its enough of history; let’s start what this post is all about.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family:Georgia;"&gt;Basic Notations&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Here is how you can represent the previous function in λ calculus:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;λx.x+1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;And if we want to evaluate for x = 2 we write it as:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;br /&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;(λx.x+1)2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Now we can write the same in common lisp as:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;((lambda(x)&lt;br /&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;(+ x 1)) 2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Now functional calculus we have learnt another thing which is higher order functions. Higher order functions are nothing but functions whose arguments are also functions (I will not get into the evaluation debate here).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Like this:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Suppose we have a function f(x) = x + 1 and g(x) = x + 2 and we are calling f(x) as f(g(x)). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;How is it going to be evaluated?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 0.25in"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;f(g(x)) = g(x) + 1 = x + 2 + 1 = x + 3&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 0.25in"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;So how do we represent it lambda calculus?&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;(λx.x+1)(λx.x+2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Now if we want to evaluate this for x = 2 we write it as&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;(λx.x+1)(λx.x+2)2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;In common lisp we write:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;((lambda(x)(+ x 1))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;((lambda(x)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;(+ x 2))2))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family:Georgia;"&gt;Free or Unbound Variable&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;“The variable X is unbound.”&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;How many times you have got this message in your REPL? This comes directly from lambda calculus; here is how. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Any variable that is not a member of any lambda expression is called a free variable and it does not have any effect on the evaluation of that expression. However in programs we cannot use such variable for evaluation. If we do so we get this error message. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;In lambda calculus a variable in cases like this:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;λx.(x * y)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Here the variable y is free. The same happens in common lisp. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;((lambda(x) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;(* x y))1) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family:Georgia;"&gt;Logical Stuffs&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;In programming we use logical operators every day, the two mostly(or *ONLY*) used of them are *AND* and *OR*. How lambda calculus does it?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Before I start I want to give the meaning of the following lambda expression:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;λxy.xxy =&gt; λxy. if x then x or y.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;And this expression is the *OR* function in lambda calculus. So we can write it in common lisp as:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;&lt;span style="font-size:+0;"&gt;&lt;/span&gt;(lambda(x y)&lt;span style="font-size:+0;"&gt; &lt;/span&gt;(if x x y))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;The *AND* function also look quite similar&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Lambda Calculus: λxy.xyx&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Common Lisp: (lambda(x y)&lt;span style="font-size:+0;"&gt; &lt;/span&gt;(if x y x))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;So that’s all about very ugly comparison of lambda calculus and common lisp. I know that I missed lot of things which include reductions and reduction strategies. But one can read about lambda calculus tutorials to get fair idea on this; here is my choice:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span class="a"&gt;&lt;span style="font-size:10;"&gt;&lt;a href="http://www.blogger.com/www.cs.chalmers.se/Cs/Research/Logic/TypesSS05/Extra/geuvers.pdf"&gt;www.cs.chalmers.se/Cs/Research/Logic/TypesSS05/Extra/geuvers.&lt;b&gt;pdf&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span class="a"&gt;&lt;span style="font-size:10;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span class="a"&gt;&lt;span style="font-size:10;"&gt;&lt;a href="http://www.blogger.com/www.utdallas.edu/~gupta/courses/apl/lambda.pdf"&gt;www.utdallas.edu/~gupta/courses/apl/lambda.&lt;b&gt;pdf&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Thanks for reading. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-1442541543688424747?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/u59R95w8fYM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/u59R95w8fYM/lambda-calculus-and-common-lisp.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>2</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/02/lambda-calculus-and-common-lisp.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-9114213997114458581</guid><pubDate>Wed, 06 Feb 2008 05:14:00 +0000</pubDate><atom:updated>2008-02-20T22:23:53.505-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Elisp</category><title>Emacs Lisp: A Note of a Newbie</title><description>&lt;?xml:namespace prefix = o /&gt;&lt;o:p&gt;&lt;/o:p&gt;(Please Note that all the codes/commands are tried in x86 based system running in Windows XP and XEmacs 21.4.20) &lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;I have been learning elisp for couple of weeks just before Steve Yegge came up with his blog on &lt;a href="http://steve-yegge.blogspot.com/2008/01/emergency-elisp.html"&gt;&lt;span style="color:blue;"&gt;Emergency Elisp&lt;/span&gt;&lt;/a&gt;. It is a good introduction to a programming language which is bound to an editor (or the other way around?). His blog talks about the basics of elisp in a nut shell, although lot of people have pointed out mistakes in it, but I feel it must have helped people like me who are learning elisp or will do so in the future. Also if you have looked for elisp tutorials in Google you must have bumped on to &lt;span style="color:blue;"&gt;&lt;a href="http://www.gnu.org/software/emacs/emacs-lisp-intro/emacs-lisp-intro.pdf"&gt;“An Introduction to Programming in Emacs Lisp”&lt;/a&gt; &lt;/span&gt;or &lt;a href="http://xahlee.org/emacs/elisp.html"&gt;&lt;span style="color:blue;"&gt;“Emacs lisp Tutorial”&lt;/span&gt;&lt;/a&gt; . The elisp manual is good for people who have played with the language for some time; but for people who want to start learning elisp it is may not be a good place to be.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;So why am I writing this blog? I found no mention of buffers and windows related stuffs in Steve’s post; as a programmer I felt I should keep notes of my work (as I do in some of my blogs). &lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;When we configure &lt;a style="COLOR: rgb(51,51,255)" href="http://lispsamik.blogspot.com/2007/09/slime-setup-for-windows.html"&gt;SLIME and Emacs&lt;/a&gt; we add some lines to our init.el file which reads some thing like:&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(add-to-list ‘load-path ….)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;So the first thing is how to inspect a variable in Emacs, &lt;b&gt;C-h v&lt;/b&gt; will prompt for the name of the variable you want to check and as soon as you enter the name of the variable it shows you the content of it. Like if I have a variable foo and want to see what the value of foo is.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-INDENT: 0.5in"&gt;Similarly if we want to see the documentation of any function we can use C-h f and enter the name of the function to see its documentation.&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-INDENT: 0.5in"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_-I1Obr-qE7M/R6lEL_8uboI/AAAAAAAAADY/Kad3ONmnRrI/s1600-h/describe-function.GIF"&gt;&lt;img id="BLOGGER_PHOTO_ID_5163733420692369026" style="CURSOR: pointer" alt="" src="http://1.bp.blogspot.com/_-I1Obr-qE7M/R6lEL_8uboI/AAAAAAAAADY/Kad3ONmnRrI/s320/describe-function.GIF" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;But don’t be fooled by these “control h” stuffs as they are nothing but either elisp functions or commands which are bound to some key combinations and keymaps. One can make a function interactive with the user by a using a built in function called (interactive). &lt;i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;b&gt;Buffers and Windows&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;Buffers are lisp objects which hold texts for future editing. So as soon as you start Emacs it starts in a buffer. The most famous buffer is *scratch* buffer. If you do not have any customizations or filename mentioned while opening Emacs, it opens in this buffer by default. Let’s check some buffer related functions.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;Let’s try out a mini project, suppose I have to create a function which will create documents in a predefined manner. How do I do that? The format is as follows:&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 1in; TEXT-INDENT: -0.25in"&gt;Author:&lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 1in; TEXT-INDENT: -0.25in"&gt;Author Email:&lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 1in; TEXT-INDENT: -0.25in"&gt;Company:&lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 1in; TEXT-INDENT: -0.25in"&gt;Abstract:&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;From there on the author will create the rest of the document. &lt;/p&gt;&lt;p class="MsoNormal"&gt;(Note here that I am not going into a lot of details in this and please do take care of the details required before creating a real project.)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;Here is a way how we can do it elisp (please feel free to comment if you have any other idea i.e. more lispy way of doing this).&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;Programmer, who has his lineage from C or Java or JavaScript, knows that if he has to output some string with values extracted from a variable he has to write something like:-&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;C: &lt;span style="font-size:0;"&gt;&lt;/span&gt;printf(“Author:%s”, auth);&lt;/p&gt;&lt;p class="MsoNormal"&gt;Java:&lt;span style="font-size:0;"&gt; &lt;/span&gt;System.out.println(“Author:” + auth);&lt;/p&gt;&lt;p class="MsoNormal"&gt;JavaScript:&lt;span style="font-size:0;"&gt; &lt;/span&gt;alert(“Author:”+auth);&lt;/p&gt;&lt;p class="MsoNormal"&gt;Common Lisp: (format t “Author:~a~%” auth)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;Same applies here also but we do the formatting as following:&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-INDENT: 0.5in"&gt;(format "Author:%s " auth)&lt;/p&gt;&lt;p class="MsoNormal"&gt;I will just quickly note what all the in build functions does and how I have used them.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;ol style="MARGIN-TOP: 0in" type="1"&gt;&lt;li class="MsoNormal"&gt;insert: This function inserts a formatted string in to the current buffer.&lt;/li&gt;&lt;li class="MsoNormal"&gt;newline: As the name suggest it appends a new line.&lt;/li&gt;&lt;li class="MsoNormal"&gt;switch-to-buffer: This function switches to a buffer and displays the buffer.&lt;/li&gt;&lt;li class="MsoNormal"&gt;create-file-buffer: This will create a buffer with the filename (if the buffer exists it appends some extras apropos) and returns that buffer.&lt;/li&gt;&lt;li class="MsoNormal"&gt;save-buffer: This function will prompt the user to save the buffer.&lt;/li&gt;&lt;/ol&gt;&lt;p class="MsoNormal" style="TEXT-INDENT: 0.5in"&gt;(Refer to &lt;a style="COLOR: rgb(51,51,255)" href="http://www.gnu.org/software/emacs/manual/elisp.html"&gt;elisp manual&lt;/a&gt; for details of these function)&lt;/p&gt;&lt;p class="MsoNormal"&gt;Here is the code:&lt;/p&gt;(defun create-the-doc-template (auth &amp;amp;optional email company) &lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(insert (format "Author:%s " auth))&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(newline)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(if (eq email nil)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(insert "Author Email:")&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(insert (format "Author Email:%s " email)))&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(newline)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(if (eq company nil)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(insert "Company:")&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(insert (format "Company:%s " email)))&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(newline)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(insert "Abstract:"))&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;(defun create-file-as-doc(filename Author &amp;amp;optional Auth-Email Comp)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(switch-to-buffer (create-file-buffer filename))&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(create-the-doc-template Author Auth-Email Comp)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(save-buffer))&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;(create-file-as-doc "hello-emacs.txt" "samik" "samikc@gmail.com" "ABC")&lt;/p&gt;&lt;p class="MsoNormal"&gt;(create-file-as-doc "hello-emacs.txt" “samik”)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;Now once you execute the first call it should look like the following:&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_-I1Obr-qE7M/R6lEmf8ubpI/AAAAAAAAADg/VbEWE7baQ4I/s1600-h/elisp-2.GIF"&gt;&lt;img id="BLOGGER_PHOTO_ID_5163733875958902418" style="CURSOR: pointer" alt="" src="http://3.bp.blogspot.com/_-I1Obr-qE7M/R6lEmf8ubpI/AAAAAAAAADg/VbEWE7baQ4I/s320/elisp-2.GIF" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;b&gt;Keyboard Macro&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;The best thing about elisp is that it allows you to hack Emacs completely and you can record a keyboard macro and use it by using a set functions and variables.&lt;/p&gt;&lt;p class="MsoNormal"&gt;The variable &lt;i&gt;last-kbd-board&lt;/i&gt; macro holds the last macro that you have defined and &lt;i&gt;execute-kbd-macro&lt;/i&gt; does repeat the last macro defined by you in the current line. This can help you build a function that will repeat the macro in vary large file.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;(defun do-macro()&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(interactive)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;(execute-kbd-macro last-kbd-macro))&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;So that’s all for now…&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;Thanks for reading.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-9114213997114458581?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/8lO-VLKG3Kc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/8lO-VLKG3Kc/emacs-lisp-note-of-newbie.html</link><author>noreply@blogger.com (samik chakraborty)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_-I1Obr-qE7M/R6lEL_8uboI/AAAAAAAAADY/Kad3ONmnRrI/s72-c/describe-function.GIF" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/02/emacs-lisp-note-of-newbie.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-3652730924343989718</guid><pubDate>Wed, 30 Jan 2008 05:21:00 +0000</pubDate><atom:updated>2008-02-20T22:25:27.154-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Arc</category><title>Arc in Windows</title><description>&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Arc was released on 29&lt;sup&gt;th&lt;/sup&gt; January; just one day back; I started working with it in Windows. How to use our Arc in Windows; here is a quick way to start.&lt;?xml:namespace prefix = o /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;First thing first go to &lt;a href="http://arclanguage.org/install"&gt;http://arclanguage.org/install&lt;/a&gt; and read the notes there carefully. It is a very small and well written guide how to get started in Arc. However for windows the first thing you have to do is to download and install &lt;span style="color:red;"&gt;&lt;a href="http://download.plt-scheme.org/mzscheme/"&gt;MzScheme&lt;/a&gt; &lt;/span&gt;first. So here is the step by step guide to your Arc setup in Windows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;ol style="MARGIN-TOP: 0in" type="1"&gt;&lt;li class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Download Arc.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Unzip Arc in a directory I use c:\Arc0.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Download MzScheme version 352(for Windows) from &lt;a href="http://download.plt-scheme.org/mzscheme/"&gt;http://download.plt-scheme.org/mzscheme/&lt;/a&gt; . You will land to the latest release download page which version 372. Click on the other version link and select V352 (as arclanguage.org suggests the use of v352; so please follow the canonical way.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Once you have MzScheme installer run it. I have used C:\Program Files\MzScheme as installation directory you can use your own directory.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Go to your MzScheme directory and run the command Setup PLT.exe from the command prompt. Watch out for the line which says something like this:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p class="MsoNormal" style="TEXT-INDENT: 0.5in"&gt;&lt;span style="font-family:Georgia;"&gt;setup-plt: Collection search path is&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-INDENT: 0.5in"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;setup-plt: C:\[some-directories]\Application Data\PLT Scheme\352\collects&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 0.5in"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;ol style="MARGIN-TOP: 0in" type="1" start="6"&gt;&lt;li class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Go to this directory and check whether the path exits or not and properly populated. If not then create the required directories and sub directories and copy the collects folder from your MzScheme folder.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Everything should be ready by now do a cd to your Arc folder and run the following command:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 1in"&gt;&lt;span style="font-family:Georgia;"&gt;mzscheme –m –f as.scm&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;That’s it start hacking Arc. &lt;span style="font-size:0;"&gt;&lt;/span&gt;If you have any problem feel free to post a comment will try to answer as fast as possible.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-3652730924343989718?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/jhLly42qP6Q" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/jhLly42qP6Q/arc-in-windows.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>4</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/01/arc-in-windows.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-2854040190511122064</guid><pubDate>Tue, 29 Jan 2008 05:09:00 +0000</pubDate><atom:updated>2008-02-29T00:32:14.686-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><title>Logical Nirvana – How Programming Languages and Our Thoughts Are Linked</title><description>&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;A programming language can change the way you think about programming; this is true but not the whole truth. Most of us when we code we try to think about a problem and we try to figure out how to solve the problem in a programming language. I do not want reiterate the same example of how BASIC does not allow you to think about recursion blah, blah, blah; but what I want to point out here is that at the time of solving a problem we actually solve the problem in our mind first and then we start coding. At the time of coding we start thinking in a programming language not before that. If some problem can be solved by a human being it can be solved by a computer. It may be tedious to put the logic but it can be done. Like as we have programs which can play chess better than most of us. So this simply means we just map our logic, which we develop in our mind, to a programming language. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Now this mapping requires us to translate the problem in a computer language. Now for example if we need to do an operation which is very low level we can do it very easily. But if the operation is complex we need to do a lot of sub operations, so at the time of translating the logic to a computer action we need to give bridging of more fundamental statements. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Now how a programming language can help you in doing this mapping? Simple it will provide you operations which are close to your logical system. It might not match the exact logical unit that you have in your mind but it can significantly reduce the number of statements that you write in that programming language. So if a programming language allows you to do some job in 10 statements and another programming language allows you to do the same job in 3 statements then it is better to use the second programming language. Plain and simple! But this is not so simple in this world and that’s why we have programming languages which require at least 4 lines to print “Hello World!!!”, moreover those programming languages are so called *MARKET LEADERS*. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Now let us return to our discussion on programming language and thinking process. The problem of mapping get worse if you are working in a programming language which is vary far from your solution in your brain; then you have to start from your end (Top-down approach) or from the programming language end(bottom up) and bring these two things to a single point and then it should work. What we are trying here is building of higher order logic from existing logical system in the programming language. So end of the day we are doing nothing but mapping of two logical systems.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Here I feel that the greatest realization of every programmer is what we are trying, while programming is not only solving a problem but also understanding our logic; the logic which lies beneath our mind. So the question is if a programming language does not allow us to think beyond certain point should we continue with that or let our thought go to wildest of imaginations where the boundaries are endless with a programming language that has no limitations.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;&lt;o:p&gt;&lt;/o:p&gt;So let’s reach out for that logical nirvana.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Georgia;"&gt;Thanks for reading.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-2854040190511122064?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/pBJpehN0mU8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/pBJpehN0mU8/logical-nirvana-how-programming.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/01/logical-nirvana-how-programming.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-5401352552272238404</guid><pubDate>Fri, 18 Jan 2008 11:42:00 +0000</pubDate><atom:updated>2008-02-20T22:25:56.766-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">common lisp</category><title>A Tale of Two Loosely Typed Languages</title><description>&lt;span style="font-family:georgia;"&gt;&lt;hr /&gt;&lt;br /&gt;Disclaimer: I love JavaScript and this blog is not a defaming blog for JavaScript.&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;We all know that JavaScript is a loosely typed language; there are advantages of being loosely typed. You need not to think about what will be the data types of a particular variable and work with that variable. But a newbie to a loosely typed language will miss a lot of details which is required to code in such a language. (As I am writing this I consider me as newbie in most of the cases in programming). But still this blog is all about the mistakes that we all make and learn from them.&lt;br /&gt;&lt;br /&gt;If you are reading this blog I can safely assume that you have some interest in programming in languages like JavaScript, Lisp or Scheme which are strictly speaking examples of great loosely typed language. Albeit I have doubts in my mind about &lt;a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf"&gt;ECMAScript&lt;/a&gt; that it might not remain as loosely typed as now with its reserve words containing char, int, long, float etc. But nevertheless I will take presently implemented format of well good JavaScript which still allows me and other programmers to write code free from types.&lt;br /&gt;&lt;br /&gt;The most important concept while programming in any loosely typed programming language is the understanding of how my function is going to behave on certain inputs. If the function is a pure function you need not to worry, however in WWW we do not write much of a code like pure functions. But even pure functions can behave absolutely insane if you allow them to do so. How? Here is a code for a function in JavaScript which takes two numbers as its arguments and adds them (&lt;a href="http://www.w3schools.com/js/default.asp"&gt;If you do not know JavaScript you can click here for a tutorial&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;function add(x,y) { alert(x+y); }&lt;br /&gt;&lt;br /&gt;I call this function as add(4,5) and as expected it pops 9. Good now if I try to call this function like this add(“hello”,5) what am I suppose to get?&lt;br /&gt;&lt;br /&gt;Let us now stop this for a moment and try the same function in Lisp, the function in Lisp should look like:&lt;br /&gt;&lt;br /&gt;(defun add(x y) (+ x y))&lt;br /&gt;&lt;br /&gt;Now if I call the function in Lisp like (add 4 5) it will evaluate to 9 but if I try to call this add function with “hello” and 5, we will be in the debugger saying something like ‘Argument X is not a NUMBER: “hello”’ (my Lisp is SBCL).&lt;br /&gt;&lt;br /&gt;Now what happens in JavaScript it will pop you a message box saying “Hello5”. That’s right, the + operator in JavaScript does two things it adds in case of a number and it also concatenates strings and moreover when it finds a string in any side of it, it forgets the other job that it can perform and it just concatenates. That is ok for me a language can do that like Java does the exact same thing. So to be sure about what you want from your function you need to check your input for certain type before you do this addition operation.&lt;br /&gt;&lt;br /&gt;In JavaScript I as a programmer has to make sure that all the arguments to the function are as I was expecting before I pass them to an operation. In our case it is addition. In Lisp we can we will use restarts using condition handlers. We need to understand here that first way is static checking and the second one is dynamic checking at the run-time. The importance of conditional restarts are more felt where we have to take care of more complex functions.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-5401352552272238404?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/DUF0BRrQEKA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/DUF0BRrQEKA/tale-of-two-loosely-typed-languages.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>3</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/01/tale-of-two-loosely-typed-languages.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-8557132972228121598</guid><pubDate>Wed, 16 Jan 2008 05:55:00 +0000</pubDate><atom:updated>2008-02-29T00:31:26.575-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><title>Evolution of Programming</title><description>The RISC architecture is good, as they say anything small and working is good! This is my fellow programmers is a philosophy of *nix*; how many years has gone by? Stupid thirty years and do not question it; because that’s the best idea we have got and we are following it. Doing great stuff, building systems on top of it, I agree. But has it ever came to your mind that why this is like THIS? Why we have to use the same old RISC for our computing? The answer is we have stopped innovating in the real sense. We now know that we need more data types, arithmetic operations and better instruction set to carry out an operation. But at the end of the day all we have is a *MOVE* or *STORE* or *LOAD* and we say that Lisp, Java or Ruby runs slowly. These programming languages are not close to low level and thus will take some time to actually execute it in our cute processors.&lt;br /&gt;&lt;br /&gt;           Tomorrow if we try to develop a programming language which is more higher level we will not be able to convince our bosses that this is the right way of doing things. Because they will tell us, “look at the performance man!” And an innovation will die. Once upon a time C was considered higher level language than machine language, yes true but you need to write a 20 lines of code to reverse a link list or worse link list is not a basic data types.&lt;br /&gt;&lt;br /&gt;           I do not blame any one but tell me is it fair to ask a student of computer science to write a link list reversal program in Java. I don’t think so. If you can declare link list as a data type and you have a method to reverse it please reverse it using that; and if your computer is taking more time to do that for link list of 10000 elements blame it on the computer not the programming language even if the C/C++ implementation is taking less time. This is because of the abstraction that this high level programming language is providing. C/C++ on the other hand is good because there is very low level abstraction in it and you have to build rest of the thing.&lt;br /&gt;&lt;br /&gt;           In programming world this is like saying to the programmer it’s my way or highway. So if the instructions set are evolved up to the level of say C then what happens? The magic starts then you can still program in C as now you still have a choice program in assembly language; but it will be better to choose a higher level language.&lt;br /&gt;&lt;br /&gt;           We have come from binaries to pneumonic to assembly, but we are long due for the next higher level let us just take the next step, and which programming language we should choose is up for debate…..or is it not clear?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-8557132972228121598?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/h1NceEbMGwY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/h1NceEbMGwY/evolution-of-programming.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2008/01/evolution-of-programming.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1369853434158175571.post-2804868833927934473</guid><pubDate>Mon, 31 Dec 2007 07:06:00 +0000</pubDate><atom:updated>2008-02-20T22:26:28.836-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SBCL</category><category domain="http://www.blogger.com/atom/ns#">SLIME</category><category domain="http://www.blogger.com/atom/ns#">common lisp</category><title>SLIME - How to Profile in Lisp</title><description>If you have worked on a fairly *BIG* project you must have heard people saying, "Let's profile it first." When I started lisp programming I was clueless about profiling a lisp code. This was fairly easy in other programming languages by the tools they provide; I knew how to profile C/C++ code with GCC compiler options but not for lisp.&lt;br /&gt;Here I am going to explain how to profile lisp codes using SLIME.&lt;br /&gt;Suppose you have a function:&lt;br /&gt;&lt;div style="TEXT-ALIGN: left"&gt;&lt;br /&gt;(defun foo()&lt;br /&gt;(format t "Hello foo"))&lt;br /&gt;&lt;br /&gt;and you call it like:&lt;br /&gt;&lt;br /&gt;(loop for n&lt;br /&gt;from 1 to 1000&lt;br /&gt;do(progn&lt;br /&gt;(print n)&lt;br /&gt;(foo)))&lt;br /&gt;&lt;br /&gt;Now you have to find how much time foo has taken. Below are the steps for that:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Run the command: M-x slime-toggle-profile-fdefinition and hit enter. It will ask you the function name you want to profile. Enter the function name (foo in our case) you want to profile.&lt;/li&gt;&lt;li&gt;Now run the function; as in our example we will run the loop for getting more data.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;To see the profile data use command M-x slime-profile-report. This will show the profiled data in the format below:&lt;/li&gt;&lt;/ul&gt;seconds  consed  calls  sec/call  name&lt;br /&gt;-----------------------------------------------------&lt;br /&gt;0.015  587,712  1,000  0.000015  FOO&lt;br /&gt;-----------------------------------------------------&lt;br /&gt;0.015  587,712  1,000   Total&lt;br /&gt;&lt;br /&gt;estimated total profiling overhead: .002 seconds&lt;br /&gt;overhead estimation parameters:&lt;br /&gt;0.0s/call, 2.03e-6s total profiling, 9.36e-7s internal profiling&lt;br /&gt;&lt;br /&gt;There is profiling options for packages. For more details you can refer to &lt;a href="http://fresh.homeunix.net/~luke/misc/lisp/slime.pdf"&gt;SLIME Manual&lt;/a&gt;. &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1369853434158175571-2804868833927934473?l=lispsamik.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/lispsamik/~4/CO3Ah3yqAJ4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/lispsamik/~3/CO3Ah3yqAJ4/slime-how-to-profile-in-lisp.html</link><author>noreply@blogger.com (samik chakraborty)</author><thr:total>0</thr:total><feedburner:origLink>http://lispsamik.blogspot.com/2007/12/slime-how-to-profile-in-lisp.html</feedburner:origLink></item></channel></rss>

