<?xml version='1.0' encoding='utf-8' ?>
<!--  If you are running a bot please visit this policy page outlining rules you must respect. http://www.livejournal.com/bots/  -->
<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/' xmlns:media='http://search.yahoo.com/mrss/' xmlns:atom10='http://www.w3.org/2005/Atom'>
<channel>
  <title>Haskwhal</title>
  <link>http://ozten.livejournal.com/</link>
  <description>Haskwhal - LiveJournal.com</description>
  <lastBuildDate>Wed, 16 Sep 2009 04:55:39 GMT</lastBuildDate>
  <generator>LiveJournal / LiveJournal.com</generator>
  <lj:journal>ozten</lj:journal>
  <lj:journalid>13620944</lj:journalid>
  <lj:journaltype>personal</lj:journaltype>
  <atom10:link rel='hub' href='http://pubsubhubbub.appspot.com/' />
  <image>
    <url>http://l-userpic.livejournal.com/65162574/13620944</url>
    <title>Haskwhal</title>
    <link>http://ozten.livejournal.com/</link>
    <width>48</width>
    <height>48</height>
  </image>

<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/7631.html</guid>
  <pubDate>Wed, 16 Sep 2009 04:55:39 GMT</pubDate>
  <title>Reading about hlint</title>
  <link>http://ozten.livejournal.com/7631.html</link>
  <description>Via &lt;a href=&quot;http://www.fatvat.co.uk/2009/09/hlint.html&quot;&gt;Fatvat&apos;s take on HLint&lt;/a&gt; I learned about &lt;a href=&quot;http://community.haskell.org/~ndm/hlint/&quot;&gt;HLint&lt;/a&gt; and &lt;a href=&quot;http://neilmitchell.blogspot.com/2009/09/how-i-use-hlint.html&quot;&gt;Neil Mitchell&lt;/a&gt;&apos;s post on the tool.&lt;br /&gt;&lt;br /&gt;I haven&apos;t spent much time with it, but it seems like a good coding mentor for the intermediate Haskell programmer. As a noob, some of the feedback I&apos;m afraid to accept, such as the changes that push it towards point free form, whereas I&apos;m still clinging to my explicit parameters.&lt;br /&gt;&lt;br /&gt;Haskell has many cool development tools, the more I read about the ecosystem.</description>
  <comments>http://ozten.livejournal.com/7631.html</comments>
  <category>haskell</category>
  <category>haskwhal</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/7279.html</guid>
  <pubDate>Fri, 04 Sep 2009 01:09:23 GMT</pubDate>
  <title>hello world in CGI FastCGI and Happstack FastCGI</title>
  <link>http://ozten.livejournal.com/7279.html</link>
  <description>Just as a sanity check for &lt;a href=&quot;http://ozten.livejournal.com/7042.html&quot;&gt;Help! Can you run Happstack as a CGI?&lt;/a&gt; I made sure your Haskell CGI and FastCGI setup is working.&lt;br /&gt;&lt;br /&gt;&lt;h6&gt;CGI&lt;/h6&gt;&lt;br /&gt;&lt;code&gt;&lt;pre&gt;
-- ghc --make -o CgiPlay.cgi CgiPlay.hs 
import Network.CGI

cgiMain :: CGI CGIResult
cgiMain = output &quot;Hello World!&quot;

main :: IO ()
main = runCGI (handleErrors cgiMain)
&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;h6&gt;FastCGI&lt;/h6&gt;&lt;br /&gt;&lt;code&gt;&lt;pre&gt;
-- ghc -package fastcgi -threaded --make -o FCgiPlay.fcgi FCgiPlay.hs 
import Control.Concurrent
import System.Posix.Process (getProcessID)

import Network.FastCGI

test :: CGI CGIResult
test = do setHeader &quot;Content-type&quot; &quot;text/plain&quot;
          pid &amp;lt;- liftIO getProcessID
          threadId &amp;lt;- liftIO myThreadId
          let tid = concat $ drop 1 $ words $ show threadId
          output $ unlines [ &quot;Process ID: &quot; ++ show pid,
                             &quot;Thread ID:  &quot; ++ tid]

main = runFastCGIConcurrent&apos; forkIO 10 test
&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;h6&gt;Happstack on FastCGI&lt;/h6&gt;&lt;br /&gt;&lt;code&gt;&lt;pre&gt;
import Happstack.Server.FastCGI
import Happstack.Server.SimpleHTTP (askRq, getData, RqData, ToMessage)
import Happstack.Server (look, fromData, FromData, simpleHTTP, Conf(..), toResponse, ServerPartT)

simpleCGI :: (ToMessage a) =&amp;gt; ServerPartT IO a -&amp;gt; IO ()
simpleCGI = runFastCGIConcurrent 10 . serverPartToCGI
 
main = simpleCGI handleRequest

handleRequest = return $ toResponse &quot;Howdy From Happstack on FastCGI&quot;
&lt;/pre&gt;&lt;/code&gt;</description>
  <comments>http://ozten.livejournal.com/7279.html</comments>
  <category>cgi</category>
  <category>fastcgi</category>
  <category>haskell</category>
  <category>haskwhal</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/7042.html</guid>
  <pubDate>Wed, 02 Sep 2009 14:55:07 GMT</pubDate>
  <title>Help! Can you run Happstack as a CGI?</title>
  <link>http://ozten.livejournal.com/7042.html</link>
  <description>Does anyone already have code for running a Happstack app as a CGi instead of a HTTP Server?&lt;br /&gt;&lt;br /&gt;Searching for a CGI adapter or backend to Happstack, I didn&apos;t find anything. The documentation mentions you can do it... but it isn&apos;t clear if it works out of the box.&lt;br /&gt;&lt;br /&gt;I &lt;strong&gt;was&lt;/strong&gt; able to find the &lt;a href=&quot;http://hackage.haskell.org/package/happstack-fastcgi&quot;&gt;happstack-fastcgi&lt;/a&gt; package. For fun, I tried converting my app to fast-cgi, following the &lt;a href=&quot;http://blog.tupil.com/running-happstack-applications-with-fastcgi/&quot;&gt;blog post&lt;/a&gt; announcing the project. No dice.&lt;br /&gt;I changed&lt;br /&gt;&lt;code&gt;&lt;pre&gt;
main = handleSqlError $ trace &quot;Starting up, try port 8080&quot; (simpleHTTP (Conf 8080 Nothing) $ handleRequest)
&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;into&lt;br /&gt;&lt;code&gt;&lt;pre&gt;
main = simpleCGI handleRequest

