<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Artful Code &#187; foop</title>
	<atom:link href="http://www.artfulcode.net/tags/foop/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artfulcode.net</link>
	<description>Resources and tips for dynamic, interactive languages.</description>
	<lastBuildDate>Fri, 09 Sep 2011 02:15:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A better MySQL module for newLISP</title>
		<link>http://www.artfulcode.net/articles/a-better-mysql-module-for-newlisp/</link>
		<comments>http://www.artfulcode.net/articles/a-better-mysql-module-for-newlisp/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 17:23:32 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[foop]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[newlisp]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.artfulcode.net/?p=491</guid>
		<description><![CDATA[The Mysql module has been written from scratch utilizing some of the more recent features of newLisp, such as FOOP and reference returns. One of its major design goals was to simplify use as well as broaden the features of the standard MySQL module, while at the same time allowing the creation of new, anonymous [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong><code>Mysql</code></strong> module has been written from scratch utilizing some of the more recent features of newLisp, such as FOOP and reference returns. One of its major design goals was to simplify use as well as broaden the features of the standard <a href="http://www.newlisp.org/code/modules/mysql.lsp.html">MySQL module</a>, while at the same time allowing the creation of new, anonymous instances at run-time.<span id="more-491"></span></p>
<p>The <code>Mysql</code> module differs from the distribution standard module in several important ways. Most obviously, it uses <a href="http://www.artfulcode.net/articles/using-the-newlisp-ffi/">FOOP wrappers for MySQL types</a>. It also requires clients to free results instances; in the standard module, only the base MYSQL instance itself must be freed (using <code>MySQL:close-db</code>).</p>
<p>The significance of this is that it is much simpler to create multiple connections (without having to duplicate the entire context at compile time). Result sets are completely independent of each other, and several may be maintained in any state at once. This also means that a spawned process may be given its own Mysql instance to use without having to worry about other processes&#8217; instances interfering. Using the standard module, the entire context would need to be cloned at compile time and given a static symbol reference (e.g., <code>(new 'MySQL 'db)</code>) in order to run multiple instances or connections to a server.</p>
<p>Moreover, because this module uses <code>unpack</code> and MySQL C API accessor functions, there is no need for the client to calculate member offsets in MySQL compound types. So long as newLisp was compiled for the same target as the <code>libmysqlclient</code> library (both are 32 bit or both are 64 bit), everything should work out of the box. Additionally, MySQL errors are now checked in the connect and query functions and re-thrown as interpreter errors. Instead of checking for <code>nil</code> returns and a using MySQL:error to get the error message, standard error  handling with the <code>catch</code> function may be used.</p>
<p>Several convenience functions and macros have been defined in the <code>mysql</code> context for common operations, including connecting to the database and iterating over results without having to worry about catching errors and managing memory. SQL statements may be passed as strings or a list containing a format string and its parameters, which will type-checked and automatically be escaped as needed.</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>mysql<span style="color: #66cc66;">:</span><span style="color: #555;">on-connect</span> '<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;localhost&quot;</span> <span style="color: #ff0000;">&quot;user&quot;</span> <span style="color: #ff0000;">&quot;secret&quot;</span> <span style="color: #ff0000;">&quot;my_database&quot;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>db err<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> err
      <span style="color: #66cc66;">&#40;</span>println <span style="color: #ff0000;">&quot;Error! &quot;</span> err<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>mysql<span style="color: #66cc66;">:</span><span style="color: #555;">row-iter</span> db <span style="color: #ff0000;">&quot;SELECT * FROM some_table&quot;</span> true
        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>row<span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span>println row<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>This module has been tested with MySQL version 5 and 5.1 and newLisp version 10.0.1. It requires newLisp 10.0 or later. You can <a href="http://static.artfulcode.net/newlisp/mysql.lsp.html">download it</a> from the <a href="http://static.artfulcode.net/newlisp/">Artful Code newLisp module repository</a>.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Submit article</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fa-better-mysql-module-for-newlisp%2F&amp;title=A+better+MySQL+module+for+newLISP" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fa-better-mysql-module-for-newlisp%2F&amp;title=A+better+MySQL+module+for+newLISP" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=A+better+MySQL+module+for+newLISP&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fa-better-mysql-module-for-newlisp%2F&amp;title=A+better+MySQL+module+for+newLISP" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fa-better-mysql-module-for-newlisp%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fa-better-mysql-module-for-newlisp%2F&amp;title=A+better+MySQL+module+for+newLISP" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fa-better-mysql-module-for-newlisp%2F&amp;title=A+better+MySQL+module+for+newLISP" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fa-better-mysql-module-for-newlisp%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+A+better+MySQL+module+for+newLISP+@+http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fa-better-mysql-module-for-newlisp%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.artfulcode.net/articles/a-better-mysql-module-for-newlisp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL library for newLISP</title>
		<link>http://www.artfulcode.net/articles/sql-library-newlisp/</link>
		<comments>http://www.artfulcode.net/articles/sql-library-newlisp/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 21:24:35 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[foop]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[newlisp]]></category>
		<category><![CDATA[releases]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.artfulcode.net/articles/sql-library-newlisp/</guid>
		<description><![CDATA[The newLISP SQL library is a set of classes and functions to ease generation of SQL code in newLISP. The module is not yet feature-complete but is in a usable state. Much of the module uses the small convenience classes to &#8220;serialize&#8221; SQL expressions. Most of the module&#8217;s classes have :serialize methods that render the [...]]]></description>
			<content:encoded><![CDATA[<p>The newLISP SQL library is a set of classes and functions to ease generation of SQL code in newLISP.  The module is not yet feature-complete but is in a usable state.<span id="more-20"></span></p>
<p>Much of the module uses the small convenience classes to &#8220;serialize&#8221; SQL expressions.  Most of the module&#8217;s classes have <code>:serialize</code> methods that render the encapsulated data as a string.  For example, the <code>Field</code> class:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>f <span style="color: #66cc66;">&#40;</span>Field <span style="color: #ff0000;">&quot;table&quot;</span> <span style="color: #ff0000;">&quot;fieldname&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">serialize</span> f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">=&amp;</span>gt<span style="color: #808080; font-style: italic;">; &quot;table.fieldname&quot;</span></pre></div></div>

<p>&#8230;or the <code>Condition</code> class:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>c <span style="color: #66cc66;">&#40;</span>Condition <span style="color: #ff0000;">&quot;&amp;gt;&quot;</span> <span style="color: #ff0000;">&quot;salary&quot;</span> <span style="color: #cc66cc;">65000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">serialize</span> c<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">=&amp;</span>gt<span style="color: #808080; font-style: italic;">; &quot;salary &amp;gt; '65000'&quot;</span></pre></div></div>

<p>Note that values are enclosed in single quotes for ANSI compliance.  The most interesting function in the module, however, is <code>sql:expr</code>, which uses the <code>match</code>-based primitives in the <span style="text-decoration: line-through;">functional</span> module to generate various types of expressions:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>sql<span style="color: #66cc66;">:</span><span style="color: #555;">expr</span> <span style="color: #ff0000;">&quot;employees&quot;</span> <span style="color: #ff0000;">&quot;first_name&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">=&amp;</span>gt<span style="color: #808080; font-style: italic;">; &quot;employees.first_name&quot;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>sql<span style="color: #66cc66;">:</span><span style="color: #555;">expr</span> <span style="color: #ff0000;">&quot;LIKE&quot;</span> <span style="color: #ff0000;">&quot;first_name&quot;</span> <span style="color: #ff0000;">&quot;Stev%&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">=&amp;</span>gt<span style="color: #808080; font-style: italic;">; &quot;first_name LIKE 'Stev%'&quot;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>sql<span style="color: #66cc66;">:</span><span style="color: #555;">expr</span> <span style="color: #ff0000;">&quot;OR&quot;</span> <span style="color: #66cc66;">&#40;</span>sql<span style="color: #66cc66;">:</span><span style="color: #555;">expr</span> <span style="color: #ff0000;">&quot;LIKE&quot;</span> <span style="color: #ff0000;">&quot;first_name&quot;</span> <span style="color: #ff0000;">&quot;Stev%&quot;</span><span style="color: #66cc66;">&#41;</span>
               <span style="color: #66cc66;">&#40;</span>sql<span style="color: #66cc66;">:</span><span style="color: #555;">expr</span> <span style="color: #ff0000;">&quot;LIKE&quot;</span> <span style="color: #ff0000;">&quot;last_name&quot;</span> <span style="color: #ff0000;">&quot;John%&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">=&amp;</span>gt<span style="color: #808080; font-style: italic;">; &quot;((first_name LIKE 'Stev%') OR (last_name LIKE 'John%'))&quot;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>sql<span style="color: #66cc66;">:</span><span style="color: #555;">expr</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">=&amp;</span>gt<span style="color: #808080; font-style: italic;">;&quot;6&quot;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>sql<span style="color: #66cc66;">:</span><span style="color: #555;">expr</span> 'myapp<span style="color: #66cc66;">:</span><span style="color: #555;">employees</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">=&amp;</span>gt<span style="color: #808080; font-style: italic;">; &quot;employees&quot;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>sql<span style="color: #66cc66;">:</span><span style="color: #555;">expr</span> <span style="color: #ff0000;">&quot;CONV&quot;</span> <span style="color: #ff0000;">&quot;AF&quot;</span> <span style="color: #cc66cc;">16</span> <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">=&amp;</span>gt<span style="color: #808080; font-style: italic;">; &quot;CONV('AF',16,10)&quot;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>sql<span style="color: #66cc66;">:</span><span style="color: #555;">expr</span> <span style="color: #ff0000;">&quot;LIKE&quot;</span> <span style="color: #66cc66;">&#40;</span>sql<span style="color: #66cc66;">:</span><span style="color: #555;">expr</span> <span style="color: #ff0000;">&quot;employees&quot;</span> <span style="color: #ff0000;">&quot;first_name&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #ff0000;">&quot;Stev%&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">=&amp;</span>gt<span style="color: #808080; font-style: italic;">; &quot;employees.first_name LIKE 'Stev%'&quot;</span></pre></div></div>

<p>Additional functions directly express <code>select</code>, <code>update</code>, <code>insert</code>, and <code>delete</code> statements or handle data type conversions (such as parsing SQL datetimes).</p>
<h4>Functional</h4>
<p>Another addition to Artful Code&#8217;s module list is the <span style="text-decoration: line-through;">functional</span> module.  This library provides some basic conditionals that make use of <code>match</code> to process data.  These macros express program logic by associating blocks of code with the structure of data.</p>
<p>Here is an example using <code>match-case</code>. <code>match-case</code> accepts a single expression and a series of forms that describe what to do based on its structure.  Each case form consists of a <a href="http://www.newlisp.org/downloads/newlisp_manual.html#match">match expression</a>, a list of variables to be locally bound to the result of the match, and an individual form to evaluate in a local scope with the matched variables bound:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>x '<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #cc66cc;">3</span> <span style="color: #cc66cc;">4</span> <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>match-<span style="color: #b1b100;">case</span> x
        <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>? ? ?<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>a b c<span style="color: #66cc66;">&#41;</span>
         <span style="color: #66cc66;">&#40;</span>println <span style="color: #ff0000;">&quot;a b and c do not get bound here, because they do not match x&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>? ? ? *<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>a b c d<span style="color: #66cc66;">&#41;</span>
         <span style="color: #66cc66;">&#40;</span>println <span style="color: #ff0000;">&quot;a = 1, b = 2, c = 3, and d = '(4 5)&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Here, the second block would match because <code>(? ? ? *)</code> matches against <code>(1 2 3 4 5)</code> and creates the binding association, <code>((a 1) (b 2) (c 3) (d (4 5)))</code>.</p>
<p>Also included in the module is <code>match-cond</code>, which is more powerful than <code>match-case</code>. <code>match-cond</code> works like <code>cond</code>, except that instead of a user-defined conditional, the first form in each case is a list of <code>pattern</code>, <code>symbol-list</code>, and <code>target</code>.  See the <span style="text-decoration: line-through;">documentation</span> for more details.</p>
<p><strong>Edit (2009-02-16): the functional module in mentioned in this post has been replaced with the <a href="http://static.artfulcode.net/newlisp/matching.lsp.html">matching</a> module.</strong></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Submit article</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fsql-library-newlisp%2F&amp;title=SQL+library+for+newLISP" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fsql-library-newlisp%2F&amp;title=SQL+library+for+newLISP" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=SQL+library+for+newLISP&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fsql-library-newlisp%2F&amp;title=SQL+library+for+newLISP" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fsql-library-newlisp%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fsql-library-newlisp%2F&amp;title=SQL+library+for+newLISP" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fsql-library-newlisp%2F&amp;title=SQL+library+for+newLISP" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fsql-library-newlisp%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+SQL+library+for+newLISP+@+http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fsql-library-newlisp%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.artfulcode.net/articles/sql-library-newlisp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is FOOP?</title>
		<link>http://www.artfulcode.net/articles/what-is-foop/</link>
		<comments>http://www.artfulcode.net/articles/what-is-foop/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 21:18:52 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[foop]]></category>
		<category><![CDATA[newlisp]]></category>
		<category><![CDATA[oop]]></category>

		<guid isPermaLink="false">http://www.artfulcode.net/articles/what-is-foop/</guid>
		<description><![CDATA[FOOP is the concept of functional object oriented programming in newLISP. It originated in a thread on the newLISP forum and was officially added to the interpreter for newLISP 9.3. To be fair, the FOOP operator, :, does not provide any truly new functionality to newLISP. However, it does make prototyping much more concise and [...]]]></description>
			<content:encoded><![CDATA[<p>FOOP is the concept of <em>functional object oriented programming</em> in newLISP.  It originated in a thread on the newLISP forum and was officially added to the interpreter for newLISP 9.3.<span id="more-36"></span></p>
<p>To be fair, the FOOP operator, <code>:</code>, does not provide any truly new functionality to newLISP.  However, it does make prototyping much more concise and expressive.</p>
<h4>The basics</h4>
<p>Prototyping is accomplished using a source <code>context</code> (a lexical closure) and the <code>new</code> keyword.  Using the commonly contrived example of the Rectangle object:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>context 'Rectangle<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'x <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'y <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>define <span style="color: #66cc66;">&#40;</span>area<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>* x y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>context MAIN<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>new Rectangle 'my-rectangle<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'my-rectangle<span style="color: #66cc66;">:</span><span style="color: #555;">x</span> <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'my-rectangle<span style="color: #66cc66;">:</span><span style="color: #555;">y</span> <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>FOOP uses the convention of <code>(object member member ...)</code> for storing object instances.  Instance data, apart from the members, is encapsulated within the context, so all of the methods may access contextually set variables.  Although not built into the interpreter, the functional convention,</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>define <span style="color: #66cc66;">&#40;</span>Class<span style="color: #66cc66;">:</span><span style="color: #555;">Class</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span>context<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>&#8230;is typically used to create new contexts for FOOP.  Using <code>Class</code>, the above example would be written as:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>new Class 'Rectangle<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'my-rectangle <span style="color: #66cc66;">&#40;</span>Rectangle <span style="color: #cc66cc;">10</span> <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Methods are attached via the normal syntax for declaring foreign context functions, but with the assumption of the argument being the <code>(object member member ...)</code> convention and implicit indexing:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>define <span style="color: #66cc66;">&#40;</span>Rectangle<span style="color: #66cc66;">:</span><span style="color: #555;">area</span> self<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>* <span style="color: #66cc66;">&#40;</span>self <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>self <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>All of the normal operations that apply to contexts remain applicable for contexts created in this fashion.  One interesting element of FOOP is that the methods and namespace are separate from the object&#8217;s properties.  Therefore, an arbitrary list of values can be consed by a cloned context to create a new instance.</p>
<p>Constructors are easily overridden using <a href="http://www.newlisp.org/downloads/newlisp_manual.html#default_function">default functors</a>.  In fact, <code>Class:Class</code> merely automates the creation of a default functor for a new context.</p>
<p>So, if we wanted a Rectangle with default x and y values:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>define <span style="color: #66cc66;">&#40;</span>Rectangle<span style="color: #66cc66;">:</span><span style="color: #555;">Rectangle</span> <span style="color: #66cc66;">&#40;</span>x <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>y <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>context<span style="color: #66cc66;">&#41;</span> x y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<h4>Solving problems with FOOP</h4>
<p>Although FOOP would not be considered a <em>true</em> object oriented system by <a href="http://paulgraham.com/reesoo.html">purists</a> (who would call it prototyping), it is an excellent substitute for a true type system.  For example, here is a simple interface for probing and validating command-line arguments:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; In case Class is not yet defined, attempt to define</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">catch</span>
  <span style="color: #66cc66;">&#40;</span>define <span style="color: #66cc66;">&#40;</span>Class<span style="color: #66cc66;">:</span><span style="color: #555;">Class</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span>context<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; Declare our classes</span>
<span style="color: #66cc66;">&#40;</span>new Class 'Option<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>new Class 'Switch<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; Option's identifying token</span>
<span style="color: #66cc66;">&#40;</span>new Class 'Required<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; Defines option as required</span>
<span style="color: #66cc66;">&#40;</span>new Class 'Predicate<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; Lambda to validate and option's value</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; Define a method to find this option in (main-args)</span>
<span style="color: #66cc66;">&#40;</span>define <span style="color: #66cc66;">&#40;</span>Option<span style="color: #66cc66;">:</span><span style="color: #b1b100;">get</span> self <span style="color: #66cc66;">,</span> loc val<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'switch <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">last</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">assoc</span> <span style="color: #66cc66;">&#40;</span>self Switch<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'loc <span style="color: #66cc66;">&#40;</span>find switch <span style="color: #66cc66;">&#40;</span>main-args<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> <span style="color: #66cc66;">&#40;</span>starts-with switch <span style="color: #ff0000;">&quot;--&quot;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">catch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">nth</span> <span style="color: #66cc66;">&#40;</span>+ <span style="color: #cc66cc;">1</span> loc<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>main-args<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 'val<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        val<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>starts-with switch <span style="color: #ff0000;">&quot;--&quot;</span><span style="color: #66cc66;">&#41;</span> true<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>starts-with switch <span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #66cc66;">&#41;</span> true<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>true <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; Define a predicate to validate the value of our option.</span>
<span style="color: #808080; font-style: italic;">;; In case the option does not come with a value, we skip the predicate</span>
<span style="color: #808080; font-style: italic;">;; part and validate solely based on the value of Required.</span>
<span style="color: #66cc66;">&#40;</span>define <span style="color: #66cc66;">&#40;</span>Option<span style="color: #66cc66;">:</span><span style="color: #555;">valid</span>? self <span style="color: #66cc66;">,</span> val req pred req? pred?<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'val <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #b1b100;">get</span> self<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'req? <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">assoc</span> <span style="color: #66cc66;">&#40;</span>self Required<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'pred? <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">assoc</span> <span style="color: #66cc66;">&#40;</span>self Predicate<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'req <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> req? <span style="color: #66cc66;">&#40;</span>true? val<span style="color: #66cc66;">&#41;</span> true<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'pred <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> pred? <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">last</span> pred?<span style="color: #66cc66;">&#41;</span> val<span style="color: #66cc66;">&#41;</span> true<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> req pred<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The Option class is made up of several other classes, Switch, Required, and Predicate.  Switch is the token to identify the option in the command-line arguments.  Switches that begin with &#8212; can take an optional value, such as <code>--url http://www.artfulcode.net</code>.  Required is another empty class that only needs to be a boolean value.  Predicate optionally stores a lambda that will be used to validate the value found in <code>(main-args)</code>.</p>
<p>Here is a sample of how we might use <code>Option</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'url <span style="color: #66cc66;">&#40;</span>Option
    <span style="color: #66cc66;">&#40;</span>Switch <span style="color: #ff0000;">&quot;--url&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>Required true<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>Predicate
        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>val<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>true? <span style="color: #66cc66;">&#40;</span>regex <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">^</span>http<span style="color: #66cc66;">:</span>//<span style="color: #66cc66;">.</span>*?$<span style="color: #66cc66;">&#125;</span> val <span style="color: #cc66cc;">17</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>For a single on/off switch, we can do:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'some-option <span style="color: #66cc66;">&#40;</span>Option
    <span style="color: #66cc66;">&#40;</span>Switch <span style="color: #ff0000;">&quot;-s&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>Required <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>To get the values and validate them:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">artful<span style="color: #66cc66;">:</span>~ newlisp test<span style="color: #66cc66;">.</span>lsp --url http<span style="color: #66cc66;">:</span>//www<span style="color: #66cc66;">.</span>artfulcode<span style="color: #66cc66;">.</span>net -s
&nbsp;
<span style="color: #66cc66;">&#40;</span>url<span style="color: #66cc66;">:</span><span style="color: #b1b100;">get</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; =&gt; &quot;http://www.artfulcode.net&quot;</span>
<span style="color: #66cc66;">&#40;</span>some-option<span style="color: #66cc66;">:</span><span style="color: #b1b100;">get</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; =&amp;gt; true</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>url<span style="color: #66cc66;">:</span><span style="color: #555;">valid</span>?<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; =&gt; true</span>
<span style="color: #66cc66;">&#40;</span>some-option<span style="color: #66cc66;">:</span><span style="color: #555;">valid</span>?<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; =&gt; true</span></pre></div></div>

<p>And for non-validating values:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">artful<span style="color: #66cc66;">:</span>~ newlisp test<span style="color: #66cc66;">.</span>lsp --url <span style="color: #ff0000;">&quot;Hello world&quot;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>url<span style="color: #66cc66;">:</span><span style="color: #b1b100;">get</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; =&gt; &quot;Hello world&quot;</span>
<span style="color: #66cc66;">&#40;</span>url<span style="color: #66cc66;">:</span><span style="color: #555;">valid</span>?<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; =&gt; nil</span></pre></div></div>

<p>newLISP 9.3&#8242;s new association list processing functions make accessing member cells a snap &#8211; <code>(assoc (object key))</code>.  Obviously, this is more expressive and concise than a lot of recursive parsing of <code>(main-args)</code>.  The trade-off is the same as with any use of OOP: contexts are more expensive than list processing, especially when creating many small context instances.</p>
<p>This is obviously a contrived example and could be solved more efficiently quite easily, but it does a good job of illustrating FOOP.</p>
<h4>What makes it functional?</h4>
<p>That&#8217;s tough to quantify.  However, if we want to shorten the class declarations in the code above to simplify our code, we could use use the higher order functions <a href="http://www.newlisp.org/downloads/newlisp_manual.html#map">map</a> and <a href="http://www.newlisp.org/downloads/newlisp_manual.html#curry">curry</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>map <span style="color: #66cc66;">&#40;</span>curry new Class<span style="color: #66cc66;">&#41;</span> '<span style="color: #66cc66;">&#40;</span>Option Switch Required Predicate<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Other examples might be to compose custom classes as needed using macros, updating a list of class instances using <code>map</code>, or currying class constructors to extend classes.</p>
<h4>What next?</h4>
<p>There are better and more extensive tutorials available in video form courtesy of <a href="http://neglook.com/">Michael Michaels of neglOOk</a> available on the <a href="http://www.newlisp.org/index.cgi?Documentation">newLisp website</a>.</p>
<p><a href="/wp-content/uploads/2008/12/argslsp.gz">download</a></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Submit article</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhat-is-foop%2F&amp;title=What+is+FOOP%3F" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhat-is-foop%2F&amp;title=What+is+FOOP%3F" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=What+is+FOOP%3F&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhat-is-foop%2F&amp;title=What+is+FOOP%3F" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhat-is-foop%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhat-is-foop%2F&amp;title=What+is+FOOP%3F" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhat-is-foop%2F&amp;title=What+is+FOOP%3F" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhat-is-foop%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+What+is+FOOP%3F+@+http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhat-is-foop%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.artfulcode.net/articles/what-is-foop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

