<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>deflisp</title>
	<atom:link href="http://deflisp.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://deflisp.wordpress.com</link>
	<description>an attempt at making Common LISP simpler.</description>
	<lastBuildDate>Mon, 22 Jun 2009 23:12:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='deflisp.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>deflisp</title>
		<link>http://deflisp.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://deflisp.wordpress.com/osd.xml" title="deflisp" />
	<atom:link rel='hub' href='http://deflisp.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Change discourage to encourage</title>
		<link>http://deflisp.wordpress.com/2009/06/22/discourage-and-encourage/</link>
		<comments>http://deflisp.wordpress.com/2009/06/22/discourage-and-encourage/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 18:03:41 +0000</pubDate>
		<dc:creator>deflisp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[optimalization]]></category>
		<category><![CDATA[Paul Graham]]></category>
		<category><![CDATA[planning]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://deflisp.wordpress.com/?p=36</guid>
		<description><![CDATA[Working with projects may seem boring and discouraging at times, most likely because of all the great tasks you have to do. The key in order to avoid this bugger, which will certainly increase the time to finish the project, is to split the program up in smaller bits, and try to make a prototype [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deflisp.wordpress.com&amp;blog=8220927&amp;post=36&amp;subd=deflisp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Working with projects may seem boring and discouraging at times, most likely because of all the great tasks you have to do. The key in order to avoid this bugger, which will certainly increase the time to finish the project, is to split the program up in smaller bits, and try to make a prototype as soon as possible. Try to avoid as much planning as possible:</p>
<blockquote><p>&#8220;<strong>Why do you advise plunging right into a programming project instead of carefully planning it first?</strong></p>
<p>If you&#8217;re trying to solve a simple, predefined problem like doing a depth-first search, thinking everything out beforehand doesn&#8217;t hurt. But few real problems are like that. In real-world applications, you don&#8217;t usually know at first precisely what problem you&#8217;re trying to solve. So if you spend a lot of time planning in advance, what you&#8217;ll end up with is a minutely detailed plan for solving the wrong problem.</p>
<p>With complex, ill-defined problems, you&#8217;re better off writing a prototype as fast as you can, seeing what turns out to be wrong with it, and then changing your definition of the problem accordingly.</p>
<p>Often the reason programmers are pushed into planning is not that the problem requires it, but that project managers require it. Maybe programmers should give managers an explicit choice: do you want me to solve the problem in the way that will make you feel good, or the way that will yield the best solution.&#8221;<br />
Paul Graham &#8211; <a href="http://www.paulgraham.com/pfaq.html">Programming FAQ</a></p></blockquote>
<p>To give you an example, I&#8217;m currently trying to start making a calculator (with GUI) which manages to calculate physical data, such as force based on the electromagnetic force between two objects and such. In order to do that, I could startup by sorting everything. I would most likely try to make some code which may calculate the electronic force or the gravitational force, all depending on the input values. That is, because these are similar. And here you see the issue with planning: I can&#8217;t make prototypes fast if I start with optimalization fast. Thus, I can&#8217;t check for errors, nor enjoy the prototype itself.</p>
<p>Now, instead of messing all that stuff up, I&#8217;ll try and make a function which focus on special relativity instead. What about the momentum? Let&#8217;s start off with that:</p>
<p>We know that</p>
<p><img class="alignnone" src="http://latex.codecogs.com/gif.latex?p%20=%20\frac{mv}{\sqrt{1-(v/c)^2}}%20=%20\gamma%20mv" alt="" /></p>
<p>and that c = 3.0 * 10^8 m/s</p>
<p>A simple function which calculates the momentum would thus be written in Java as</p>
<pre class="brush: java;">
static final double c = 3.0 * Math.pow(10, 8);

static momentum(double m, double v) {
    double p = m * v / gamma(v);
    return p;
}

static gamma(double v){
   return (Math.sqrt(1 - Math.pow(v/c, 2));
}
</pre>
<p>(I&#8217;m writing in Java because Applets and Lisp doesn&#8217;t seem to be friends at the current moment.)</p>
<p>Most likely, I would have put the whole expression into the momentum-function in the beginning. That is, I would put the gamma-function directly into the momentum-function. After I notice that the momentum-function works fine this way, I drag it out and recheck.</p>
<p>Most people know this already, but I just want to ensure people know it and do it. Also, please avoid thinking about optimalization at the current moment, you&#8217;ll have tons of time for that later on. Besides, it&#8217;s more fun to actually be done, then optimalizate later on.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/deflisp.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/deflisp.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/deflisp.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/deflisp.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/deflisp.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/deflisp.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/deflisp.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/deflisp.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/deflisp.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/deflisp.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/deflisp.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/deflisp.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/deflisp.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/deflisp.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deflisp.wordpress.com&amp;blog=8220927&amp;post=36&amp;subd=deflisp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://deflisp.wordpress.com/2009/06/22/discourage-and-encourage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bf54b7bb38d3985735f575f0d593ad01?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">deflisp</media:title>
		</media:content>

		<media:content url="http://latex.codecogs.com/gif.latex?p%20=%20\frac{mv}{\sqrt{1-(v/c)^2}}%20=%20\gamma%20mv" medium="image" />
	</item>
		<item>
		<title>elt, nth, aref, svref, gethash, char, schar? No thanks.</title>
		<link>http://deflisp.wordpress.com/2009/06/20/arrays/</link>
		<comments>http://deflisp.wordpress.com/2009/06/20/arrays/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 09:33:26 +0000</pubDate>
		<dc:creator>deflisp</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[common lisp]]></category>
		<category><![CDATA[macros]]></category>

		<guid isPermaLink="false">http://deflisp.wordpress.com/?p=5</guid>
		<description><![CDATA[Why bother with all these different functions in lisp in order to reach an element? The syntax should be easier, more convenient, and clearer.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deflisp.wordpress.com&amp;blog=8220927&amp;post=5&amp;subd=deflisp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>elt, nth, aref, svref, gethash, char, schar? No thanks.<br />
While working with a Python package for a program roughly one month ago, I realized that Python had a much better syntax for list/array/hash-processing than Common LISP without any macros involved. Compare these pieces of code:</p>
<pre class="brush: python;">x = 5
newLst = [y[x] for y in [lst, array, ht, string]]</pre>
<pre class="brush: python;">
(setf x 5
      new-lst
  (list (nth x lst)
        (aref array x)
        (gethash x ht)
        (schar string x)))</pre>
<p>Now, as shown, python is incredibly much shorter due to its ability to get data from lists, arrays, hash-tables and strings. Are we able to recreate this with macros in Common LISP? Possibly, yes.<br />
The main issue is just the hash-table, which you cannot use the function elt on. Otherwise, you could just make dispatch-macros and use elt accordingly with it. So this macro has to evaluate and check the type of the element we&#8217;re dragging out. Consider it as a cond-evaluation (I prefer if-ing it):</p>
<pre class="brush: python;">
(if (typep ,sequence 'hash-table)
    (gethash ,@args ,sequence)
(if (typep ,sequence 'array)
    (aref ,sequence ,@args)
    (elt ,sequence ,@args)))</pre>
<p>The “prettiest” way of using this macro is most likely by making the macro operate in this way:</p>
<pre class="brush: python;">[hash-table key]
[multidimensional-array 1 2 3]
[list 4]</pre>
<p>Now, we can define the former long expression to a rather short one:</p>
<pre class="brush: python;">
(setf x 5
      new-lst (mapcar #'(lambda (y) [y x])
              '(lst array ht string)))
; Or  (loop for y in '(lst array ht string) collect [y x])</pre>
<p>Albeit, it&#8217;s rather inefficient compared to the former expression.<br />
But why stop there? I mean, in Python, I used the [x:y:z]-syntax to make a simple PNG-parser which gave the pixel-value of each pixel in the image. Why shouldn&#8217;t Lispers have this possibility as well? To be honest, there is none but the lack of such an idea.</p>
<pre class="brush: python;">
&gt;&gt; x = “Hello World!”
&gt;&gt; x[:5] # Evaluates to x[0:5]
'Hello'
&gt;&gt; x[::2] # Evaluates to x[0:len(x):2]
'HloWrd'</pre>
<p>In lisp, this would be possible to express as</p>
<pre class="brush: python;">
(setf x “Hello World!”)
[x :5]
[x ::2]</pre>
<p>Now, expanding it to have more pythonic ways of working, we may add negative numbers as well:</p>
<pre class="brush: python;">
[x -1] ; Last character in the string
[x :-1] ; All but last character in the string
[x ::-1] ; Reverses the string.</pre>
<p>I would assume this would shorten lisp-code by a lot, due to the increase of abstraction. But, as we all know, this comes with a price: Slower speed.</p>
<p>I&#8217;ve thought a lot about that issue, but I came to the conclusion that with a good compiler, this would only be slower in cases where you haven&#8217;t defined the type of the elements. And those cases usually seem to be a prototype-stadium.</p>
<p>Another thing which I would really want a compiler to do when we&#8217;re at it, is making code more efficient by converting the first statement into the second statement</p>
<pre class="brush: python;">
(write-string [string 0:5] out) ; Inefficient
(write-string string out :start 0 :end 5) ; Efficient</pre>
<p>This also yields for all other functions which works like this one.</p>
<p>But let me go deeper. I want a code which exceeds Python&#8217;s capacity in terms of abstraction. In order to do that, I&#8217;m going to state something which is obvious for most people in the programming world: Data within a computer is based upon bits: zeroes and ones.</p>
<p>Now, what has this to do with sequences and hash-tables? Pretty much everything: A number is a number, but is also an array of bits. A string is a string, and an array of characters. A character is a converted number, and a number is an array of bits. What about manipulating these bits through Lisp?<br />
In order to actually manipulate bits and bytes in Lisp through this method, you&#8217;ll have to think multidimensional arrays: All elements are made up either by arrays of bits, arrays of arrays, or a combination. We could say that all elements are made up by ts and nils, apart from t and nil.</p>
<p>In order to manipulate this data directly would mean that setf-ing this would be a destructive modification. Not only that, but in order to speed up the code, a []-array would return pointers to the bits, bytes or object. Also, the array would have an element-type (unless we&#8217;re bracketing a hash-table or an array)  to prevent possible errors. In other words, this would always return a displaced array. How to get a copy instead? Take advantage of copy-seq or copy-alist.<br />
An example of how this could be utilized is by making a xor-function which repeat an xor-pattern on an ASCII-string:</p>
<p><font face="monospace" size="3"><font color="#6a5acd">(</font><font color="#a52a2a"><b>defun</b></font>&nbsp;xor&nbsp;<font color="#6a5acd">(</font>xor&nbsp;size&nbsp;<font color="#a52a2a"><b>string</b></font><font color="#6a5acd">)</font><br />
&nbsp;&nbsp;<font color="#ff00ff">&quot;(xor xor-num size string) returns an xored-string where xor-num is</font><br />
<font color="#ff00ff">&nbsp;&nbsp; the number which will perform the xoring, and size is the amount</font><br />
<font color="#ff00ff">&nbsp;&nbsp; of bits the xor-number is (e.g. 32 or 64, though ‘non-byte’ </font><br />
<font color="#ff00ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; values may be used as well)&quot;</font><br />
&nbsp;&nbsp; <font color="#6a5acd">(</font><font color="#a52a2a"><b>let</b></font>&nbsp;<font color="#6a5acd">((</font>xor-bitlst&nbsp;<font color="#6a5acd">(</font><font color="#a52a2a"><b>coerce</b></font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#6a5acd">(</font><font color="#a52a2a"><b>copy-seq</b></font>&nbsp;[xor&nbsp;<font color="#2e8b57"><b>:size</b></font>]<font color="#6a5acd">)</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#6a5acd">&#8216;</font><font color="#008b8b">list</font><font color="#6a5acd">))</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#6a5acd">(</font>new-string&nbsp;<font color="#6a5acd">(</font><font color="#a52a2a"><b>copy-seq</b></font>&nbsp;<font color="#a52a2a"><b>string</b></font><font color="#6a5acd">)))</font><br />
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#6a5acd">(</font><font color="#a52a2a"><b>nconc</b></font>&nbsp;xor-bitlst&nbsp;xor-bitlst<font color="#6a5acd">)</font>&nbsp;<font color="#0000ff">; Circular list.</font><br />
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#6a5acd">(</font><font color="#a52a2a"><b>loop</b></font>&nbsp;for&nbsp;xor-bit&nbsp;in&nbsp;xor-bitlst<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for&nbsp;val-bit&nbsp;in&nbsp;[new-string&nbsp;:&nbsp;:8]<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for&nbsp;i<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#a52a2a"><b>do</b></font>&nbsp;<font color="#6a5acd">(</font><font color="#a52a2a"><b>setf</b></font>&nbsp;[new-string&nbsp;:&nbsp;:8]&nbsp;<font color="#6a5acd">(</font><font color="#a52a2a"><b>logxor</b></font>&nbsp;xor-bit&nbsp;val-bit<font color="#6a5acd">)))</font><br />
&nbsp;&nbsp;&nbsp;&nbsp; new-string<font color="#6a5acd">))</font></font></p>
<p>Which raises a lot of interesting questions: How do one actually represent an integer as an array if bits? One may assume that [x] would return the “whole” bit-array of x. But for an integer, [x] would be infinite, so that&#8217;s out of the question. Rather, [x] would be short for [x :(1+ (integer-length x))]. Thus, [1] would return #*10, -1 would yield #*11, -4 would yield #*001. Basically, the bit-vector returned would be signed, and in the “opposite” way.</p>
<p>In order to find out whether a number is negative, one can just do [x -1]. If [x -1] returns true, then the number is negative. Else, the number is zero or positive. Trying to modify the value of this would give you an error.<br />
Take note that [x y:z] will always give an error if x is an integer, y is a non-negative integer and z is a negative integer.<br />
If y is a negative integer, then the array returned could have been represented as <code>(make-array (-  y z) :element-type 'bit :initial-element [x -1])</code>. However, as this array would be impossible to modify, it would be causing more trouble than usefullness.</p>
<p>Another interesting thing included, though most likely not frequently used, would be the offset-addon. Python has the list[x:y:z]-possibility. Lisp should have the [list w:x:y:z]-possibility, where y is the offset for the list. This would work as :displaced-offset-index in make-array. Thus, (eq [list :::4] [list :4]) should be true, and (subseq list (+ w z) (+ x z)) would eq [list w:x::z].</p>
<p>Now, only the last part remains: A macro which will be implemented in any lisp-compiler which actually does this job for us. It will give programs a faster development-process, and it would be about as fast as programs without these macros as well. It&#8217;s a win-win situation.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/deflisp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/deflisp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/deflisp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/deflisp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/deflisp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/deflisp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/deflisp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/deflisp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/deflisp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/deflisp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/deflisp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/deflisp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/deflisp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/deflisp.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=deflisp.wordpress.com&amp;blog=8220927&amp;post=5&amp;subd=deflisp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://deflisp.wordpress.com/2009/06/20/arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bf54b7bb38d3985735f575f0d593ad01?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">deflisp</media:title>
		</media:content>
	</item>
	</channel>
</rss>