simpleCGI :: (ToMessage a) =&amp;gt; ServerPartT IO a -&amp;gt; IO ()
simpleCGI = runFastCGIConcurrent 10 . serverPartToCGI 
&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;I compiled with&lt;br /&gt;&lt;code&gt;&lt;pre&gt;
ghc --make -package cgi -package xhtml -o main.fcgi Main.hs
&lt;/pre&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;when I run it via apache I get&lt;br /&gt;&lt;code&gt;&lt;pre&gt;
[Tue Sep 01 23:11:12 2009] [error] [client 172.16.46.1] FastCGI: incomplete headers (0 bytes) received from server &quot;/home/some/web/main.fcgi&quot;
&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;I&apos;d really like to find out how to run my app under plain old CGI, so that I can host it at &lt;a href=&quot;https://www.nearlyfreespeech.net/&quot;&gt;NearlyFreeSpeech&lt;/a&gt;. They don&apos;t support FastCGI, nor long running processes like the Server mode.&lt;/code&gt;&lt;/code&gt;</description>
  <comments>http://ozten.livejournal.com/7042.html</comments>
  <category>happstack</category>
  <category>haskell</category>
  <category>haskwhal</category>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/6842.html</guid>
  <pubDate>Tue, 01 Sep 2009 15:59:02 GMT</pubDate>
  <title>Segmentation Fault and small files for errors</title>
  <link>http://ozten.livejournal.com/6842.html</link>
  <description>I don&apos;t know if I should be proud of myself or not... but my toy application has Seg Faulted ghc :/&lt;br /&gt;&lt;br /&gt;I found to suspicious things&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Calling commit on a connection that had already been disconnected&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Trying read an int out of the textual representation of a &lt;pre&gt;Data.ByteString.Lazy.Char8&lt;/pre&gt; and insert it into the database&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;I&apos;m not quite sure, but fixing those two things have fixed the issue.&lt;br /&gt;&lt;br /&gt;Another thing I&apos;m noticing is to keep files extremely small, because while compile errors are verbose, runtime error reporting in ghci is very weak. Seg Fault gave me nothing... The error&lt;br /&gt;&lt;code&gt;&lt;pre&gt;Prelude.read: no parse&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;Gives me just a filename &lt;strong&gt;and no line number&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;I&apos;m excited I&apos;ve reached a milestone in my &lt;a href=&quot;http://github.com/ozten/Haskell.Random.Play/tree/f05878c19e242a249933ad53c9ca8ded79b4e50c/5bx&quot;&gt;toy application&lt;/a&gt;... I can&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;Send out HTML&lt;/li&gt;&lt;br /&gt;  &lt;li&gt;Include data from the Database in the HTML&lt;/li&gt;&lt;br /&gt;  &lt;li&gt;Process input from a form&lt;/li&gt;&lt;br /&gt;  &lt;li&gt;Save the data to the db&lt;/li&gt;&lt;br /&gt;  &lt;li&gt;Do a redirect&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;It&apos;s taken quite a few hours in 30 minute chunks to get this far. It&apos;s a good problem for exercising basic Haskell knowledge.</description>
  <comments>http://ozten.livejournal.com/6842.html</comments>
  <category>debugging</category>
  <category>errors</category>
  <category>haskell</category>
  <category>haskwhal</category>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/6493.html</guid>
  <pubDate>Sat, 29 Aug 2009 20:43:49 GMT</pubDate>
  <title>Being explicit helps compilation</title>
  <link>http://ozten.livejournal.com/6493.html</link>
  <description>It seems like I should be exact as possible with type signatures as I&apos;m learning. For example I was using:&lt;br /&gt;&lt;code&gt;&lt;pre&gt;doWeight :: (ServerMonad m) =&amp;gt; String -&amp;gt; m Response&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;which is all fine and good, until I change the String into a &lt;code&gt;Maybe Stats&lt;/code&gt;. Then I ran into some compilation errors and I figured it was with my Maybe plumbing or maybe the IO of the database connection. My compilation error was&lt;br /&gt;&lt;code&gt;&lt;pre&gt;
WeightController.hs:36:0:
    Ambiguous constraint `ServerMonad m&apos;
        At least one of the forall&apos;d type variables mentioned by the constraint
        must be reachable from the type after the &apos;=&amp;gt;&apos;
    In the type signature for `doWeight&apos;:
      doWeight :: (ServerMonad m) =&amp;gt; ServerPartT IO Response
Failed, modules loaded: Config, StatsDal, Stats, FiveBeeX, WeightView.
&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;It seems like the biggest clue, which I often miss, is to pay attention to every part of the compilation error message.... what line and character? &lt;strong&gt;Ambiguous&lt;/strong&gt; constraint... and then the hint of the actual type signature &lt;code&gt;ServerPartT IO Response&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;After fumbeling around, I remembred by looking at another one of my function type signatures that m Response was indeed ServerPartT IO Response, so without changing the implementation, but just the type signature to&lt;br /&gt;&lt;code&gt;&lt;pre&gt;doWeight :: Maybe Stats -&amp;gt; ServerPartT IO Response&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;everything compiles and works. I&apos;m just so used to the issue being the implementation, maybe always being explicit with the Type signature will reduce these compilation errors and red herrings.</description>
  <comments>http://ozten.livejournal.com/6493.html</comments>
  <category>haskell</category>
  <category>haskwhal</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/6258.html</guid>
  <pubDate>Thu, 27 Aug 2009 15:35:29 GMT</pubDate>
  <title>liftIO and a Formal Haskell Learning Curve</title>
  <link>http://ozten.livejournal.com/6258.html</link>
  <description>I’ve come to know Control.Monad.Trans and liftIO for the first time.&lt;br /&gt;&lt;br /&gt;I was trying to glue together Database.HDBC results and a Happstack.Server Response. My method’s which wouldn’t compile looked like&lt;br /&gt;&lt;a name=&quot;cutid1&quot;&gt;&lt;/a&gt;&lt;br /&gt;&lt;code&gt;&lt;pre&gt;
currentWeight :: ServerPartT IO Response
currentWeight = let conn = connectMySQL defaultMySQLConnectInfo { mysqlHost = host, mysqlDatabase = database, mysqlUser = username, mysqlPassword = password, mysqlUnixSocket = unixSocket}
                -- this works...
                --in return $ toResponse &quot;f&quot;
                -- but not this..
                in (currentStat conn) &amp;gt;&amp;gt;= showStats
                where
                  showStats :: Stats -&amp;gt; ServerPartT IO Response
                  showStats stats = return $ toResponse $ show stats
&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;The function &lt;code&gt;currentStat&lt;/code&gt; retrieves a row from the database and creates a Stats piece of data.&lt;br /&gt;&lt;br /&gt;I got some help on #haskell from ksf and Twey. I now understand that I needed to “lift” my expressions of type IO into the ServerPartT monad. liftIO was the recommended function. &lt;br /&gt;&lt;br /&gt;It makes sense now, but I didn’t know you could “stack contexts” like this.&lt;br /&gt;&lt;br /&gt;There was also some discussion of fmap, &amp;lt;$&amp;gt;, etc... but it was all a bit much for me at this point. There are so many advanced features to the language, I think it’s tough to give newbies advice. It’s seems easy to bake in lots of advanced features instead of the most basic, brain dead example, so that they will see the core of the answer and can then later “rework” it as they learn Applicative, combinators, partially applied functions, etc.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;One role that RWH plays, but that I think could be improved upon, is to have a Formal Haskell Learning Curve. It would be a series of “levels” in understanding the Haskell language. At beginner level I you study the syntax for declaring functions, data types, how to run your code, and part of the Prelude, recursion, etc. Level II you learn the IO monad, etc at higher levels it begins to branch. At level 4 you understand stacking monads, and a bunch of other stuff I don’t know yet :) Then when people are helping you they can try to stay on your level in the explanation.&lt;br /&gt;￼&lt;a href=&quot;http://www.flickr.com/photos/ozten/3861640187/&quot; title=&quot;Haskell Levels by oztenphoto, on Flickr&quot;&gt;&lt;img src=&quot;http://farm3.static.flickr.com/2634/3861640187_fe05ac2a93.jpg&quot; width=&quot;414&quot; height=&quot;500&quot; alt=&quot;Haskell Levels&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a name=&quot;cutid2&quot;&gt;&lt;/a&gt;&lt;br /&gt;We do this intuitively already when we teach someone a topic. With a formal learning curve, we can say... don’t tackle HDBC until your a level 3 and don’t mess with Happstack until your a level 4, etc.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;They also pointed me to the &lt;a href=&quot;”http://www.haskell.org/sitewiki/images/8/85/TMR-Issue13.pdf”&quot;&gt;Typeclassopedia&lt;/a&gt;, which I am reading now. This is good supplementary material, but covers way to many “levels” and steepens the learning curve.&lt;br /&gt;&lt;br /&gt;W00t! I’ve got data being displayed in my browser via MySQL...&lt;br /&gt;&lt;code&gt;&lt;pre&gt;
currentWeight :: ServerPartT IO Response
currentWeight = connectDb &amp;gt;&amp;gt;= (\conn -&amp;gt;
                    liftIO (currentStat conn) &amp;gt;&amp;gt;= showStats)
                where
                  connectDb = liftIO $ connectMySQL defaultMySQLConnectInfo { mysqlHost = host, mysqlDatabase = database, mysqlUser = username, mysqlPassword = password, mysqlUnixSocket = unixSocket}
                  showStats :: Stats -&amp;gt; ServerPartT IO Response
                  showStats stats = return $ toResponse $ show stats
&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;The key here was lifting the connection and lifting my results from the database each time, before using the &lt;code&gt;&amp;gt;&amp;gt;=&lt;/code&gt; function.&lt;br /&gt;</description>
  <comments>http://ozten.livejournal.com/6258.html</comments>
  <category>learning curve</category>
  <category>haskell</category>
  <category>haskwhal</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/6124.html</guid>
  <pubDate>Mon, 24 Aug 2009 16:21:33 GMT</pubDate>
  <title>Where can I put my debug statements?</title>
  <link>http://ozten.livejournal.com/6124.html</link>
  <description>I&apos;m not much on debuggers and rely on the REPL or println statements to learn what a piece of code is doing (or not doing). A frustration I&apos;ve been having when learning Haskell, is not knowing where I could use Debug.Trace&apos;s trace function in my code. The module Debug.Trace provides two methods.&lt;br /&gt;&lt;code&gt;&lt;pre&gt;
