<?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>Musings of a would be lispnik</title>
	<atom:link href="http://lispwannabe.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://lispwannabe.wordpress.com</link>
	<description>common blog on common lisp (and whatever else)</description>
	<lastBuildDate>Tue, 30 Aug 2011 05:12:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='lispwannabe.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Musings of a would be lispnik</title>
		<link>http://lispwannabe.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://lispwannabe.wordpress.com/osd.xml" title="Musings of a would be lispnik" />
	<atom:link rel='hub' href='http://lispwannabe.wordpress.com/?pushpress=hub'/>
		<item>
		<title>DSL in lisp</title>
		<link>http://lispwannabe.wordpress.com/2011/08/09/dsl-in-lisp/</link>
		<comments>http://lispwannabe.wordpress.com/2011/08/09/dsl-in-lisp/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 00:31:29 +0000</pubDate>
		<dc:creator>lispwannabe</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lispwannabe.wordpress.com/?p=75</guid>
		<description><![CDATA[Since most of the traffic here is linking to the post I had on working with a lexer/yacc in lisp, I thought that I&#8217;d share a link to a post on a more &#8216;lispy&#8217; way to approach the issue. Paul says : To a CL&#8217;er, infix notation is just unnecessary syntactic sugar. Many novice CL&#8217;ers [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=75&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since most of the traffic here is linking to the post I had on working with a lexer/yacc in lisp, I thought that I&#8217;d share a link to a post on a more &#8216;lispy&#8217; way to approach the issue. </p>
<p><a href="http://lists.common-lisp.net/pipermail/pro/2011-July/000621.html" title="Lisp and DSLs" target="_blank"></a></p>
<p>Paul says :</p>
<blockquote><p>To a CL&#8217;er, infix notation is just unnecessary syntactic sugar.  Many novice CL&#8217;ers try to create macros that understand infix notation early on in their careers, but as they become more familiar with the power of CL, they drop the syntatic sugar and use parse trees directly.</p></blockquote>
<p>Which is true &#8211; the structure of lisp is exactly what you get when you run a bunch of infix code through a lex/yac or even an ANTLR combination. </p>
<p>The problem that I had when I was investigating the issue was that most people don&#8217;t think in prefix notation the way a lisper would! The prefix (also know as &#8216;abstract syntax tree&#8217; or AST for short) notation is much easier to deal with from a programming perspective, which is why the first step for almost all compilers is to translate things down to AST format. This is why the above advice makes perfect sense if you are creating a DSL for yourself, but may not work if you are trying to create one for the rest of the world.</p>
<p>Just random thoughts . . .</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lispwannabe.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lispwannabe.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lispwannabe.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lispwannabe.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lispwannabe.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lispwannabe.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lispwannabe.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lispwannabe.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lispwannabe.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lispwannabe.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lispwannabe.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lispwannabe.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lispwannabe.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lispwannabe.wordpress.com/75/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=75&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lispwannabe.wordpress.com/2011/08/09/dsl-in-lisp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd8ec3b6ac5c6798688ff487e9b72014?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lispwannabe</media:title>
		</media:content>
	</item>
		<item>
		<title>Undo/ rollback in elephant on lisp</title>
		<link>http://lispwannabe.wordpress.com/2011/08/09/undo-rollback-in-elephant-on-lisp/</link>
		<comments>http://lispwannabe.wordpress.com/2011/08/09/undo-rollback-in-elephant-on-lisp/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 00:08:55 +0000</pubDate>
		<dc:creator>lispwannabe</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lispwannabe.wordpress.com/?p=72</guid>
		<description><![CDATA[This morning I accidentally deleted a bunch of stuff in a elephant store for lisp. I was using the standard berkeley DB. I was worried that everything I had done was totally gone. Luckily you can do a db_recover to a specific date/time db_recover -t as a side note, I was trying to use db_printlog [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=72&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This morning I accidentally deleted a bunch of stuff in a elephant store for lisp. I was using the standard berkeley DB. I was worried that everything I had done was totally gone.</p>
<p>Luckily you can do a db_recover to a specific date/time</p>
<p>db_recover -t </p>
<p>as a side note, I was trying to use db_printlog and it kept giving me an error about environment mismatch. After messing around with this for an obscene amount of time, I discovered that if you do much of anything with elephant, there are a bunch of __db.00x files out there. If you do a db_recover, (I would close your elephant store first, don&#8217;t know if it makes a difference) all of those files are gone and db_printlog (and a few other things) work fine. If you are sure that your executables are of the same flavor (i.e. 4.5 or 4.7 etc.) and you are having &#8216;version mismatch&#8217; errors, give db_recover a try first.</p>
<p>Hope this helps!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lispwannabe.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lispwannabe.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lispwannabe.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lispwannabe.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lispwannabe.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lispwannabe.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lispwannabe.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lispwannabe.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lispwannabe.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lispwannabe.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lispwannabe.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lispwannabe.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lispwannabe.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lispwannabe.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=72&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lispwannabe.wordpress.com/2011/08/09/undo-rollback-in-elephant-on-lisp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd8ec3b6ac5c6798688ff487e9b72014?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lispwannabe</media:title>
		</media:content>
	</item>
		<item>
		<title>Allocating memory using Clozure FFI</title>
		<link>http://lispwannabe.wordpress.com/2010/01/31/allocating-memory-using-clozure-ffi/</link>
		<comments>http://lispwannabe.wordpress.com/2010/01/31/allocating-memory-using-clozure-ffi/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 01:22:40 +0000</pubDate>
		<dc:creator>lispwannabe</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lispwannabe.wordpress.com/?p=62</guid>
		<description><![CDATA[What I did in the previous post is fine if we want to write a file right to disk, but what if we want to get the image data back from ImageMagick? To do this we will need to use the #_MagickGetImageBlob call. From the ImageMagick Documentation: MagickGetImageBlob MagickGetImageBlob() implements direct to memory image formats. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=62&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>What I did in the previous post is fine if we want to write a file right to disk, but what if we want to get the image data back from ImageMagick?</p>
<p>To do this we will need to use the #_MagickGetImageBlob call.</p>
<p>From the ImageMagick <a href="http://www.imagemagick.org/api/magick-image.php#MagickGetImageBlob">Documentation</a>:</p>
<p><code></p>
<pre>
 MagickGetImageBlob

MagickGetImageBlob() implements direct to memory image formats.
 It returns the image as a blob and its length.
Use MagickSetFormat() to set the format of the returned blob (GIF,
 JPEG, PNG, etc.).

Use MagickRelinquishMemory() to free the blob when you are done with it.

The format of the MagickGetImageBlob method is:

  unsigned char *MagickGetImageBlob(MagickWand *wand,size_t *length)
A description of each parameter follows:

wand

the magick wand.

length

the length of the blob.
</pre>
<p></code><br />
We have already made plenty of calls where we use a pointer to MagickWand, but we have not yet done anything where we need to allocate memory to pass to our foreign function.</p>
<p>Luckily this isn&#8217;t too hard and this is a pretty trivial example.  </p>
<p>First we set up the environment. I&#8217;m assuming we&#8217;ve done the stuff that I described in my first part of the tutorial, that is, set up the interface directory.</p>
<p><code></p>
<pre>
CL-USER&gt; (ccl:use-interface-dir :imagemagick)
#

CL-USER&gt; (ccl:use-interface-dir :libc)
#
; we load the libc interface so that we know what size size_t is

CL-USER&gt;   (ccl:open-shared-library "libMagickWand.so")
#

CL-USER&gt; (setf wand (#_NewMagickWand))
#&lt;A Foreign Pointer#x1CB83F0 &gt;

CL-USER&gt; (#_MagickSetSize wand 100 100)
1

CL-USER&gt; (with-cstrs ((image-format "png"))
	   (#_MagickSetFormat wand image-format))
;Compiler warnings :
;   In an anonymous lambda form: Undeclared free variable WAND
1

CL-USER&gt; (with-cstrs ((red-image "xc:red"))
	   (#_MagickReadImage wand red-image))
;Compiler warnings :
;   In an anonymous lambda form: Undeclared free variable WAND
1
</pre>
<p></code></p>
<p>Now we have a wand that is a png, 100&#215;100 and solid red. What we want to do next is allocate our memory, call our blob function, convert the return value to a string and free all of the memory.</p>
<p>To create the space for the length, we use the make-record macro (found in the FFI <a href="http://ccl.clozure.com/manual/chapter12.12.html">Documentation</a>). Once we do this, we can call the Blob function.</p>
<p>The make-record macro retuns a pointer, and to be able to see what is in the memory at the pointer, we can use the ccl:pref function, and to free the pointer that we created, we use the ccl:free function. To translate c data to a string, we can use either ccl:%get-cstring if we know it is a normal C string (nul terminated) or, if we know the length, we can use ccl:%str-from-ptr (documented <a href="http://ccl.clozure.com/manual/chapter12.3.html">here</a></p>
<p><code></p>
<pre>

CL-USER&gt; (setf length (ccl:make-record #&gt;size_t))
#&lt;A Foreign Pointer (:* (:UNSIGNED 64)) #x1D21080&gt;

(ccl:pref length #&gt;size_t)
0

CL-USER&gt; (setf imagedata (#_MagickGetImageBlob wand length))
#&lt;A Foreign Pointer #x7FCE070F1010 &gt;

CL-USER&gt; (ccl:pref length #&gt;size_t)
477

CL-USER&gt; (setf imagestr (ccl:%str-from-ptr imagedata (ccl:pref length #&gt;size_t)))
"\211PNG^M
. . . bunch of stuff that I can't paste here"

CL-USER&gt; (ccl:free length)
NIL

CL-USER&gt; (#_MagickRelinquishMemory imagedata)
#&lt;A Null Foreign Pointer&gt;

CL-USER&gt; (#_DestroyMagickWand wand)
#&lt;A Null Foreign Pointer&amp;gt
</pre>
<p></code></p>
<p>So, now we have gotten our string, we can push that out using hunchetoot (or whatever, just make sure you set the content-type to &#8220;image/png&#8221;), and we have cleaned up after ourselves.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lispwannabe.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lispwannabe.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lispwannabe.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lispwannabe.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lispwannabe.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lispwannabe.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lispwannabe.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lispwannabe.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lispwannabe.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lispwannabe.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lispwannabe.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lispwannabe.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lispwannabe.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lispwannabe.wordpress.com/62/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=62&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lispwannabe.wordpress.com/2010/01/31/allocating-memory-using-clozure-ffi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd8ec3b6ac5c6798688ff487e9b72014?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lispwannabe</media:title>
		</media:content>
	</item>
		<item>
		<title>Clozure FFI mini-tutorial continued</title>
		<link>http://lispwannabe.wordpress.com/2010/01/26/clozure-ffi-mini-tutorial-continued/</link>
		<comments>http://lispwannabe.wordpress.com/2010/01/26/clozure-ffi-mini-tutorial-continued/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 12:31:40 +0000</pubDate>
		<dc:creator>lispwannabe</dc:creator>
				<category><![CDATA[lisp]]></category>
		<category><![CDATA[clozure]]></category>
		<category><![CDATA[ffi]]></category>
		<category><![CDATA[imagemagick]]></category>

		<guid isPermaLink="false">http://lispwannabe.wordpress.com/?p=47</guid>
		<description><![CDATA[Now that we have the ImageMagick bindings set up, we will try to do something &#8216;useful&#8217; with what we have done. I wanted to do something similar to what we find here that matches the C source code that we find here so, we are combining the images: to end up with an image that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=47&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Now that we have the ImageMagick bindings set up, we will try to do something &#8216;useful&#8217; with what we have done.</p>
<p>I wanted to do something similar to what we find <a href="http://www.imagemagick.org/Usage/compose/#mask">here</a> that matches the C source code that we find <a href="http://members.shaw.ca/el.supremo/MagickWand/clipmask.htm">here</a></p>
<p>so, we are combining the images:</p>
<table>
<tr>
<td><img src="http://lispwannabe.files.wordpress.com/2010/01/tile_water.jpg?w=510" alt="Src" /></td>
<td><img src="http://lispwannabe.files.wordpress.com/2010/01/tile_aqua.jpg?w=510" alt="Dest" /></td>
<td><img src="http://lispwannabe.files.wordpress.com/2010/01/moon_mask.gif?w=510" alt="Mask" /></td>
</tr>
</table>
<p>to end up with an image that looks like this:</p>
<p><img src="http://lispwannabe.files.wordpress.com/2010/01/clip_out.jpg?w=510" alt="Finished Image" /></p>
<p>Here is the lisp source:<br />
<code>
<pre>; load imagemagick bindings
(use-interface-dir :imagemagick)

; load the shared library
(open-shared-library "libMagickWand.so")

; use with-cstrs to convert lisp strings to c style strings that
; we can pass to functions
(with-cstrs ((water "/home/kelly/blog/tile_water.jpg")
	     (aqua "/home/kelly/blog/tile_aqua.jpg")
	     (moon "/home/kelly/blog/moon_mask.gif")
	     (output "/home/kelly/blog/clip_out.jpg"))
  ; use #_ as a macro to reference functions
  (setf dest (#_NewMagickWand))
  (setf mask (#_NewMagickWand))
  (setf src (#_NewMagickWand))

  (#_MagickReadImage dest aqua)
  (#_MagickReadImage mask moon)
  ; use #$ as a macro to reference constants
  (#_MagickNegateImage mask #$MagickFalse)

  (#_MagickReadImage src water)
  ; use #&gt; as a macro to reference structures
  ; and pref to dreference pointers
  (setf (ccl:pref dest #&gt;MagickWand.images.mask) (ccl:pref mask #&gt;MagickWand.images))

  (#_MagickCompositeImage dest src #$OverCompositeOp 0 0)
  ; null pointer with the %null-ptr macro
  (setf (ccl:pref dest #&gt;MagickWand.images.mask) (ccl:%null-ptr))

  (#_MagickWriteImage dest output)

  (#_DestroyMagickWand src)
  (#_DestroyMagickWand dest)
  (#_DestroyMagickWand mask))
</pre>
<p></code><br />
As you can tell, we pretty much followed the C source code exactly, using the macros that Clozure provides (<a href="http://ccl.clozure.com/ccl-documentation.html#id445662">documentation</a>)<br />
If we wanted to do other things, we would use the ImageMagick API documentation <a href="http://www.imagemagick.org/api/magick-image.php"> here</a></p>
<p>The next post will show how to allocate memory and interface with a function that has a little more complicated call where we pass in a pointer of a data structure that we created in lisp and get back a pointer to memory.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lispwannabe.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lispwannabe.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lispwannabe.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lispwannabe.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lispwannabe.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lispwannabe.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lispwannabe.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lispwannabe.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lispwannabe.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lispwannabe.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lispwannabe.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lispwannabe.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lispwannabe.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lispwannabe.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=47&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lispwannabe.wordpress.com/2010/01/26/clozure-ffi-mini-tutorial-continued/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd8ec3b6ac5c6798688ff487e9b72014?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lispwannabe</media:title>
		</media:content>

		<media:content url="http://lispwannabe.files.wordpress.com/2010/01/tile_water.jpg" medium="image">
			<media:title type="html">Src</media:title>
		</media:content>

		<media:content url="http://lispwannabe.files.wordpress.com/2010/01/tile_aqua.jpg" medium="image">
			<media:title type="html">Dest</media:title>
		</media:content>

		<media:content url="http://lispwannabe.files.wordpress.com/2010/01/moon_mask.gif" medium="image">
			<media:title type="html">Mask</media:title>
		</media:content>

		<media:content url="http://lispwannabe.files.wordpress.com/2010/01/clip_out.jpg" medium="image">
			<media:title type="html">Finished Image</media:title>
		</media:content>
	</item>
		<item>
		<title>Clozure Common Lisp FFI mini-tutorial</title>
		<link>http://lispwannabe.wordpress.com/2010/01/25/clozure-common-lisp-ffi-mini-tutorial/</link>
		<comments>http://lispwannabe.wordpress.com/2010/01/25/clozure-common-lisp-ffi-mini-tutorial/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 01:51:23 +0000</pubDate>
		<dc:creator>lispwannabe</dc:creator>
				<category><![CDATA[lisp]]></category>
		<category><![CDATA[clozure]]></category>
		<category><![CDATA[ffi]]></category>
		<category><![CDATA[imagemagick]]></category>

		<guid isPermaLink="false">http://lispwannabe.wordpress.com/?p=44</guid>
		<description><![CDATA[Clozure uses something called <a href="http://ccl.clozure.com/ccl-documentation.html#Using-Interface-Directories">interface directories</a> and comes with a few of these installed.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=44&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was working on creating on-the-fly images for a web application that I&#8217;m working on and off lately. I had made a method that called imagemagick using (run-program). This worked fine when I was running with one thread, but when I was using hunchentoot to serve it, threads were hanging up and acting flaky.</p>
<p>I went back to the drawing board and tried my hand at using FFI with Clozure. I was pleasantly suprised by what I found. </p>
<p>Clozure uses something called <a href="http://ccl.clozure.com/ccl-documentation.html#Using-Interface-Directories">interface directories</a> and comes with a few of these installed. You have to have the directories set up before you wan work with the FFI interface and that is what I&#8217;m going to cover in this post.</p>
<p>The first thing to know is that you need to have the ffigen4 tool installed. It wasn&#8217;t so easy to find the <a href="http://trac.clozure.com/ccl/wiki/BuildFFIGEN">directions</a> on installing this, but once you find them, it wasn&#8217;t too hard to get installed.  </p>
<p>This installs a shell command h-to-ffi.sh that is used in the next step.</p>
<p>In order to use these you need to go to the ccl install directory (I just have it in my home directory) and go to the headers file that describes what version of CCL you are using. I&#8217;m using 64 bit CCL on linux so for me it would be ~/ccl/x86-headers64</p>
<p>you will see a few directories already installed there. Since I&#8217;m wanting to work with ImageMagick, I created an imagemagick directory and a C subdirectory per the instructions. The imagemagick directory should be all lowercase as CCL will later map a keyword to all lowercase to find the directory.</p>
<p>in the C directory, I created a new shell file populate.sh you must use this name exactly.</p>
<p>I put the following in the shell file:</p>
<p><code>#!/bin/sh<br />
rm -rf ./home<br />
h-to-ffi.sh  -I/home/admin/ImageMagick-6.5.8-10  /home/admin/ImageMagick-6.5.8-10/magick/MagickCore.h<br />
h-to-ffi.sh  -I/home/admin/ImageMagick-6.5.8-10  /home/admin/ImageMagick-6.5.8-10/wand/MagickWand.h<br />
h-to-ffi.sh  -I/home/admin/ImageMagick-6.5.8-10  /home/admin/ImageMagick-6.5.8-10/wand/magick-wand-private.h<br />
</code><br />
In most cases you can grab your header files out of your normal include directory (i.e. /usr/include) but because ImageMagick doesn&#8217;t install magick-wand-private.h, I needed to use the source directory for everything.</p>
<p>This is specific to ImageMagick, but I had to edit the magick-wand-private.h to include the line:</p>
<p><code>#include </code></p>
<p>at the top so that it could find all of the correct symbols.</p>
<p>once this is done, we can start up ccl and do the following (documented<a href="http://ccl.clozure.com/manual/chapter12.7.html"> here</a>):</p>
<p><code><br />
?(require "PARSE-FFI")<br />
PARSE-FFI</p>
<p>? (ccl::parse-standard-ffi-files :imagemagick)<br />
</code></p>
<p>note the double colons in the last statement, its not an exported function.</p>
<p>Assuming all went well you can now do the following</p>
<p><code><br />
(use-interface-dir :imagemagick)<br />
(open-shared-library "libMagickWand.so")<br />
(setf wand (#_NewMagickWand))<br />
</code></p>
<p>and that will have to do until the next post.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lispwannabe.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lispwannabe.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lispwannabe.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lispwannabe.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lispwannabe.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lispwannabe.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lispwannabe.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lispwannabe.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lispwannabe.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lispwannabe.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lispwannabe.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lispwannabe.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lispwannabe.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lispwannabe.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=44&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lispwannabe.wordpress.com/2010/01/25/clozure-common-lisp-ffi-mini-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd8ec3b6ac5c6798688ff487e9b72014?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lispwannabe</media:title>
		</media:content>
	</item>
		<item>
		<title>CLSQL sqlite on ubuntu</title>
		<link>http://lispwannabe.wordpress.com/2010/01/16/clsql-sqlite-on-ubuntu/</link>
		<comments>http://lispwannabe.wordpress.com/2010/01/16/clsql-sqlite-on-ubuntu/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 15:48:33 +0000</pubDate>
		<dc:creator>lispwannabe</dc:creator>
				<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://lispwannabe.wordpress.com/?p=39</guid>
		<description><![CDATA[I was having problems getting clsql working with sqlite3 on ubuntu. no matter how I adjusted the paths, it would not load the library with uffi. After messing around with it for most of the morning, I finally discovered that there was something funky with the symbolic links in the /usr/lib/ area. lrwxrwxrwx 1 root [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=39&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was having problems getting clsql working with sqlite3 on ubuntu.</p>
<p>no matter how I adjusted the paths, it would not load the library with uffi.</p>
<p>After messing around with it for most of the morning, I finally discovered that there was something funky with the symbolic links in the /usr/lib/ area.</p>
<blockquote>
<div id="_mcePaste">lrwxrwxrwx 1 root root     15 2009-12-30 08:09 libsqlite3.so -&gt; libqslite3.so.0</div>
<div id="_mcePaste">lrwxrwxrwx 1 root root     19 2009-11-02 23:03 libsqlite3.so.0 -&gt; libsqlite3.so.0.8.6</div>
<div id="_mcePaste">-rw-r&#8211;r&#8211; 1 root root 556648 2009-09-19 16:35 libsqlite3.so.0.8.6</div>
</blockquote>
<p>when I tried to ldd /usr/lib/libsqlite3.so it said that there was no file /usr/lib/libsqlite3.so</p>
<p>Redoing the link like so:</p>
<p>sudo ln -sf libsqlite3.so.0.8.6 libsqlite3.so</p>
<p>fixed the problem and allowed me to (require &#8216;clsql-sqlite3) with no problems</p>
<p>HTH</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lispwannabe.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lispwannabe.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lispwannabe.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lispwannabe.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lispwannabe.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lispwannabe.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lispwannabe.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lispwannabe.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lispwannabe.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lispwannabe.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lispwannabe.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lispwannabe.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lispwannabe.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lispwannabe.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=39&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lispwannabe.wordpress.com/2010/01/16/clsql-sqlite-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd8ec3b6ac5c6798688ff487e9b72014?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lispwannabe</media:title>
		</media:content>
	</item>
		<item>
		<title>closures in clojure</title>
		<link>http://lispwannabe.wordpress.com/2008/10/24/closures-in-clojure/</link>
		<comments>http://lispwannabe.wordpress.com/2008/10/24/closures-in-clojure/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 14:43:53 +0000</pubDate>
		<dc:creator>lispwannabe</dc:creator>
				<category><![CDATA[clojure]]></category>
		<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://lispwannabe.wordpress.com/?p=36</guid>
		<description><![CDATA[A friend of mine said that he read somewhere that you couldn&#8217;t do a closure in clojure. I thought that was probably incorrect &#8211; but I haven&#8217;t really done much in clojure. He couldn&#8217;t find the link so I thought I&#8217;d put it to the test: (defn plusn [x] (fn [y] (+ x y))) (def [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=36&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A friend of mine said that he read somewhere that you couldn&#8217;t do a closure in clojure. I thought that was probably incorrect &#8211; but I haven&#8217;t really done much in clojure. He couldn&#8217;t find the link so I thought I&#8217;d put it to the test:</p>
<p>(defn plusn [x]<br />
(fn [y] (+ x y)))</p>
<p>(def plus5 (plusn 5))<br />
(plus5 3)</p>
<p>&gt;&gt; 8</p>
<p>Yep, it&#8217;s got closures</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lispwannabe.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lispwannabe.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lispwannabe.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lispwannabe.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lispwannabe.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lispwannabe.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lispwannabe.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lispwannabe.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lispwannabe.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lispwannabe.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lispwannabe.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lispwannabe.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lispwannabe.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lispwannabe.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=36&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lispwannabe.wordpress.com/2008/10/24/closures-in-clojure/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd8ec3b6ac5c6798688ff487e9b72014?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lispwannabe</media:title>
		</media:content>
	</item>
		<item>
		<title>Common Lisp Lexer</title>
		<link>http://lispwannabe.wordpress.com/2008/05/18/common-lisp-lexer/</link>
		<comments>http://lispwannabe.wordpress.com/2008/05/18/common-lisp-lexer/#comments</comments>
		<pubDate>Sun, 18 May 2008 20:53:16 +0000</pubDate>
		<dc:creator>lispwannabe</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lispwannabe.wordpress.com/?p=18</guid>
		<description><![CDATA[I&#8217;ve been interested in compilers lately, leading me to purchase the last book I blogged about and a $6 copy of the 1st ed. Dragon book, and I have a copy of the ANTLR reference book coming. Of course, knowing that Lisp is well suited to working with compilers, I wanted to play with some [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=18&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been interested in compilers lately, leading me to purchase the<br />
last book I blogged about and a $6 copy of the 1st ed. Dragon book, and I<br />
have a copy of the ANTLR reference book coming.</p>
<p>Of course, knowing that Lisp is well suited to working with compilers,<br />
I wanted to play with some of this stuff in lisp. </p>
<p>I loaded cl-yacc and messed with their list lexer that they had in the<br />
examples. This led me to wanting to get a more complex lexer that<br />
would work well with a file or string.</p>
<p>Of course I could just use the lisp read which is in essence a lexer,<br />
it doesn&#8217;t handle things like &#8220;parse this line;&#8221; where you want the<br />
semicolon to be a token in it&#8217;s own right. Lisp read will happily pull<br />
in the last symbol &#8216;line;&#8217;.</p>
<p>So . .  I used ASDF to load up regex and clawk from cliki, and<br />
 downloaded lexer from wherever Google led me. This is where my<br />
 problems began &#8211; and I&#8217;m hoping that I can avoid you some pain.</p>
<p>The lexer that I downloaded referenced a function<br />
macroexpand-regex-expr which was not available, and when I tried to<br />
figure out what it might be referencing, I still had problems. Perhaps<br />
I would have gotten to the end of it, but then again, maybe not.</p>
<p>The right thing to do (in this case) was to use the lispbuilder code<br />
that is at <a href="http://lispbuilder.sourceforge.net/"> sourceforge</a>. Because<br />
they weren&#8217;t immediately installable with asdf-install I had to<br />
extract them and re tgz them. I added these to cliki so<br />
that we can just asdf-install them. Just for grins, here is some of<br />
the code that I&#8217;m playing with.</p>
<pre> <code>

(defparameter test-lexer)

(lispbuilder-lexer:deflexer test-lexer
    ("[0-9]+([.][0-9]+([Ee][0-9]+)?)"
      (return (values 'flt (read-from-string lispbuilder-lexer:%0))))
    ("[0-9]+"
      (return (values 'int (parse-integer lispbuilder-lexer:%0))))
    ("[:alpha:][:alnum:]*"
      (return (values 'id (read-from-string lispbuilder-lexer:%0))))
    ("(-|[+*/])"
      (return (values (read-from-string lispbuilder-lexer:%0) (read-from-string lispbuilder-lexer:%0))))
    ("[(]"
      (return (values '|(| '|(|)))
    ("[)]"
      (return (values '|)| '|)|)))
    ("[:space:]+") )

(defvar *expression-parser*)

(yacc:define-parser *expression-parser*
  (:start-symbol expression)
  (:terminals (int id + - * / |(| |)|))
  (:precedence ((:left * /) (:left + -)))

  (expression
   (expression + expression #'i2p)
   (expression - expression #'i2p)
   (expression * expression #'i2p)
   (expression / expression #'i2p)
   term)

  (term
   id
   int
   (- term)
   (|(| expression |)| #'k-2-3)))

(setq *test* (yacc:parse-with-lexer (test-lexer "x * - (2 + 3) * y") *expression-parser*))

(print *test*)

 (* (* X (- (+ 2 3))) Y)

</code></pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/lispwannabe.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/lispwannabe.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lispwannabe.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lispwannabe.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lispwannabe.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lispwannabe.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lispwannabe.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lispwannabe.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lispwannabe.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lispwannabe.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lispwannabe.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lispwannabe.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lispwannabe.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lispwannabe.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lispwannabe.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lispwannabe.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=18&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lispwannabe.wordpress.com/2008/05/18/common-lisp-lexer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd8ec3b6ac5c6798688ff487e9b72014?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lispwannabe</media:title>
		</media:content>
	</item>
		<item>
		<title>Review of Constructing Language Processors for Little Languages</title>
		<link>http://lispwannabe.wordpress.com/2008/05/05/review-of-constructing-language-processors-for-little-languages/</link>
		<comments>http://lispwannabe.wordpress.com/2008/05/05/review-of-constructing-language-processors-for-little-languages/#comments</comments>
		<pubDate>Mon, 05 May 2008 02:18:54 +0000</pubDate>
		<dc:creator>lispwannabe</dc:creator>
				<category><![CDATA[books]]></category>

		<guid isPermaLink="false">http://lispwannabe.wordpress.com/?p=17</guid>
		<description><![CDATA[Randy Kaplan ISBN 0-471-59753-8 This book is an introduction to interpreters and compilers. It is intended to be down a level from the dragon book. I found the book accessible, an easy read for the most part. (I read the book mostly over the weekend, but I did do some skimming) If anything, it connected [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=17&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Randy Kaplan ISBN 0-471-59753-8</p>
<p>This book is an introduction to interpreters and compilers. It is intended to<br />
be down a level from the dragon book.  I found the book accessible, an<br />
easy read for the most part. (I read the book mostly over the weekend,<br />
but I did do some skimming) If anything, it connected the<br />
dots just a little too much, but the book stays true to it&#8217;s purpose.</p>
<p>Kaplan starts with a survey of little languages, and discusses design<br />
of languages. That discussion was one of the reasons why I bought the<br />
book and I was a bit disappointed with that aspect because it<br />
covered just a few pages (37-39). Other parts of the tour were quite<br />
adequate and you come away with a firm grasp of what a lexer and a<br />
parser do as well as a basic understanding of lex &amp; yacc and how all<br />
of this stuff is brought together to make an interpreter or a<br />
compiler. I particularly enjoyed the section on computation engines &amp;<br />
finite state automata (82 ff)</p>
<p>The author is careful to point out that the standard book on the topic<br />
is the dragon book, and points you to it in several instances.</p>
<p>Most of the book revolves around a language that the author made up<br />
for a specific purpose and takes if cradle to grave. He develops a<br />
grammar, lexer, parser (both from scratch and using lex &amp; yacc) and<br />
shows in very fine detail (too much at times) how each fits into the<br />
overall picture. All source code is given in c, often with a walk<br />
through of each procedure and data structure.</p>
<p>How does this relate to lisp? Well he does have an interesting chapter<br />
in the back showing how do manage the same task (i.e. a little<br />
language) in both prolog and lisp. He doesn&#8217;t start with the same<br />
input as he uses for his grammar and example in the rest of the book<br />
but shows how to modify the grammar slightly to allow you to write<br />
your little language. I would certainly like to revisit both of those<br />
sections, but they are just a tiny part of the book. I was hoping to<br />
find some references to fuller works on the topic with these languages<br />
in mind. (for lisp he pointed to CLTL2 and SICP)</p>
<p>Also, it has been a very long time since I have programmed in c. It<br />
was striking how verbose the source code really was for the<br />
project. After he presents the prolog code for one of the statements<br />
he comments: &#8220;This may seem like a lot of code, but it translates and<br />
executes &#8230;&#8221;.</p>
<p>In the last chapter, it seems that he is making the case for a richer<br />
environment for making little languages and that prolog, lisp and<br />
forth were all better platforms for creating them, even<br />
with the helper programs lex and yacc. However, as I read along and<br />
noticed several places where things would have been much easier in<br />
lisp it may have been mere projection on my part.</p>
<p>I am glad that I read the book, but I think that I probably should<br />
have saved my book buying $$ for the dragon book and tried to borrow<br />
this one. On the other hand, I actually got through this book and I<br />
found it useful for thinking about the upcoming design of a little<br />
language, and I don&#8217;t know if either could be said about the dragon<br />
book.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/lispwannabe.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/lispwannabe.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lispwannabe.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lispwannabe.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lispwannabe.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lispwannabe.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lispwannabe.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lispwannabe.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lispwannabe.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lispwannabe.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lispwannabe.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lispwannabe.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lispwannabe.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lispwannabe.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lispwannabe.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lispwannabe.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=17&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lispwannabe.wordpress.com/2008/05/05/review-of-constructing-language-processors-for-little-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd8ec3b6ac5c6798688ff487e9b72014?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lispwannabe</media:title>
		</media:content>
	</item>
		<item>
		<title>(cond (n00b flame) (t work))</title>
		<link>http://lispwannabe.wordpress.com/2008/04/30/cond-n00b-flame-t-work/</link>
		<comments>http://lispwannabe.wordpress.com/2008/04/30/cond-n00b-flame-t-work/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 00:49:07 +0000</pubDate>
		<dc:creator>lispwannabe</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[macro]]></category>

		<guid isPermaLink="false">http://lispwannabe.wordpress.com/?p=16</guid>
		<description><![CDATA[I was messing around with a cond statement and ended up with a bunch of ugly looking statements. One of the problems with lisp, is that it gives you the sense that you can do anything anywhere. You pretty much can, but not without some problems every now and then. I thought I would solve [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=16&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was messing around with a cond statement and ended up with a bunch<br />
of ugly looking statements. One of the problems with lisp, is that it<br />
gives you the sense that you can do anything anywhere. You pretty much<br />
can, but not without some problems every now and then.</p>
<p>I thought I would solve the problem by making a macro so it would look<br />
something like: </p>
<pre><code>
(cond (macro parm1 parm2 parm3)
      (macro parm1 parm2 parm3))
</code></pre>
<p>Any lisp veteran is probably chuckling to themselves thinking that I<br />
probably have also tried to do the functional equivalent of something like:  </p>
<pre><code>
(setq x '(pred sexpr))

(cond x)
</code></pre>
<p>As I learned quite quickly, you just can&#8217;t do this because of the<br />
macro expansion of cond.</p>
<pre><code>
&gt;(print (macroexpand-1 '(cond (macro param1 param2)
		      (macro param1 param2))))

(IF MACRO (PROGN PARAM1 PARAM2) (COND (MACRO PARAM1 PARAM2)))
</code></pre>
<p>The problem in both of these scenarios is that the cond macro gets<br />
expanded before any of the other macros, essentially goofing up our<br />
original plan.</p>
<p>To solve the problem I just changed it around so I had a macro that<br />
took the list of parameters that I wanted and created the entire cond<br />
statement for me.</p>
<pre><code>

(cond-macro (param1 param2)
	    (param1 param2))

</code></pre>
<p>Which did exactly what I wanted.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/lispwannabe.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/lispwannabe.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lispwannabe.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lispwannabe.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lispwannabe.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lispwannabe.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lispwannabe.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lispwannabe.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lispwannabe.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lispwannabe.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lispwannabe.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lispwannabe.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lispwannabe.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lispwannabe.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lispwannabe.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lispwannabe.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lispwannabe.wordpress.com&amp;blog=3162286&amp;post=16&amp;subd=lispwannabe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lispwannabe.wordpress.com/2008/04/30/cond-n00b-flame-t-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd8ec3b6ac5c6798688ff487e9b72014?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lispwannabe</media:title>
		</media:content>
	</item>
	</channel>
</rss>