putTraceMsg :: String -&amp;gt; IO ()
trace :: String -&amp;gt; a -&amp;gt; a&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;I chose to go with putTaceMsg... because what the heck is that a -&amp;gt; a all about? Okay, so I plopped it into &lt;a href=&quot;http://github.com/ozten/Haskell.Random.Play&quot;&gt;my code&lt;/a&gt; and voila, it compiles and I get to see my output. A day later I added it to a different chunk of code and it won&apos;t compile.&lt;br /&gt;&lt;br /&gt;I was frustrated and confused. Then I noticed that it worked in an IO() context, but not in a pure function... Hmm.&lt;br /&gt;&lt;a name=&quot;cutid1&quot;&gt;&lt;/a&gt;&lt;br /&gt;I got a clue from reading &lt;span class=&apos;ljuser ljuser-name_totherme&apos; lj:user=&apos;totherme&apos; style=&apos;white-space: nowrap;&apos;&gt;&lt;a href=&apos;http://totherme.livejournal.com/profile&apos;&gt;&lt;img src=&apos;http://l-stat.livejournal.com/img/userinfo.gif&apos; alt=&apos;[info]&apos; width=&apos;17&apos; height=&apos;17&apos; style=&apos;vertical-align: bottom; border: 0; padding-right: 1px;&apos; /&gt;&lt;/a&gt;&lt;a href=&apos;http://totherme.livejournal.com/&apos;&gt;&lt;b&gt;totherme&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&apos;s post &lt;a href=&quot;http://totherme.livejournal.com/3674.html?thread=9050#t9050&quot;&gt;Development with Types&lt;/a&gt; and it&apos;s comments. I re-read chapters 4 and 7 of &lt;a href=&quot;http://book.realworldhaskell.org/read/&quot;&gt;RWH&lt;/a&gt; focusing on Types, I see that I&apos;ve been having trouble internalizing &amp;quot;everything is an expression. I need to unlearn the imperative statement oriented languages.&lt;br /&gt;&lt;br /&gt;I think I&apos;m starting to see what the basis is for where I can use trace. I&apos;ve got to focus on the &amp;quot;shape&amp;quot; of the main function or within my pure functions. Like lego bricks, the input Type and output Type of each component must match. The overall type must be satisfied by the expression. An expression can be broken up by if, let, where, case, and function calls. The various branches, must all have the same type. Doh, but realizing this difference from weakly typed, statement oriented languages really takes some time.&lt;br /&gt;&lt;br /&gt;Okay, so now I understand why trace has the signature String -&amp;gt; a -&amp;gt; a. This allows you to &amp;quot;hide&amp;quot; your tracing by not changing the Type of your expression. You are effectively wrapping a sub-expression in a trace.&lt;br /&gt;&lt;br /&gt;Example: To inject a bit of tracing, just wrap an expression in trace. Before and after, it retains the same shape:&lt;br /&gt;&lt;code&gt;&lt;pre&gt;
  some f
&lt;/pre&gt;&lt;/code&gt;becomes&lt;code&gt;&lt;pre&gt;  
  trace &amp;quot;hello world&amp;quot; (some f)
&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;Related learning, while trying to figure this out: I&apos;ve been avoiding declaring the Type signature of functions, until I had them &amp;quot;figured out&amp;quot;. It sounds like I need to go the other way around, so that I&apos;ll be sure that the pile of function calls maintains the correct shape.</description>
  <comments>http://ozten.livejournal.com/6124.html</comments>
  <category>haskell</category>
  <category>haskwhal</category>
  <lj:security>public</lj:security>
  <lj:reply-count>2</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/5747.html</guid>
  <pubDate>Fri, 21 Aug 2009 23:27:39 GMT</pubDate>
  <title>Haskwhal &amp;lt;- Eval Scheme, Apply Learnings</title>
  <link>http://ozten.livejournal.com/5747.html</link>
  <description>Introducing &lt;strong&gt;Haskwhal&lt;/strong&gt;, Missteps of a Narwhal calf...&lt;br /&gt;&lt;br /&gt;Hello again... I originally created this journal to track my progress through &lt;a href=&quot;http://mitpress.mit.edu/sicp/full-text/book/book.html&quot;&gt;The Structure and Interpretation of Computer Programs&lt;/a&gt;. Until this post, it was named &amp;quot;Eval Scheme, Apply Learnings&amp;quot;.&lt;br /&gt;&lt;br /&gt;I&apos;m moving on to study Haskell from the excellent book &lt;a href=&quot;http://book.realworldhaskell.org/read/&quot;&gt;Real World Haskell&lt;/a&gt;. A new name is in order... so it&apos;s Haskwhal. To tidy up, I&apos;ve re-tagged all the previous entries with &lt;a href=&quot;http://ozten.livejournal.com/tag/eval+scheme+apply+learnings&quot;&gt;Eval Scheme, Apply Learnings&lt;/a&gt;. As a &lt;a href=&quot;http://en.wikipedia.org/wiki/Lifelong_learning&quot;&gt;Lifelong Learner&lt;/a&gt; I try to learn a new programming language every 18 months, to learn new concepts and warp my mind a bit more.&lt;br /&gt;&lt;br /&gt;Going forward I&apos;m looking forward to doing a better job of using the &amp;quot;Friends&amp;quot; features of livejournal to find other newbie Haskellers, asking questions here in the journal, document my failures and successes, and generally learn in the open.&lt;br /&gt;&lt;pre&gt;

case journalEntry of
  Just learned -&amp;gt; apply $ whatWas $ learned 
  Nothing -&amp;gt; getAClue $ readComments&lt;/pre&gt;</description>
  <comments>http://ozten.livejournal.com/5747.html</comments>
  <category>haskell</category>
  <category>haskwhal</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/5401.html</guid>
  <pubDate>Sat, 07 Jun 2008 17:53:36 GMT</pubDate>
  <title>Finished SICP last April</title>
  <link>http://ozten.livejournal.com/5401.html</link>
  <description>Shame on me... I have been super busy with my new gig. So I finished my independent study on SICP and got my grade back... &lt;b&gt;A&lt;/b&gt; boo ya. I turned in a ton of work and it has been a very enlightening and worth while exercise. I really enjoyed working through SICP and STPL. I have not been doing any Lisp stuff since late-April. I will be focusing much more on Lisp in C&apos;s clothing aka JavaScript. I probably won&apos;t be updating this livejournal anymore ( and I wasn&apos;t very good at posting frequently during this study anywhoos ). Follow me at &lt;a href=&quot;http://ozten.com&quot;&gt;ozten.com&lt;/a&gt;</description>
  <comments>http://ozten.livejournal.com/5401.html</comments>
  <category>lisp</category>
  <category>scheme</category>
  <category>javascript</category>
  <category>eval scheme apply learnings</category>
  <category>class</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/5251.html</guid>
  <pubDate>Fri, 11 Apr 2008 03:47:32 GMT</pubDate>
  <title>Gnuplot in Action</title>
  <link>http://ozten.livejournal.com/5251.html</link>
  <description>My friend and colleague Philipp K. Janert is writing a book on &lt;a href=&quot;http://www.gnuplot.info/&quot;&gt;gnuplot&lt;/a&gt;. I am a technical reviewer and have thoroughly enjoyed the experience so far.&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://www.gnuplot.info/figs/title1.png&quot; style=&quot;float:right; margin: 10px;&quot; /&gt; The title is &lt;a href=&quot;http://www.manning.com/janert/&quot;&gt;Gnuplot in Action&lt;/a&gt;: Understanding Data with Graphs. It really coming along swimmingly! gnuplot is a really interesting graphing application. Much like ruby&apos;s irb, it gives you an interactive REPL ( read evaluate print loop ) where you can explore a dataset visually. There isn&apos;t a contemporary GUI, so figuring out how to setup and use the program has been a chore in the past, just working from man pages.&lt;br /&gt;&lt;br /&gt;This book revels the cultural aspects of how to really use the program, or incorporate it into systems by setting up the environment and writing little reusable commands. Before I had seen gnuplot, I thought you would have to fire up a spreadsheet program or Mathematica to do graphs. In reality, you can be trying to troubleshoot an issue by analyzing the frequency of errors in a server log, and then pipe the results into a file and display it with Gnuplot to spot trends and see relationships.&lt;br /&gt;&lt;br /&gt;Another nice aspect of the book is the background information on logarithms and logarithmic plots, a review of color spaces, and some details around how to expose quantitative information in your graphs. It also touches on how to integrate your graphs into &lt;a href=&quot;http://www.latex-project.org/&quot;&gt;LaTeX&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I was surprised at how many backends gnuplot comes with. I installed it on Mac OS X Tiger and was able to generate SVG, png, and Cocoa output. I had recently added gnuplot to my toolbag, so the chance to review this book couldn&apos;t have come at a better time.&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://www.manning.com/janert/&quot;&gt;&lt;img src=&quot;http://www.manning.com/janert/janert_cover150.jpg&quot; border=&quot;0&quot; style=&quot;float:left; margin-right: 10px;&quot; /&gt;&lt;/a&gt;&lt;br /&gt;Check the sample chapter &lt;a href=&quot;http://www.manning-source.com/books/janert/janert_meapch2.pdf&quot;&gt;Essential gnuplot&lt;/a&gt;.</description>
  <comments>http://ozten.livejournal.com/5251.html</comments>
  <category>unix</category>
  <category>data analysis</category>
  <category>graphs</category>
  <category>tools</category>
  <category>eval scheme apply learnings</category>
  <category>graphics</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/4896.html</guid>
  <pubDate>Sat, 15 Mar 2008 18:22:27 GMT</pubDate>
  <title>SICP 5.5 thoughts proper tail recursion</title>
  <link>http://ozten.livejournal.com/4896.html</link>
  <description>It&apos;s interesting how proper tail recursion is such a subtle and deep feature that is easy to get wrong in a language. Many languages don&apos;t support it, such as Java, and so you don&apos;t miss it if you don&apos;t have it. &lt;br /&gt;&lt;br /&gt;Recursion can make solutions for some problems much easier to think about and to implement. With iterative recursion, there is no additional memory overhead since the stack doesn&apos;t grow. But without proper tail recursion this problem solving technique is severely crippled.&lt;br /&gt;&lt;br /&gt;It makes me wonder about other subtle and deep potential features of programming languages are out there lurking.</description>
  <comments>http://ozten.livejournal.com/4896.html</comments>
  <category>lisp</category>
  <category>scheme</category>
  <category>sicp</category>
  <category>eval scheme apply learnings</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/4733.html</guid>
  <pubDate>Wed, 12 Mar 2008 05:12:41 GMT</pubDate>
  <title>5.3 update and Leopard quick view for DrScheme</title>
  <link>http://ozten.livejournal.com/4733.html</link>
  <description>SICP 5.1 - 5.3 have been really fun and really insane. Writing assembly code is really addictive, but at the same time like serving prison time. You really appreciate how closely the C programming language really is just an improved assembly. Having to think in such linear chunks, manage registers, and the state of the stack is t-e-d-i-o-u-s. &lt;br /&gt;&lt;br /&gt;It is pretty mind-blowing to keep going to deeper levels of computation and keep re-implementing the meta-circular evaluator. It&apos;s also nice to see how to two types of garbage collection work at a high level. There is a pun buried in the idea of using two arrays for implementing car and cdr memory. I laughed out loud in a &quot;I think I am losing it&quot; kind of way as I worked through 5.4.&lt;br /&gt;&lt;br /&gt;On a practical note, I am now using Mac OS X Leopard... and want scheme code to show up as text in the &quot;Quick View&quot; such as TimeMachine and Finder CoverFlow. &lt;br /&gt;&lt;br /&gt;I cracked open /Applications/PLT Scheme v372/DrScheme.app/Contents/Info.plist and added the following:&lt;br /&gt;After&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;string&amp;gt;372&amp;lt;/string&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Add&lt;br /&gt;&lt;code&gt;	&lt;br /&gt;	&amp;lt;key&amp;gt;UTExportedTypeDeclarations&amp;lt;/key&amp;gt;&lt;br /&gt;	&amp;lt;array&amp;gt;&lt;br /&gt;		&amp;lt;dict&amp;gt;&lt;br /&gt;			&amp;lt;key&amp;gt;UTTypeConformsTo&amp;lt;/key&amp;gt;&lt;br /&gt;			&amp;lt;array&amp;gt;&lt;br /&gt;				&amp;lt;string&amp;gt;public.text&amp;lt;/string&amp;gt;&lt;br /&gt;				&amp;lt;string&amp;gt;public.plain-text&amp;lt;/string&amp;gt;&lt;br /&gt;			&amp;lt;/array&amp;gt;&lt;br /&gt;			&amp;lt;key&amp;gt;UTTypeDescription&amp;lt;/key&amp;gt;&lt;br /&gt;			&amp;lt;string&amp;gt;Scheme text file&amp;lt;/string&amp;gt;&lt;br /&gt;			&amp;lt;key&amp;gt;UTTypeIdentifier&amp;lt;/key&amp;gt;&lt;br /&gt;			&amp;lt;string&amp;gt;org.plt-scheme&amp;lt;/string&amp;gt;&lt;br /&gt;			&amp;lt;key&amp;gt;UTTypeTagSpecification&amp;lt;/key&amp;gt;&lt;br /&gt;			&amp;lt;dict&amp;gt;&lt;br /&gt;				&amp;lt;key&amp;gt;com.apple.ostype&amp;lt;/key&amp;gt;&lt;br /&gt;				&amp;lt;string&amp;gt;TEXT&amp;lt;/string&amp;gt;&lt;br /&gt;				&amp;lt;key&amp;gt;public.filename-extension&amp;lt;/key&amp;gt;&lt;br /&gt;				&amp;lt;array&amp;gt;&lt;br /&gt;					&amp;lt;string&amp;gt;scm&amp;lt;/string&amp;gt;&lt;br /&gt;					&amp;lt;string&amp;gt;ss&amp;lt;/string&amp;gt;&lt;br /&gt;				&amp;lt;/array&amp;gt;&lt;br /&gt;			&amp;lt;/dict&amp;gt;&lt;br /&gt;		&amp;lt;/dict&amp;gt;&lt;br /&gt;	&amp;lt;/array&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;which should be before&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;/dict&amp;gt;&lt;br /&gt;&amp;lt;/plist&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Save file and touch the DrScheme.app or move it so Tiger picks up the changes.</description>
  <comments>http://ozten.livejournal.com/4733.html</comments>
  <category>eval scheme apply learnings</category>
  <lj:security>public</lj:security>
  <lj:reply-count>2</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/4479.html</guid>
  <pubDate>Thu, 06 Mar 2008 04:38:41 GMT</pubDate>
  <title>Random SICP updates</title>
  <link>http://ozten.livejournal.com/4479.html</link>
  <description>Mac OS X Leopard breaks SICP.pdf. So I just upgraded to 10.5 and now I can&apos;t use Preview&apos;s search to find specific snippets of code in the SICP book. This is a bummer, as I typically jump around the pdf cross referencing different parts of the book.&lt;br /&gt;&lt;br /&gt;I download Adobe&apos;s Reader 8 and it does find things like &lt;code&gt;(assign new-cdrs &lt;/code&gt; correctly, so oddly enough I will be using Adobe Reader often for the first time in about X years.&lt;br /&gt;&lt;br /&gt;Chapter 5 is really great at putting together the lower levels of computation and how the Lisp rubber hits the road. 5.3&apos;s description really drove home how garbage collection works in general, and how clever the idea of Lisp pairs are. Having two arrays one for car and one for cdr is very smart. The pun of pairs as values in the car or cdr made me laugh out loud on the bus.&lt;br /&gt;&lt;br /&gt;BTW a great update of the &lt;a href=&quot;http://vpri.org/pdf/steps_TR-2007-008.pdf&quot;&gt;Steps Toward The Reinvention of Programming&lt;/a&gt; is worth reading.</description>
  <comments>http://ozten.livejournal.com/4479.html</comments>
  <category>eval scheme apply learnings</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/4293.html</guid>
  <pubDate>Mon, 18 Feb 2008 07:58:31 GMT</pubDate>
  <title>Streams documentation</title>
  <link>http://ozten.livejournal.com/4293.html</link>
  <description>&lt;p&gt;I am most of the way through the exercises in Chapter 4, but am totally stalling on finishing. For some yak shaving goodness, I thought I would document the Query system and all the layers on top of Scheme which are need to implement this.&lt;/p&gt;
&lt;p&gt;PLT Streams code is originally by &lt;a href=&quot;http://people.csail.mit.edu/bkph/courses/6001/2007/2007_05_04.scm&quot;&gt;Berthold K.P. Horn for 2007 class&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I am starting from the bottom up... Without further ado&lt;/p&gt;
&lt;p&gt;Doh, LJ doesn&apos;t allow &lt;code&gt;iframe&lt;/code&gt;... so click to open in a new window
&lt;a href=&quot;http://www.ozten.com/2008/2/17/documentation/streams.html&quot; target=&quot;_new&quot;&gt;SICP Streams Documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Hopefully once I have it all documented in a Visual Language, then I can polish of the last questions quicker.&lt;/p&gt;</description>
  <comments>http://ozten.livejournal.com/4293.html</comments>
  <category>eval scheme apply learnings</category>
  <category>scheme streams</category>
  <lj:mood>sleepy</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/3873.html</guid>
  <pubDate>Thu, 27 Dec 2007 05:07:57 GMT</pubDate>
  <title>Package systems a special case of first class functions</title>
  <link>http://ozten.livejournal.com/3873.html</link>
  <description>SICP Lecture 7B makes a great point during the second Q&amp;A session about solving modularity and abstraction problems by reorganizing a solution around PGEN which parametrizes a general algorithm for a specific input. &lt;br /&gt;&lt;br /&gt;Early in the book, the similarity of class based object systems and package management systems with Scheme style first class functions kept peaking my interest. Sussman points out that first-class functions can solve modularity issues in the general case with a very simple minimal mechanism. Without first class functions, one can solve specific known problems without special language features such as packages, modules, etc.&lt;br /&gt;&lt;br /&gt;One case the immediately comes to mind is the Java language feature of anonymous inner classes for getting around certain awkward pieces of code ( usually introduced by static typing requirements ).</description>
  <comments>http://ozten.livejournal.com/3873.html</comments>
  <category>modularity</category>
  <category>lisp</category>
  <category>scheme</category>
  <category>java</category>
  <category>eval scheme apply learnings</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/3682.html</guid>
  <pubDate>Tue, 16 Oct 2007 04:50:50 GMT</pubDate>
  <title>Finished 3.4 and playing with backtracking</title>
  <link>http://ozten.livejournal.com/3682.html</link>
  <description>&lt;p&gt;So I finished Section 3.4 on concurrency. Sorry no posts for 2.3 - 3.4. Study group has been going well and I have been playing with Scheme instead of writing summaries here... Doh!
&lt;/p&gt;&lt;p&gt;
An example:&lt;br /&gt;
Implementing a backtracking stategy in Scheme:&lt;/p&gt;
&lt;pre&gt;
(define matrix
  #{
    #{40  53 216}
    #{252 52 85}
    #{150 36 70}
    })
(define (matrix-width)
  (vector-length (vector-ref matrix 0)))
(define (matrix-height)
  (vector-length matrix))
(define (energy@ matrix x y)
  ;(display (format &quot;energy@ ~a ~a~n&quot; x y))
  (vector-ref (vector-ref matrix y) x))
(define (energy@-test)
  (values
   (energy@ matrix 0 0)   ;=&amp;gt; 40
   (energy@ matrix 2 2))) ;=&amp;gt; 70

;problem - find lowest energy path from top row &quot;0&quot;
; to bottom row &quot;2&quot;. A path can only go 1 space away
; so 0,1 (value 53 above) can go to
;1,0 (252)
;1,1 (52)
;1,2 (85)
; since they are the left, down, and right spaces from 0,1
;
; The lowest energy path is found by adding cells in path
; Example perhaps
; x:0,y:1    x:1,y:2    x:2,y:1  could have the lowest sum
; when we add up the values 53 + 85 + 36

(define (brute-find-lowest-no-cache)
  (define (column-iter n)
    (define (try-path x y solution)
      (if (or (or (&amp;gt;= y (matrix-height))
                  (&amp;lt; x 0))
              (&amp;gt;= x (matrix-width)))
          solution
          (let* ((try-left (&amp;gt; x 0))
                 (left-sum (if try-left 
                               (+ (try-path (- x 1) (+ 1 y) (energy@ matrix x y)) solution)
                               30000))
                 (try-down #t) ; see assertion below
                 (down-sum (if try-down 
                               (+ (try-path  x (+ 1 y) (energy@ matrix x y)) solution)
                               (error &quot;Should never happen, can always go down without hitting an edge&quot;)))
                 (try-right (&amp;lt; x (- (matrix-width) 1)))
                 (right-sum (if try-right 
                                (+ (try-path (+ 1 x) (+ 1 y) (energy@ matrix x y)) solution)
                                30000)))
            (cond ((and try-left (and (&amp;lt; left-sum down-sum) (&amp;lt; left-sum right-sum)))
                   left-sum)
                  ((and try-right (and (&amp;lt; right-sum down-sum) (&amp;lt; right-sum left-sum)))
                   right-sum)
                  (else
                   down-sum)))))
    ;(display (format &quot;Doing ~a~n&quot; n))
    (if (&amp;gt;= n (matrix-width))
        0
        (begin
          ;(display (format &quot;x=~a~n&quot; n))
          (display (format &quot;col ~a lowest=~a~n&quot; n (try-path n 0 0)))
          (column-iter (+ 1 n)))))
  (column-iter 0))
;(brute-find-lowest-no-cache)

(define (get-cache-key x y)
  ;todo try sha-digest on this output, profile...
  (format &quot;~a:~a&quot; x y))
(define *cache* #f)
(define (brute-find-lowest)
  (let ((cache (make-hash-table &apos;equal)))
    (define (column-iter n)
      (define (try-path x y solution)
        (let* ((cache-key (get-cache-key x y))
               (cached-answer (hash-table-get cache cache-key #f)))
          (if cached-answer
              (begin
                ;(display (format &quot;Using cached answer for cache-key=~a cached-answer=~a~n&quot; cache-key cached-answer))
                (+ cached-answer solution))
              (if (or (or (&amp;gt;= y (matrix-height))
                          (&amp;lt; x 0))
                      (&amp;gt;= x (matrix-width)))
                  solution                  
                  (let* ((try-left (&amp;gt; x 0))
                         (left-sum (if try-left
                                       (let* ((new-solution                                                (try-path (- x 1) (+ 1 y) (energy@ matrix x y))) 
                                              
                                              (new-cache-key (get-cache-key x y)))
                                         ;(display (format &quot;at ~a put ~a~n&quot; new-cache-key new-solution))
                                         ;(hash-table-put! cache new-cache-key new-solution)
                                          new-solution )
                                       30000))
                         (try-down #t) ; see assertion below
                         (down-sum (if try-down 
                                       (let* ((new-solution
                                               (try-path  x (+ 1 y) (energy@ matrix x y)) 
                                               )
                                              (new-cache-key (get-cache-key x y)))
                                         ;(display (format &quot;at ~a put ~a~n&quot; new-cache-key new-solution))
                                         ;(hash-table-put! cache new-cache-key new-solution)
                                         new-solution
                                         )
                                       (error &quot;Should never happen, can always go down without hitting an edge&quot;)))
                         (try-right (&amp;lt; x (- (matrix-width) 1)))
                         (right-sum (if try-right                                      
                                        (let* ((new-solution
                                                (try-path (+ x 1) (+ 1 y) (energy@ matrix x y)) 
                                                )
                                               
                                               (new-cache-key (get-cache-key x y)))
                                          ;(display (format &quot;at ~a put ~a~n&quot; new-cache-key new-solution))
                                          
                                          new-solution )
                                        30000)))
                    
                    (cond ((and try-left (and (&amp;lt; left-sum down-sum) (&amp;lt; left-sum right-sum)))
                           (hash-table-put! cache (get-cache-key x y) left-sum)
                           (+ left-sum solution))
                          ((and try-right (and (&amp;lt; right-sum down-sum) (&amp;lt; right-sum left-sum)))
                           (hash-table-put! cache (get-cache-key x y) right-sum)
                           (+ right-sum solution))
                          (else
                           (hash-table-put! cache (get-cache-key x y) down-sum)
                           (+ down-sum solution))))))))
      ;(display (format &quot;Doing ~a~n&quot; n))
      (if (&amp;gt;= n (matrix-width))
          0
          (begin
            ;(display (format &quot;x=~a~n&quot; n))
            ;(display (format &quot;col ~a lowest=~a~n&quot; n (try-path n 0 0)))
            (column-iter (+ 1 n)))))
    (column-iter 0)
    (set! *cache* cache)
    ))

(define lowest-seen 10000)
(define (backtracking-find-lowest)
  (define (column-iter n)
    (define (try-path x y solution-so-far)
      (if (or (or (or (&amp;gt;= y (matrix-height))
                      (&amp;lt; x 0))
                  (&amp;gt;= x (matrix-width)))
              (&amp;gt;= solution-so-far lowest-seen))
          solution-so-far
          
          (let* ((try-left (&amp;gt; x 0))
                 (left-sum (if try-left 
                               (+ (try-path (- x 1) (+ 1 y) (energy@ matrix x y)) solution-so-far)
                               30000))
                 (try-down #t) ; see assertion below
                 (down-sum (if try-down 
                               (+ (try-path  x (+ 1 y) (energy@ matrix x y)) solution-so-far)
                               (error &quot;Should never happen, can always go down without hitting an edge&quot;)))
                 (try-right (&amp;lt; x (- (matrix-width) 1)))
                 (right-sum (if try-right 
                                (+ (try-path (+ 1 x) (+ 1 y) (energy@ matrix x y)) solution-so-far)
                                30000)))
            (cond ((and try-left (and (&amp;lt; left-sum down-sum) (&amp;lt; left-sum right-sum)))
                   left-sum)
                  ((and try-right (and (&amp;lt; right-sum down-sum) (&amp;lt; right-sum left-sum)))
                   right-sum)
                  (else
                   down-sum)))))
    ;(display (format &quot;Doing ~a~n&quot; n))
    (if (&amp;gt;= n (matrix-width))
        0
        (let ((solution (try-path n 0 0)))
          ;(display (format &quot;x=~a~n&quot; n))
          (if (&amp;lt; solution lowest-seen)
              (begin
                ;(display &quot;New lowest ever&quot;)(newline)
                (set! lowest-seen solution)))
          (display (format &quot;col ~a lowest=~a~n&quot; n solution))
          (column-iter (+ 1 n)))))
  (column-iter 0))
;(backtracking-find-lowest)
&lt;/pre&gt;
&lt;p&gt;
So I coded up a brute force solution, a backtracking solution, and then backtracking with caching. In Land of the Lost terminology that is memoization which simply means caching results. Then I ran
&lt;/p&gt;
&lt;code&gt;&lt;pre&gt;(time-apply brute-find-lowest &apos;())&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;&lt;a href=&quot;http://www.ozten.com/SICP/backtracking.scm&quot;&gt;backtracking.scm&lt;/a&gt; has the gory details including a real jpeg converted into an &quot;energy map&quot; for testing with a larger data set.&lt;/p&gt;</description>
  <comments>http://ozten.livejournal.com/3682.html</comments>
  <category>lisp</category>
  <category>scheme</category>
  <category>eval scheme apply learnings</category>
  <lj:mood>amused</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/3361.html</guid>
  <pubDate>Wed, 10 Oct 2007 00:05:23 GMT</pubDate>
  <title>Behind on blog updates</title>
  <link>http://ozten.livejournal.com/3361.html</link>
  <description>So I am still on pace with Reading SICP and doing exercises, but haven&apos;t really had time to update this blog with ruminations.&lt;br /&gt;&lt;br /&gt;I find the text a much deeper wading into Lisp and computational processes, which is what I needed after reading the &lt;a href=&quot;http://www.gigamonkeys.com/book/&quot;&gt;Lisp Tutorial&lt;/a&gt; and the Little Schemer books.&lt;br /&gt;&lt;br /&gt;The study group has been going well with pretty consistent attendance. I hope my taking a break for one month to go to South Africa doesn&apos;t disturb the flow too much.</description>
  <comments>http://ozten.livejournal.com/3361.html</comments>
  <category>lisp</category>
  <category>update</category>
  <category>scheme</category>
  <category>cl</category>
  <category>eval scheme apply learnings</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/3122.html</guid>
  <pubDate>Tue, 18 Sep 2007 03:49:03 GMT</pubDate>
  <title>Unit Testing Scheme code</title>
  <link>http://ozten.livejournal.com/3122.html</link>
  <description>Today I played around with three testing frameworks for PLT DrScheme.&lt;br /&gt;&lt;br /&gt;SRFI-78 &quot;check.ss&quot;, SRFI-64 &quot;testing.ss&quot;, and lastly SchemeUnit &quot;test.ss&quot;.&lt;br /&gt;&lt;br /&gt;I started with SRFI-78 since it was a more recent standard. It has a very minimal API.&lt;br /&gt;(require (lib &quot;check.ss&quot; &quot;srfi&quot; &quot;78&quot;))&lt;br /&gt;(check-set-mode! &apos;report-failed ) ;report-failed)&lt;br /&gt;(load &quot;image-filters.scm&quot;)&lt;br /&gt;(check (get-nth-filter 0) =&amp;gt; identity-filter)&lt;br /&gt;(check (get-nth-filter 1) =&amp;gt; sharpen-filter)&lt;br /&gt;(check (get-nth-filter 1) =&amp;gt; identity-filter)&lt;br /&gt;(check-report)&lt;br /&gt;&lt;br /&gt;(get-nth-filter 1)&lt;br /&gt; =&amp;gt; ((0 -2 0 -2 11 -2 0 -2 0) 3 0)&lt;br /&gt; ; *** failed ***&lt;br /&gt; ; expected result: ((1 1 1 1 1 1 1 1 1) 9 0)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;; *** checks *** : 2 correct, 1 failed. First failed example:&lt;br /&gt;&lt;br /&gt;(get-nth-filter 1)&lt;br /&gt; =&amp;gt; ((0 -2 0 -2 11 -2 0 -2 0) 3 0)&lt;br /&gt; ; *** failed ***&lt;br /&gt; ; expected result: ((1 1 1 1 1 1 1 1 1) 9 0)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Loading the file causes the tests to be run. I didn&apos;t like the output, but found &quot;check-set-model&quot; would keep it to only reporting failed tests. This is pretty good, but very minimal.&lt;br /&gt;&lt;br /&gt;As I read more, I realized that this library wasn&apos;t the only SRFI testing standard, so I also loaded up 64 and gave it a shot.&lt;br /&gt;&lt;br /&gt;(require (lib &quot;testing.ss&quot; &quot;srfi&quot; &quot;64&quot;))&lt;br /&gt;(load &quot;image-filters.scm&quot;)&lt;br /&gt;(test-begin &quot;Image Filters&quot;)&lt;br /&gt;(test-eqv identity-filter (get-nth-filter 0))&lt;br /&gt;(test-eqv sharpen-filter  (get-nth-filter 1))&lt;br /&gt;(test-eqv identity-filter (get-nth-filter 1))&lt;br /&gt;(test-error &quot;Bad input&quot;   (get-nth-filter 100))&lt;br /&gt;(test-end)&lt;br /&gt;&lt;br /&gt;Again, loading this fail causes the test runner to run with the results:&lt;br /&gt;%%%% Starting test Image Filters  (Writing full log to &quot;Image Filters.log&quot;)&lt;br /&gt;:14: FAIL&lt;br /&gt;Nth filter : 100&lt;br /&gt;# of expected passes      3&lt;br /&gt;# of unexpected failures  1&lt;br /&gt;&lt;br /&gt;Both of these libraries dis a xUnit style library &lt;a href=&quot;http://planet.plt-scheme.org/package-source/schematics/schemeunit.plt/2/8/doc.txt&quot;&gt;SchemeUnit&lt;/a&gt;, so I had to give this one a go also.&lt;br /&gt; &lt;br /&gt;(require (planet &quot;test.ss&quot; (&quot;schematics&quot; &quot;schemeunit.plt&quot; 2)))&lt;br /&gt;(load &quot;image-filters.scm&quot;)&lt;br /&gt;&lt;br /&gt;(define file-tests&lt;br /&gt;  (test-suite&lt;br /&gt;   &quot;Test image-filters.scm&quot;&lt;br /&gt;   (test-equal? &quot;First element is zero indexed&quot; (get-nth-filter 0)  identity-filter)&lt;br /&gt;   (test-equal? &quot;Normal case&quot;  (get-nth-filter 1) sharpen-filter)&lt;br /&gt;   (test-equal? &quot;Pretend error&quot; (get-nth-filter 1)  identity-filter )))&lt;br /&gt;&lt;br /&gt;Which comes with two test runners, a text and gui. Let&apos;s run them both...&lt;br /&gt;&lt;br /&gt;Text Test Runner&lt;br /&gt;&lt;br /&gt;Test image-filters.scm &amp;gt; Pretend error&lt;br /&gt;Pretend error has a FAILURE&lt;br /&gt;name: check-equal?&lt;br /&gt;location: #&amp;gt;struct:object:...pper stepper-tool.ss:618:8=&quot;&quot;&amp;lt;:31:3&lt;br /&gt;actual: ((0 -2 0 -2 11 -2 0 -2 0) 3 0)&lt;br /&gt;expected: ((1 1 1 1 1 1 1 1 1) 9 0)&lt;br /&gt;2 success(es) 1 failure(s) 0 error(s) 3 test(s) run&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;and Gui Test Runner&lt;br /&gt;

&lt;a title=&quot;Photo Sharing&quot; href=&quot;http://www.flickr.com/photos/ozten/1400279068/&quot;&gt;&lt;img width=&quot;647&quot; height=&quot;454&quot; alt=&quot;SchemeUnit&quot; src=&quot;http://farm2.static.flickr.com/1160/1400279068_91108cb69c_o.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I think SRFI-64 and SchemeUnit are both usable. I am more familiar with xUnit APIs so I am going to start coding against SchemeUnit for now.</description>
  <comments>http://ozten.livejournal.com/3122.html</comments>
  <category>libraries</category>
  <category>lisp</category>
  <category>scheme</category>
  <category>eval scheme apply learnings</category>
  <category>unit testing</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/2981.html</guid>
  <pubDate>Thu, 13 Sep 2007 05:11:33 GMT</pubDate>
  <title>Sections 2.1 and 2.2</title>
  <link>http://ozten.livejournal.com/2981.html</link>
  <description>SICP Section 2.1&lt;br /&gt;The text introduces the topic of Data Abstraction. Coming into this discussion, I see this as a core feature of Object Oriented Programming and an element for enabling programming in the large.&lt;br /&gt;&lt;br /&gt;It is also another tool for adding abstraction to a system. Given selectors, constructors, and invariant rules or contracts, one can happily go about programming by “wishful thinking” caring only about this interface and not the actual data representation on the backend. This is important as one either builds layers of abstraction, or attempts to collaborate on a system with other programmers.&lt;br /&gt;&lt;br /&gt;The text runs though silly implementations of basic “primitives” of Lisp, to show that as long as selectors and constructors use the same silly implementation everything will work, albeit slowly.&lt;br /&gt;&lt;br /&gt;This has massive benefits for prototyping and agile system development. Once can sketch-out a component of the system, but not commit to it’s details or spend time on making it efficient, until it is something that is worth investing in. Also this supports &lt;a href=&quot;http://en.wikipedia.org/wiki/David_Parnas&quot;&gt;David Parnas&lt;/a&gt; style information hiding and module de-composition. If one structures the abstract data types so that they use only the constructors and selectors of other abstract data types, then one can rework the implementation without recoding these parts.&lt;br /&gt;&lt;br /&gt;Section 2.2&lt;br /&gt;The text continues to blur the lines between data and code, when introducing the concept of hierarchical data and the closure property. This term “closure property” used in the text been superseded by a new concept of scoping rules and environment. I would call this feature composition or regularity. A cons is a pair of boxes that point to something. A cons pair may in-fact point to two other cons pairs. Thus the definition achieves “closure” and powerful abilities emerge out from this. &lt;br /&gt;&lt;br /&gt;I think about GUI programming where every widget is composable and recomposable. Example you can place a frame inside of a panel inside of a tabbed widget and so on. The ability to nest them brings power and the regularity brings simplicity.&lt;br /&gt;&lt;br /&gt;We can model sequences or hierarchical structures with the same simple glue. &lt;br /&gt;&lt;br /&gt;The section on “A Picture Language” is a very cool example. In this picture language the only primatives are painters. A painter given a rectangle, paints itself into that rectangle. The means of combination are functions, created with a rectable, that compose other painters. We are given two painters “Rogers” and an Escheresque “Wave” drawing where the line segments wrap around the image, for maximum trippiness factor.&lt;br /&gt;&lt;br /&gt;Very quickly the text begins creating composition combinators that do nothing more than compose other painters, but which create complexity from simple parts very quickly. Thus the “beside” combinator breaks the field in half and populates each half recursively with it’s two arguments.&lt;br /&gt;&lt;br /&gt;These painters are sort of data, in that they represent a photo, but at the same time they are a procedure that given a rectangle, render onto the screen.&lt;br /&gt;&lt;br /&gt;Again, similar to writing of Parnas, the text stress the importance of stratified design, such that each layer in a system builds on the abstraction below it only. This allows one to make a more robust system and to focus on less details at any one time.</description>
  <comments>http://ozten.livejournal.com/2981.html</comments>
  <category>lisp</category>
  <category>sicp</category>
  <category>section 2.1 2.2</category>
  <category>eval scheme apply learnings</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/2579.html</guid>
  <pubDate>Thu, 13 Sep 2007 04:37:46 GMT</pubDate>
  <title>SICP Section 1.3</title>
  <link>http://ozten.livejournal.com/2579.html</link>
  <description>High order procedures are a very powerful mechanism for designing procedures. In languages that support it, one can pass procedures into procedures as arguments, or similarly have a procedure which returns a procedure as it’s result.&lt;br /&gt;&lt;br /&gt;One first blush this sound like a lot of complicated gobbledygook, but being able to pass in procedures allows one to factor code to capture common patterns and name it as a new abstraction, via a procedure, which can be written, tested, and documented once. An example from the Ruby world would be File#open method given a block. This procedure accepts a block executes the block in the context of an open file, and lastly closes the file. The user doesn’t need to remember to do with, if they pass in their “read file” procedure which takes one argument “file-handle” then they don’t have to duplicate standard file code.&lt;br /&gt;&lt;br /&gt;Being able to return procedures from procedures, I image, would allow one to parameterize the new procedure. One of the annoying things about Java’s object constructors is that they can not create and return a subclass. So one ends up adding static “creation” methods, so that you can parameters the object you give out. High order procedures don’t have this limitation and you can dynamically build a function based on the inputs the the current procedure.&lt;br /&gt;&lt;br /&gt;In a way this is run time code generation. I think this makes it harder to reason about the code, and it use probably really shines when it clarifies an idiom and captures it, but it could be needless complexity or obfuscation when used without purpose.&lt;br /&gt;&lt;br /&gt;This “first class” notion of functions, where you can name them by variables, pass as arguments to procedures, returned as results from procedures, and be included as elements of data structures, increases the faculty for building abstractions.</description>
  <comments>http://ozten.livejournal.com/2579.html</comments>
  <category>lisp</category>
  <category>sicp</category>
  <category>eval scheme apply learnings</category>
  <category>section 1.3</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/2480.html</guid>
  <pubDate>Sun, 09 Sep 2007 18:04:19 GMT</pubDate>
  <title>counting car</title>
  <link>http://ozten.livejournal.com/2480.html</link>
  <description>&lt;a href=&quot;http://blog.plt-scheme.org/2007/09/how-many-occurrences-of-car-in-plt.html&quot;&gt;How many occurrences of Car in PLT Scheme&lt;/a&gt; is a great blog post. I have an idea for learning new PL languages and their idioms. Get a sample of &quot;good&quot; projects, and then do static code analysis. This would allow you to study the documentation of syntax in the order it is used the most, and discover those idioms faster.&lt;br /&gt;&lt;br /&gt;I have never implemented a system to try this out. Languages where there is a large body of quality projects under open source licensing would be a requirements.</description>
  <comments>http://ozten.livejournal.com/2480.html</comments>
  <category>eval scheme apply learnings</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/2103.html</guid>
  <pubDate>Sun, 09 Sep 2007 04:56:46 GMT</pubDate>
  <title>SICP Exercises 1.1 - 1.7</title>
  <link>http://ozten.livejournal.com/2103.html</link>
  <description>I have been slow in posting these, but here is exercises 1.1 - 1.7
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ozten.com/SICP/SICP-1.1.scm&quot;&gt;Exercise 1.1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ozten.com/SICP/SICP-1.2.scm&quot;&gt;Exercise 1.2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ozten.com/SICP/SICP-1.3.scm&quot;&gt;Exercise 1.3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ozten.com/SICP/SICP-1.4.scm&quot;&gt;Exercise 1.4&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ozten.com/SICP/SICP-1.5.scm&quot;&gt;Exercise 1.5&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ozten.com/SICP/SICP-1.6.scm&quot;&gt;Exercise 1.6&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ozten.com/SICP/SICP-1.7.scm&quot;&gt;Exercise 1.7&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</description>
  <comments>http://ozten.livejournal.com/2103.html</comments>
  <category>lisp</category>
  <category>scheme</category>
  <category>homework</category>
  <category>sicp</category>
  <category>exercises</category>
  <category>eval scheme apply learnings</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/2031.html</guid>
  <pubDate>Tue, 04 Sep 2007 04:30:52 GMT</pubDate>
  <title>SICP 1.2 recursion fun</title>
  <link>http://ozten.livejournal.com/2031.html</link>
  <description>Reading section 1.2 and watching Lecture 1-b. Up until now, I had the false understanding that any procedure which calls itself was considered recursive in terms of both written procedure and runtime process. Aside, that doesn&apos;t mean that I shied away from using recursion, and I did have an intuitive feel that some forms of recursion performed better than others. &lt;br /&gt;&lt;br /&gt;Why structure a procedure using recursion? Often code written using recursion is easier to understand, for certain classes of problems, like process tree based structures ( XML Nodes ). The book also discusses an algorithm for making change from different coins, where the recursive algorithm is easier to understand.&lt;br /&gt;&lt;br /&gt;I had previously missed the distinction between how a procedure is specified in source code, and how the processes runs and evolves through time. SICP refines the definition of recursion specifically for processes into iterative processes and recursive processes. Iterative, doesn&apos;t mean that it can&apos;t be written using recursion. An operation may call itself, but it does so in constant space in a straight forward manner, but like a for loop changing the state of loop variables.&lt;br /&gt;&lt;br /&gt;So how do we frame procedures, so that we get the runtime process we want?&lt;br /&gt;&lt;br /&gt;The metaphor of &quot;Bureaucracy&quot; in the video drove the lesson home of explicit state, versus hiding state away in the machinery of the computation. In the bureaucracy lite version, you ask someone to solve a problem. They ask someone else to solve a similar problem and to give the results back to you directly. They have processed one step and are now out of the picture, have passed on the final destination and updated state of the problem. This is an interative process that chips away at the answer in constant space. The procedure may call back into itself, but it is still an iterative processes.&lt;br /&gt;&lt;br /&gt;The heavy bureaucracy has you ask someone to solve a problem. They process part of the problem and delegate another part to someone else. When that person is finished they answer back to their manager, instead of passing the finished work to you. They then finish processing the partially solved problem and give you the answer, perhaps claiming credit for all of their child processes work. This hidden state is all of the operations delegating to further operations and awaiting a response to post process and hand back up the chain of command.&lt;br /&gt;&lt;br /&gt;I find the domain of SICP ( mathematics ) very challenging, so it takes me a long time to solve the math focused exercises, but I can get the gist of what the problem is trying to get me to think about, and thus make some guesses at the directions for massaging the equations from recursive to iterative and back again.</description>
  <comments>http://ozten.livejournal.com/2031.html</comments>
  <category>lisp</category>
  <category>scheme</category>
  <category>sicp</category>
  <category>eval scheme apply learnings</category>
  <category>1.2</category>
  <lj:mood>busy</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/1627.html</guid>
  <pubDate>Thu, 30 Aug 2007 17:45:24 GMT</pubDate>
  <title>Thoughts on SICP 1.1</title>
  <link>http://ozten.livejournal.com/1627.html</link>
  <description>&lt;p&gt;Section 1.1 of SICP starts of with some simple, straight forward basics of programming languages, but at the same time provided some deep food for thought.&lt;/p&gt;
&lt;p&gt;Judging for this limited exposure, Scheme has a very minimal syntax and is incredibly regular. We learn how to use expressions and names. Names are similar to variable names from a language like Java, but are more general in that they also serve the purpose of naming data or functions, by placing them into the current environment.&lt;/p&gt;

&lt;p&gt;Next we see that we can combine expressions and that a grouping of operator followed by operands is called a combination. Again very simple and regular. The postfix notation doesn&apos;t bother me since I have spent some time playing with Common Lisp for doing generative graphics.&lt;/p&gt;

&lt;p&gt;The section on substitution models is really fascinating and I am having a hard time keeping the two notions straight. The two notions being applicative order and normal order. I have created a mnemonic &quot;nORmal order is ||&quot;. This means most substitution follows the textual pattern, except some things are conditionally or lazily computed, just like &lt;code&gt;||&lt;/code&gt; in Java. If we say
&lt;pre&gt;if( foo() || bar() ){
  baz()
}
&lt;/pre&gt;
in Java, it is poosible that bar() may never be computed.&lt;/p&gt;

&lt;p&gt;I had rarely considered this formally as a first class notion. I have created a template language in the past and when implementing looping and conditional logic I had to implement a normal order substitution model, but just kind of stumbled through it, without the formal perspective.&lt;/p&gt;

&lt;p&gt;Scheme seems to run in applicative order normally, except for when you declare that you want to step out into normal order.&lt;/p&gt;

&lt;p&gt;The chapter moves on to look at Newton&apos;s Method for approximating square roots. These mathematical passages are challenging to me, and I better buck up if I am going to finish this book. Perhaps I will learn a fair amount of math along the way. It would be great to rewrite the domain aspect of this text using the domain of web programming instead of math :) Of course you would have to dive into input output very early, which isn&apos;t desirable from a pedagogical point of view.&lt;/p&gt;

&lt;p&gt;Lastly this chapter defines several functions in a nested fashion within an overall function. This left me in awe for a few minutes. Wowsers. This is so simple, regular, and powerful! This immediately reminded me of Java classes and how they must be implemented under the covers. Except that Java has many more restrictions and semantics on top of the class keyword. Here we are left with the raw power and goodness of nested function definition. Parameters to the top-most function are visible within the scope of the nested function. The nested function isn&apos;t defined in the global environment, and thus doesn&apos;t pollute it&apos;s namespace. The is something really interesting going on here, which I think will become clearer as I gain more experience with these constructs, but all ready it sets my mind alight.&lt;/p&gt;

&lt;p&gt;The ability to name functions and nest functions allows us to build powerful black box abstractions. No notion of interface or documentation has been introduced yet, but the idea is that you can tell someone if you calll operator X with arguments y and z then you can expect foo as a result.&lt;/p&gt; 

&lt;p&gt;This allows construction of programs in a layered fashion, whereby each piece follows contracts between interfaces and the overall complexity of the system is broken down into manageable chunks that can be
&lt;ul&gt;
&lt;li&gt;tested&lt;/li&gt;
&lt;li&gt;thought about&lt;/li&gt;
&lt;li&gt;reused&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Exercises 1.5 and 1.6 were great. Working them out on paper, as well as
exploring some possibilities from Scheme REPL really helps to understand the substitution
model.&lt;/p&gt;</description>
  <comments>http://ozten.livejournal.com/1627.html</comments>
  <category>lisp</category>
  <category>scheme</category>
  <category>eval scheme apply learnings</category>
  <category>sicp 1.1</category>
  <lj:mood>calm</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ozten.livejournal.com/1354.html</guid>
  <pubDate>Wed, 29 Aug 2007 22:00:03 GMT</pubDate>
  <title>R6RS ratified</title>
  <link>http://ozten.livejournal.com/1354.html</link>
  <description>A controversial &lt;a href=&quot;http://www.r6rs.org/ratification/results.html&quot;&gt;R6RS has been ratified&lt;/a&gt;. I like how open the voting is, so I can read what concerns were voiced. 65.7% voted in favor of the new standard. Yikes, that is a narrow margin. According to the document 60% were required to pass.&lt;br /&gt;&lt;br /&gt;Of course as a complete newbie to Scheme, I have no opinion. I would tend to agree with the gist of the ideas that R4RS serves as a better research tool, and that R6RS would make a better production language. It is disconcerting that many of the Nahs stated that the process ignored many of the &lt;a href=&quot;http://srfi.schemers.org/&quot;&gt;SRFI&lt;/a&gt;s.</description>
  <comments>http://ozten.livejournal.com/1354.html</comments>
  <category>lisp</category>
  <category>scheme</category>
  <category>eval scheme apply learnings</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
</channel>
</rss>
