<?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>weaselhat &#187; Software</title>
	<atom:link href="http://www.weaselhat.com/category/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.weaselhat.com</link>
	<description></description>
	<lastBuildDate>Wed, 01 Feb 2012 20:18:01 +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>QuickRedex</title>
		<link>http://www.weaselhat.com/2012/02/01/quickredex/</link>
		<comments>http://www.weaselhat.com/2012/02/01/quickredex/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 20:18:01 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=321</guid>
		<description><![CDATA[Following Robby Findler&#8217;s excellent presentation on PLT Redex at POPL (check out the paper and presentation!), I hacked up something similar in Haskell. Naturally, it&#8217;s all manual, and there&#8217;s none of the publication or visualization support, but the essence is there. Here&#8217;s the code for the untyped lambda calculus: Haskell [Show Styled Code]: module Untyped [...]]]></description>
			<content:encoded><![CDATA[<p>Following <a href="http://eecs.northwestern.edu/~robby/" title="I am the walrus.">Robby Findler&#8217;s</a> excellent presentation on <a href="http://redex.plt-scheme.org/">PLT Redex</a> at POPL (check out the <a href="http://eecs.northwestern.edu/~robby/lightweight-metatheory/">paper and presentation!</a>), I hacked up something similar in Haskell.  Naturally, it&#8217;s all manual, and there&#8217;s none of the publication or visualization support, but the essence is there.  Here&#8217;s the code for the untyped lambda calculus:</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4f2d1c73e2e50">
<div class="synthi_header" style="font-weight:bold;"> Haskell <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4f2d1c73e2e50').style.display='block';document.getElementById('plain_synthi_4f2d1c73e2e50').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
module Untyped where

import Control.Monad
import Data.Maybe
import Test.QuickCheck

data Expr =
    Var Int
  | Lambda Expr
  | App Expr Expr

showExpr :: Int -> Expr -> String
showExpr _b (Var n) = &#034;var&#034; ++ show n
showExpr b (Lambda e) = &#034;lambda. &#034; ++ showExpr (b+1) e
showExpr b (App e1 e2) = &#034;(&#034; ++ showExpr b e1 ++ &#034; &#034; ++ showExpr b e2 ++ &#034;)&#034;

instance Show Expr where
  show e = showExpr 0 e

size :: Expr -> Int
size (Var _) = 1
size (Lambda e) = 1 + size e
size (App e1 e2) = size e1 + size e2

wellLexed :: Expr -> Bool
wellLexed = wellLexedAux 0
  where wellLexedAux :: Int -> Expr -> Bool
        wellLexedAux b (Var n) = 0 <= n &#038;&#038; n < b
        wellLexedAux b (Lambda e) = wellLexedAux (b+1) e
        wellLexedAux b (App e1 e2) = wellLexedAux b e1 &#038;&#038; wellLexedAux b e2

arbitraryExpr :: Int -> Int -> Gen Expr
arbitraryExpr n 0 = oneof [return $ Lambda $ Var 0] -- base case
arbitraryExpr n max = do
  oneof $
    (if n < max
     then [arbitraryExpr (n+1) (max-1) >>= return . Lambda]
     else []) ++
    (if n > 0
     then [choose (0,n-1) >>= return . Var]
     else []) ++
    [do { e1 <- arbitraryExpr n (max `div` 2);
          e2 <- arbitraryExpr n (max `div` 2);
          return $ App e1 e2 }]

instance Arbitrary Expr where
  arbitrary = sized $ \max -> arbitraryExpr 0 max

-- All the terms we generate should be well-lexed
prop_WellLexed e = collect (size e) $ wellLexed e

subst :: Expr -> Int -> Expr -> Expr
subst e n (Var n')
  | n == n' = e
  | otherwise = (Var n')
subst e n (Lambda e') = Lambda $ subst e (n+1) e'
subst e n (App e1 e2) = App (subst e n e1) (subst e n e2)

shift :: Int -> Expr -> Expr
shift i (Var n) = if n < i then Var n else Var (n-1)
shift i (Lambda e) = Lambda $ shift (i+1) e
shift i (App e1 e2) = App (shift i e1) (shift i e2)

value :: Expr -> Bool
value (Lambda e) = True
value _ = False

-- we can run this with m = Maybe or m = List
step :: MonadPlus m => Expr -> m Expr
step (Var _) = mzero -- unbound variable
step (Lambda e) = mzero -- found a term
step (App e1@(Lambda e11) e2)
  | value e2 = return $ shift 0 $ subst e2 0 e11
  | otherwise = do
    e2' <- step e2
    return $ App e1 e2'
step (App e1 e2) = do
  e1' <- step e1
  return $ App e1' e2

-- if we can step, we'd better preserve scope
prop_StepWellLexed e = isJust next ==> wellLexed (fromJust next)
  where next = step e

-- verify progress
prop_Progress e = (classify isValue &#034;value&#034;) $ (classify (not isValue) &#034;step&#034;) $ value e || isJust (step e)
  where isValue = value e

-- use the List monad to ensure determinacy
prop_Deterministic e = nextStates > 0 ==> nextStates == 1
  where nextStates = length $ step e
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4f2d1c73e2e50">
<div class="synthi_header" style="font-weight:bold;"> Haskell <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4f2d1c73e2e50').style.display='block';document.getElementById('styled_synthi_4f2d1c73e2e50').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="haskell" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">module</span> Untyped <span style="color: #06c; font-weight: bold;">where</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">import</span> Control.<span style="color: #060;">Monad</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">import</span> <span style="color: #06c; font-weight: bold;">Data</span>.<span style="color: #060;">Maybe</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">import</span> Test.<span style="color: #060;">QuickCheck</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">data</span> Expr =</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Var Int</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | Lambda Expr</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | App Expr Expr</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">showExpr :: Int -&gt; Expr -&gt; String</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">showExpr _b <span style="color: #6c6;">&#40;</span>Var n<span style="color: #6c6;">&#41;</span> = <span style="color: #3cb371;">&quot;var&quot;</span> ++ show n</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">showExpr b <span style="color: #6c6;">&#40;</span>Lambda e<span style="color: #6c6;">&#41;</span> = <span style="color: #3cb371;">&quot;lambda. &quot;</span> ++ showExpr <span style="color: #6c6;">&#40;</span>b<span style="color: #c6c;">+1</span><span style="color: #6c6;">&#41;</span> e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">showExpr b <span style="color: #6c6;">&#40;</span>App e1 e2<span style="color: #6c6;">&#41;</span> = <span style="color: #3cb371;">&quot;(&quot;</span> ++ showExpr b e1 ++ <span style="color: #3cb371;">&quot; &quot;</span> ++ showExpr b e2 ++ <span style="color: #3cb371;">&quot;)&quot;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">instance</span> Show Expr <span style="color: #06c; font-weight: bold;">where</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; show e = showExpr <span style="color: #c6c;">0</span> e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">size :: Expr -&gt; Int</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">size <span style="color: #6c6;">&#40;</span>Var _<span style="color: #6c6;">&#41;</span> = <span style="color: #c6c;">1</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">size <span style="color: #6c6;">&#40;</span>Lambda e<span style="color: #6c6;">&#41;</span> = <span style="color: #c6c;">1</span> + size e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">size <span style="color: #6c6;">&#40;</span>App e1 e2<span style="color: #6c6;">&#41;</span> = size e1 + size e2</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">wellLexed :: Expr -&gt; Bool</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">wellLexed = wellLexedAux <span style="color: #c6c;">0</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #06c; font-weight: bold;">where</span> wellLexedAux :: Int -&gt; Expr -&gt; Bool</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; wellLexedAux b <span style="color: #6c6;">&#40;</span>Var n<span style="color: #6c6;">&#41;</span> = <span style="color: #c6c;">0</span> &lt;= n &amp;&amp; n &lt; b</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; wellLexedAux b <span style="color: #6c6;">&#40;</span>Lambda e<span style="color: #6c6;">&#41;</span> = wellLexedAux <span style="color: #6c6;">&#40;</span>b<span style="color: #c6c;">+1</span><span style="color: #6c6;">&#41;</span> e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; wellLexedAux b <span style="color: #6c6;">&#40;</span>App e1 e2<span style="color: #6c6;">&#41;</span> = wellLexedAux b e1 &amp;&amp; wellLexedAux b e2</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">arbitraryExpr :: Int -&gt; Int -&gt; Gen Expr</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">arbitraryExpr n <span style="color: #c6c;">0</span> = oneof <span style="color: #6c6;">&#91;</span><span style="color: #06c; font-weight: bold;">return</span> $ Lambda $ Var <span style="color: #c6c;">0</span><span style="color: #6c6;">&#93;</span> <span style="">&#8211; base case</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">arbitraryExpr n max = <span style="color: #06c; font-weight: bold;">do</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; oneof $ </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">if</span> n &lt; max </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">then</span> <span style="color: #6c6;">&#91;</span>arbitraryExpr <span style="color: #6c6;">&#40;</span>n<span style="color: #c6c;">+1</span><span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>max<span style="color: #c6c;">-1</span><span style="color: #6c6;">&#41;</span> &gt;&gt;= <span style="color: #06c; font-weight: bold;">return</span> . <span style="color: #060;">Lambda</span><span style="color: #6c6;">&#93;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">else</span> <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#93;</span><span style="color: #6c6;">&#41;</span> ++ </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">if</span> n &gt; <span style="color: #c6c;">0</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">then</span> <span style="color: #6c6;">&#91;</span>choose <span style="color: #6c6;">&#40;</span><span style="color: #c6c;">0</span>,n<span style="color: #c6c;">-1</span><span style="color: #6c6;">&#41;</span> &gt;&gt;= <span style="color: #06c; font-weight: bold;">return</span> . <span style="color: #060;">Var</span><span style="color: #6c6;">&#93;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">else</span> <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#93;</span><span style="color: #6c6;">&#41;</span> ++</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #6c6;">&#91;</span><span style="color: #06c; font-weight: bold;">do</span> <span style="color: #6c6;">&#123;</span> e1 &lt;- arbitraryExpr n <span style="color: #6c6;">&#40;</span>max `div` <span style="color: #c6c;">2</span><span style="color: #6c6;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e2 &lt;- arbitraryExpr n <span style="color: #6c6;">&#40;</span>max `div` <span style="color: #c6c;">2</span><span style="color: #6c6;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">return</span> $ App e1 e2 <span style="color: #6c6;">&#125;</span><span style="color: #6c6;">&#93;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">instance</span> Arbitrary Expr <span style="color: #06c; font-weight: bold;">where</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; arbitrary = sized $ \max -&gt; arbitraryExpr <span style="color: #c6c;">0</span> max</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">&#8211; All the terms we generate should be well-lexed</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">prop_WellLexed e = collect <span style="color: #6c6;">&#40;</span>size e<span style="color: #6c6;">&#41;</span> $ wellLexed e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">subst :: Expr -&gt; Int -&gt; Expr -&gt; Expr</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">subst e n <span style="color: #6c6;">&#40;</span>Var n&#8217;<span style="color: #6c6;">&#41;</span> </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | n == n&#8217; = e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | <span style="color: #06c; font-weight: bold;">otherwise</span> = <span style="color: #6c6;">&#40;</span>Var n&#8217;<span style="color: #6c6;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">subst e n <span style="color: #6c6;">&#40;</span>Lambda e&#8217;<span style="color: #6c6;">&#41;</span> = Lambda $ subst e <span style="color: #6c6;">&#40;</span>n<span style="color: #c6c;">+1</span><span style="color: #6c6;">&#41;</span> e&#8217;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">subst e n <span style="color: #6c6;">&#40;</span>App e1 e2<span style="color: #6c6;">&#41;</span> = App <span style="color: #6c6;">&#40;</span>subst e n e1<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>subst e n e2<span style="color: #6c6;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">shift :: Int -&gt; Expr -&gt; Expr</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">shift i <span style="color: #6c6;">&#40;</span>Var n<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">if</span> n &lt; i <span style="color: #06c; font-weight: bold;">then</span> Var n <span style="color: #06c; font-weight: bold;">else</span> Var <span style="color: #6c6;">&#40;</span>n<span style="color: #c6c;">-1</span><span style="color: #6c6;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">shift i <span style="color: #6c6;">&#40;</span>Lambda e<span style="color: #6c6;">&#41;</span> = Lambda $ shift <span style="color: #6c6;">&#40;</span>i<span style="color: #c6c;">+1</span><span style="color: #6c6;">&#41;</span> e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">shift i <span style="color: #6c6;">&#40;</span>App e1 e2<span style="color: #6c6;">&#41;</span> = App <span style="color: #6c6;">&#40;</span>shift i e1<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>shift i e2<span style="color: #6c6;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">value :: Expr -&gt; Bool</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">value <span style="color: #6c6;">&#40;</span>Lambda e<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">True</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">value _ = <span style="color: #06c; font-weight: bold;">False</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">&#8211; we can run this with m = Maybe or m = List</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">step :: MonadPlus m =&gt; Expr -&gt; m Expr</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">step <span style="color: #6c6;">&#40;</span>Var _<span style="color: #6c6;">&#41;</span> = mzero <span style="">&#8211; unbound variable</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">step <span style="color: #6c6;">&#40;</span>Lambda e<span style="color: #6c6;">&#41;</span> = mzero <span style="">&#8211; found a term</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">step <span style="color: #6c6;">&#40;</span>App e1@<span style="color: #6c6;">&#40;</span>Lambda e11<span style="color: #6c6;">&#41;</span> e2<span style="color: #6c6;">&#41;</span> </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | value e2 = <span style="color: #06c; font-weight: bold;">return</span> $ shift <span style="color: #c6c;">0</span> $ subst e2 <span style="color: #c6c;">0</span> e11</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | <span style="color: #06c; font-weight: bold;">otherwise</span> = <span style="color: #06c; font-weight: bold;">do</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; e2&#8242; &lt;- step e2</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">return</span> $ App e1 e2&#8242;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">step <span style="color: #6c6;">&#40;</span>App e1 e2<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">do</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; e1&#8242; &lt;- step e1</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #06c; font-weight: bold;">return</span> $ App e1&#8242; e2</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">&#8211; if we can step, we&#8217;d better preserve scope</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">prop_StepWellLexed e = isJust next ==&gt; wellLexed <span style="color: #6c6;">&#40;</span>fromJust next<span style="color: #6c6;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #06c; font-weight: bold;">where</span> next = step e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">&#8211; verify progress</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">prop_Progress e = <span style="color: #6c6;">&#40;</span>classify isValue <span style="color: #3cb371;">&quot;value&quot;</span><span style="color: #6c6;">&#41;</span> $ <span style="color: #6c6;">&#40;</span>classify <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">not</span> isValue<span style="color: #6c6;">&#41;</span> <span style="color: #3cb371;">&quot;step&quot;</span><span style="color: #6c6;">&#41;</span> $ value e || isJust <span style="color: #6c6;">&#40;</span>step e<span style="color: #6c6;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #06c; font-weight: bold;">where</span> isValue = value e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">&#8211; use the List monad to ensure determinacy</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">prop_Deterministic e = nextStates &gt; <span style="color: #c6c;">0</span> ==&gt; nextStates == <span style="color: #c6c;">1</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #06c; font-weight: bold;">where</span> nextStates = length $ step e </div>
</li>
</ol>
</div>
</div>
<p>One of the trickiest things here was making sure I was generating well lexed lambda terms that were small enough to be tractable.  It would have been even harder, I think, with a more explicit representation of variables or binding.  Thoughts, variations?  Or, perhaps, complaints that I should have done this with GADTS or in Coq?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2012/02/01/quickredex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPEnkoder 1.11</title>
		<link>http://www.weaselhat.com/2011/10/11/phpenkoder-1-11/</link>
		<comments>http://www.weaselhat.com/2011/10/11/phpenkoder-1-11/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 13:47:02 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=288</guid>
		<description><![CDATA[A change not due to NilsOla Nilsson broke PHPEnkoder 1.10 on mailto: links. But he caught this almost immediately and sent me a fix. PHPEnkoder 1.11 should work fine. Thanks, NilsOla! As usual, updates are available from the WordPress plugin directory or from your dashboard.]]></description>
			<content:encoded><![CDATA[<p>A change not due to <a href="http://www.femtrappor.se">NilsOla Nilsson</a> broke PHPEnkoder 1.10 on <tt>mailto:</tt> links.  But he caught this almost immediately and sent me a fix.  PHPEnkoder 1.11 should work fine.  Thanks, NilsOla!</p>
<p>As usual, updates are available from the <a href="http://wordpress.org/extend/plugins/php-enkoder/">WordPress plugin directory</a> or from your dashboard.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2011/10/11/phpenkoder-1-11/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHPEnkoder 1.10</title>
		<link>http://www.weaselhat.com/2011/10/05/phpenkoder-1-10/</link>
		<comments>http://www.weaselhat.com/2011/10/05/phpenkoder-1-10/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 15:48:48 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=281</guid>
		<description><![CDATA[NilsOla Nilsson pointed out a few changes I could make to the link-detection regexes that resolved a few issues with overzealous encoding. As usual, updates are available from the WordPress plugin directory&#8212;or, of course, automatically in your dashboard.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.femtrappor.se">NilsOla Nilsson</a> pointed out a few changes I could make to the link-detection regexes that resolved a few issues with overzealous encoding.</p>
<p>As usual, updates are available from the <a href="http://wordpress.org/extend/plugins/php-enkoder/">WordPress plugin directory</a>&#8212;or, of course, automatically in your dashboard.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2011/10/05/phpenkoder-1-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPEnkoder 1.9</title>
		<link>http://www.weaselhat.com/2011/03/15/phpenkoder-1-9/</link>
		<comments>http://www.weaselhat.com/2011/03/15/phpenkoder-1-9/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 20:16:49 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=263</guid>
		<description><![CDATA[Per a bug report from Kim Carr at WebShoppingSystems.com, PHPEnkoder now correctly supports whitespace&#8212;this bug was most noticeable in email hidden; JavaScript is required shortcodes. Updates are available from the WordPress plugin directory&#8212;or straight from your dashboard. (We&#8217;ve come quite a way from 2.3, haven&#8217;t we!)]]></description>
			<content:encoded><![CDATA[<p>Per a bug report from <a href="http://webshoppingsystems.com">Kim Carr at WebShoppingSystems.com</a>, PHPEnkoder now correctly supports whitespace&#8212;this bug was most noticeable in <tt>[enkode]</tt> shortcodes.</p>
<p>Updates are available from the <a href="http://wordpress.org/extend/plugins/php-enkoder/">WordPress plugin directory</a>&#8212;or straight from your dashboard.  (We&#8217;ve come quite a way from 2.3, haven&#8217;t we!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2011/03/15/phpenkoder-1-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPEnkoder 1.8</title>
		<link>http://www.weaselhat.com/2011/02/21/phpenkoder-1-8/</link>
		<comments>http://www.weaselhat.com/2011/02/21/phpenkoder-1-8/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 02:05:18 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=253</guid>
		<description><![CDATA[Per Tom&#8217;s report, version 1.8 fixes a few minor bugs. If PHPEnkoder is working for you, there&#8217;s no pressing need to upgrade. Updates from now on will only be available from the WordPress plugin directory.]]></description>
			<content:encoded><![CDATA[<p>Per <a href="http://wordpress.org/support/topic/phpenkoder-errors-with-debugging-on#post-1952375">Tom&#8217;s report</a>, version 1.8 fixes a few minor bugs.  If PHPEnkoder is working for you, there&#8217;s no pressing need to upgrade.</p>
<p>Updates from now on will only be available from <a href="http://wordpress.org/extend/plugins/php-enkoder/">the WordPress plugin directory</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2011/02/21/phpenkoder-1-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPEnkoder 1.7</title>
		<link>http://www.weaselhat.com/2010/05/03/phpenkoder-1-7/</link>
		<comments>http://www.weaselhat.com/2010/05/03/phpenkoder-1-7/#comments</comments>
		<pubDate>Mon, 03 May 2010 18:49:14 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=220</guid>
		<description><![CDATA[By Julius Welby&#8217;s request, there is now an option to set a class attribute on the a tags generated for mailto: links. If you leave this option empty (the default), then no class attribute will be set. The latest version is available from the PHPEnkoder website and its home in the plugin directory.]]></description>
			<content:encoded><![CDATA[<p>By Julius Welby&#8217;s request, there is now an option to set a class attribute on the <tt>a</tt> tags generated for <tt>mailto:</tt> links.  If you leave this option empty (the default), then no class attribute will be set.</p>
<p>The latest version is available from the <a href="http://www.weaselhat.com/phpenkoder/">PHPEnkoder website</a> and <a href="http://wordpress.org/extend/plugins/php-enkoder/">its home in the plugin directory</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2010/05/03/phpenkoder-1-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nested functions in GCC</title>
		<link>http://www.weaselhat.com/2010/03/03/nested-functions-in-gcc/</link>
		<comments>http://www.weaselhat.com/2010/03/03/nested-functions-in-gcc/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 16:06:40 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=208</guid>
		<description><![CDATA[GCC supports &#8220;nested functions&#8221; using the -fnested-functions flag. When I first saw this, I was excited: closures in C! In the famous words of Admiral Ackbar, &#8220;it&#8217;s a trap!&#8221; C [Show Styled Code]: #include typedef int (*fptr)(int); fptr f(int arg) { int nested_function(int nested_arg) { return arg + nested_arg; } return &#038;nested_function; } void smash(int [...]]]></description>
			<content:encoded><![CDATA[<p>GCC supports &#8220;nested functions&#8221; using the <tt>-fnested-functions</tt> flag.  When I first saw this, I was excited: closures in C!  In the famous words of Admiral Ackbar, &#8220;it&#8217;s a trap!&#8221;</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4f2d1c741a328">
<div class="synthi_header" style="font-weight:bold;"> C <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4f2d1c741a328').style.display='block';document.getElementById('plain_synthi_4f2d1c741a328').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
#include <stdio.h>

typedef int (*fptr)(int);

fptr f(int arg) {
  int nested_function(int nested_arg) {
    return arg + nested_arg;
  }

  return &#038;nested_function;
}

void smash(int arg) {
  return;
}

int main(void) {
  fptr g = f(10);
  printf(&#034;%d\n&#034;, (*g)(5));
  smash(12);
  // printf(&#034;%d\n&#034;, (*g)(5));
  fptr h = f(12);
  printf(&#034;%d\n&#034;, (*g)(5));
  printf(&#034;%d\n&#034;, (*h)(5));

  return 0;
}
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4f2d1c741a328">
<div class="synthi_header" style="font-weight:bold;"> C <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4f2d1c741a328').style.display='block';document.getElementById('styled_synthi_4f2d1c741a328').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="c" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">typedef</span> <span style="color: #993333;">int</span> <span style="color: #66cc66;">&#40;</span>*fptr<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">fptr f<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> arg<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #993333;">int</span> nested_function<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> nested_arg<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">return</span> arg + nested_arg;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #b1b100;">return</span> &amp;nested_function;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">void</span> smash<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> arg<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #b1b100;">return</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">int</span> main<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; fptr g = f<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, <span style="color: #66cc66;">&#40;</span>*g<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; smash<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #808080; font-style: italic;">// printf(&quot;%d\n&quot;, (*g)(5));</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; fptr h = f<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, <span style="color: #66cc66;">&#40;</span>*g<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, <span style="color: #66cc66;">&#40;</span>*h<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
<p>Try compiling (<tt>gcc -fnested-functions</tt>).  What does the second call to <tt>g</tt> produce&#8212;15 or 17?  Try uncommenting line 21.  What happens?  Does commenting out line 20 affect this?  What if line 19 is commented out, but lines 20 and 21 are uncommented?</p>
<p>I&#8217;m not sure this feature is worth it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2010/03/03/nested-functions-in-gcc/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Locally installing LLVM with Ocaml bindings</title>
		<link>http://www.weaselhat.com/2009/09/24/llvm-ocaml-loca/</link>
		<comments>http://www.weaselhat.com/2009/09/24/llvm-ocaml-loca/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 19:44:31 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=145</guid>
		<description><![CDATA[We can&#8217;t install software into the /usr tree at my office, so I end up having local installs of lots of software. Some things, like GODI, play well with this. I had some trouble finding the right way to get LLVM&#8216;s Ocaml bindings to work, so I figured I&#8217;d share the wealth. The following instructions [...]]]></description>
			<content:encoded><![CDATA[<p>We can&#8217;t install software into the /usr tree at my office, so I end up having local installs of lots of software.  Some things, like <a href="http://godi.camlcity.org/godi/index.html">GODI</a>, play well with this.  I had some trouble finding the right way to get <a href="http://llvm.org">LLVM</a>&#8216;s Ocaml bindings to work, so I figured I&#8217;d share the wealth.  The following instructions will put an install into the directory <tt>$PREFIX/llvm-install</tt>.</p>
<p>Here are the steps; they&#8217;re followed by a plain English explanation.</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4f2d1c743a6a2">
<div class="synthi_header" style="font-weight:bold;"> Bash <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4f2d1c743a6a2').style.display='block';document.getElementById('plain_synthi_4f2d1c743a6a2').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
cd $PREFIX
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
wget http://llvm.org/releases/2.5/llvm-gcc4.2-2.5-x86-linux-RHEL4.tar.gz
tar xzf llvm-gcc4.2-2.5-x86-linux-RHEL4.tar.gz
mkdir llvm-objects llvm-install
cd llvm-objects
../llvm/configure --with-llvmgccdir=$PREFIX/llvm-gcc4.2-2.5-x86-linux-RHEL4 --enable-optimized --enable-jit --prefix=$PREFIX/llvm-install --with-ocaml-libdir=$GODI_PATH/lib/ocaml/std-lib
make
make install
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4f2d1c743a6a2">
<div class="synthi_header" style="font-weight:bold;"> Bash <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4f2d1c743a6a2').style.display='block';document.getElementById('styled_synthi_4f2d1c743a6a2').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="bash" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066;">cd</span> <span style="color: #0000ff;">$PREFIX</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">wget http://llvm.org/releases/<span style="color: #cc66cc;">2.5</span>/llvm-gcc4<span style="color: #cc66cc;">.2</span><span style="color: #cc66cc;">-2.5</span>-x86-linux-RHEL4.tar.gz</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">tar xzf llvm-gcc4<span style="color: #cc66cc;">.2</span><span style="color: #cc66cc;">-2.5</span>-x86-linux-RHEL4.tar.gz</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mkdir llvm-objects llvm-install</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066;">cd</span> llvm-objects</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">../llvm/configure &#8211;with-<span style="color: #0000ff;">llvmgccdir=</span><span style="color: #0000ff;">$PREFIX</span>/llvm-gcc4<span style="color: #cc66cc;">.2</span><span style="color: #cc66cc;">-2.5</span>-x86-linux-RHEL4 &#8211;enable-optimized &#8211;enable-jit &#8211;<span style="color: #0000ff;">prefix=</span><span style="color: #0000ff;">$PREFIX</span>/llvm-install &#8211;with-ocaml-<span style="color: #0000ff;">libdir=</span><span style="color: #0000ff;">$GODI_PATH</span>/lib/ocaml/std-lib</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">make</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">make install </div>
</li>
</ol>
</div>
</div>
<p>My <tt>PREFIX</tt> is my home directory, and <tt>GODI_PATH = ~/godi</tt>.  First, we checkout the latest LLVM from SVN (step 2).  Then we download and extract the <a href="http://llvm.org/releases/download.html#2.5">latest release (2.5, as of writing) of LLVM-gcc</a> (steps 3 and 4).  (I couldn&#8217;t get the SVN version of LLVM-gcc to work with the SVN version of LLVM.)  Notably, LLVM does <i>not</i> support in-place builds, so we create the <tt>llvm-objects</tt> directory to actually build LLVM; we&#8217;ll install it into <tt>llvm-install</tt> (step 5).  We configure the software <i>from the <tt>llvm-objects</tt> directory</i> (steps 6 and 7).  The long configure is necessary; the only optional item is <tt>--enable-jit</tt>.  You may have to adjust your <tt>--with-ocaml-libdir</tt> to point to wherever your Ocaml libraries live.  Then make and make install (steps 8 and 9).  Voila!</p>
<p>To test it out, we can use the &#8220;Hello, World!&#8221; program written by <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/010996.html">Gordon Henrikson</a>.  I had to change it a little to bring it up to date with the latest APIs (in particular, the global context had to be added).  You can download it as <a href="downloads/llvm_test.ml"><tt>llvm_test.ml</tt></a>.</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4f2d1c743d582">
<div class="synthi_header" style="font-weight:bold;"> OCaml <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4f2d1c743d582').style.display='block';document.getElementById('plain_synthi_4f2d1c743d582').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
open Printf
open Llvm

let main filename =
   let c = create_context () in

   let i8_t  = i8_type c in
   let i32_t = i32_type c in

   let m = create_module c filename in

   (* @greeting = global [14 x i8] c&#034;Hello, world!\00&#034; *)
   let greeting =
     define_global &#034;greeting&#034; (const_string c &#034;Hello, world!\000&#034;) m in

   (* declare i32 @puts(i8* ) *)
   let puts =
     declare_function &#034;puts&#034;
       (function_type i32_t [|pointer_type i8_t|]) m in

   (* define i32 @main() { entry: *)
   let main = define_function &#034;main&#034; (function_type i32_t [| |]) m in
   let at_entry = builder_at_end c (entry_block main) in

   (* %tmp = getelementptr [14 x i8]* @greeting, i32 0, i32 0 *)
   let zero = const_int i32_t 0 in
   let str = build_gep greeting [| zero; zero |] &#034;tmp&#034; at_entry in

   (* call i32 @puts( i8* %tmp ) *)
   ignore (build_call puts [| str |] &#034;&#034; at_entry);

   (* ret void *)
   ignore (build_ret (const_null i32_t) at_entry);

   (* write the module to a file *)
   if not (Llvm_bitwriter.write_bitcode_file m filename) then exit 1;
   dispose_module m

let () = match Sys.argv with
  | [|_; filename|] -> main filename
  | _ -> main &#034;a.out&#034;
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4f2d1c743d582">
<div class="synthi_header" style="font-weight:bold;"> OCaml <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4f2d1c743d582').style.display='block';document.getElementById('styled_synthi_4f2d1c743d582').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="ocaml" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">open</span> <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html"><span style="">Printf</span></a></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">open</span> Llvm</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">let</span> main filename =</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">let</span> c = create_context <span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">in</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">let</span> i8_t&nbsp; = i8_type c <span style="color: #06c; font-weight: bold;">in</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">let</span> i32_t = i32_type c <span style="color: #06c; font-weight: bold;">in</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">let</span> m = create_module c filename <span style="color: #06c; font-weight: bold;">in</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">(* @greeting = global [14 x i8] c&quot;Hello, world!\00&quot; *)</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">let</span> greeting =</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;define_global <span style="color: #3cb371;">&quot;greeting&quot;</span> <span style="color: #6c6;">&#40;</span>const_string c <span style="color: #3cb371;">&quot;Hello, world!\000&quot;</span><span style="color: #6c6;">&#41;</span> m <span style="color: #06c; font-weight: bold;">in</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">(* declare i32 @puts(i8* ) *)</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">let</span> puts =</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;declare_function <span style="color: #3cb371;">&quot;puts&quot;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #6c6;">&#40;</span>function_type i32_t <span style="color: #6c6;">&#91;</span>|pointer_type i8_t|<span style="color: #6c6;">&#93;</span><span style="color: #6c6;">&#41;</span> m <span style="color: #06c; font-weight: bold;">in</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">(* define i32 @main() { entry: *)</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">let</span> main = define_function <span style="color: #3cb371;">&quot;main&quot;</span> <span style="color: #6c6;">&#40;</span>function_type i32_t <span style="color: #6c6;">&#91;</span>| |<span style="color: #6c6;">&#93;</span><span style="color: #6c6;">&#41;</span> m <span style="color: #06c; font-weight: bold;">in</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">let</span> at_entry = builder_at_end c <span style="color: #6c6;">&#40;</span>entry_block main<span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">in</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">(* %tmp = getelementptr [14 x i8]* @greeting, i32 0, i32 0 *)</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">let</span> zero = const_int i32_t <span style="color: #c6c;">0</span> <span style="color: #06c; font-weight: bold;">in</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">let</span> str = build_gep greeting <span style="color: #6c6;">&#91;</span>| zero; zero |<span style="color: #6c6;">&#93;</span> <span style="color: #3cb371;">&quot;tmp&quot;</span> at_entry <span style="color: #06c; font-weight: bold;">in</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">(* call i32 @puts( i8* %tmp ) *)</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALignore"><span style="">ignore</span></a> <span style="color: #6c6;">&#40;</span>build_call puts <span style="color: #6c6;">&#91;</span>| str |<span style="color: #6c6;">&#93;</span> <span style="color: #3cb371;">&quot;&quot;</span> at_entry<span style="color: #6c6;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">(* ret void *)</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALignore"><span style="">ignore</span></a> <span style="color: #6c6;">&#40;</span>build_ret <span style="color: #6c6;">&#40;</span>const_null i32_t<span style="color: #6c6;">&#41;</span> at_entry<span style="color: #6c6;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">(* write the module to a file *)</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">if</span> <span style="color: #06c; font-weight: bold;">not</span> <span style="color: #6c6;">&#40;</span>Llvm_bitwriter.<span style="color: #060;">write_bitcode_file</span> m filename<span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span> <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALexit"><span style="">exit</span></a> <span style="color: #c6c;">1</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;dispose_module m</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">let</span> <span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">match</span> <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Sys.html"><span style="">Sys</span></a>.<span style="color: #060;">argv</span> <span style="color: #06c; font-weight: bold;">with</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | <span style="color: #6c6;">&#91;</span>|_; filename|<span style="color: #6c6;">&#93;</span> -&gt; main filename</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | _ -&gt; main <span style="color: #3cb371;">&quot;a.out&quot;</span> </div>
</li>
</ol>
</div>
</div>
<p>Now we can compile:</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4f2d1c74442e8">
<div class="synthi_header" style="font-weight:bold;"> Bash <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4f2d1c74442e8').style.display='block';document.getElementById('plain_synthi_4f2d1c74442e8').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
ocamlopt -cc g++ llvm.cmxa llvm_bitwriter.cmxa llvm_test.ml -o llvm_test
./llvm_test hello.bc # generates bitcode
$PREFIX/llvm-install/bin/llvm-dis hello.bc # disassembles bitcode into hello.ll
$PREFIX/llvm-install/bin/lli hello.bc # outputs &#034;Hello, world!&#034;
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4f2d1c74442e8">
<div class="synthi_header" style="font-weight:bold;"> Bash <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4f2d1c74442e8').style.display='block';document.getElementById('styled_synthi_4f2d1c74442e8').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="bash" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ocamlopt -cc g++ llvm.cmxa llvm_bitwriter.cmxa llvm_test.ml -o llvm_test</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">./llvm_test hello.bc <span style="color: #808080; font-style: italic;"># generates bitcode</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$PREFIX</span>/llvm-install/bin/llvm-dis hello.bc <span style="color: #808080; font-style: italic;"># disassembles bitcode into hello.ll</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$PREFIX</span>/llvm-install/bin/lli hello.bc <span style="color: #808080; font-style: italic;"># outputs &quot;Hello, world!&quot; </span></div>
</li>
</ol>
</div>
</div>
<p>If interpretation via <tt>lli</tt> isn&#8217;t your bag, you can also compile to native code:</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4f2d1c7446226">
<div class="synthi_header" style="font-weight:bold;"> Bash <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4f2d1c7446226').style.display='block';document.getElementById('plain_synthi_4f2d1c7446226').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
$PREFIX/llvm-install/bin/llc hello.bc # generates assembly, hello.s
gcc -o hello hello.s
./hello # outputs &#034;Hello, world!&#034;
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4f2d1c7446226">
<div class="synthi_header" style="font-weight:bold;"> Bash <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4f2d1c7446226').style.display='block';document.getElementById('styled_synthi_4f2d1c7446226').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="bash" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$PREFIX</span>/llvm-install/bin/llc hello.bc <span style="color: #808080; font-style: italic;"># generates assembly, hello.s</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">gcc -o hello hello.s</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">./hello <span style="color: #808080; font-style: italic;"># outputs &quot;Hello, world!&quot; </span></div>
</li>
</ol>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2009/09/24/llvm-ocaml-loca/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHPEnkoder 1.6</title>
		<link>http://www.weaselhat.com/2009/08/18/phpenkoder-1-6/</link>
		<comments>http://www.weaselhat.com/2009/08/18/phpenkoder-1-6/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 21:11:41 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=135</guid>
		<description><![CDATA[Martin Rees caught another bug in PHPEnkoder, which was making it difficult to edit posts with comments containing e-mails. This problem has been solved by turning off the enkoder filters when displaying administrative panels. In addition to the bugfix, there are two improvements. First, the internal enkoding system will choose names that are more likely [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.strangelyperfect.tv/">Martin Rees</a> caught another bug in PHPEnkoder, which was making it difficult to edit posts with comments containing e-mails.  This problem has been solved by turning off the enkoder filters when displaying administrative panels.</p>
<p>In addition to the bugfix, there are two improvements.  First, the internal enkoding system will choose names that are more likely to be unique.  Second, I&#8217;ve added a <a href="http://codex.wordpress.org/Shortcode_API">shortcode</a>, <tt>enkode</tt>.  You can use it to manually enkode an arbitrary stretch of text, like so: <tt>&#91;enkode]this will be enkoded&#91;/enkode]</tt>.</p>
<p>The latest version is available from the <a href="http://www.weaselhat.com/phpenkoder/">PHPEnkoder website</a> and <a href="http://wordpress.org/extend/plugins/php-enkoder/">its home in the plugin directory</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2009/08/18/phpenkoder-1-6/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Flapjax: A Programming Language for Ajax Applications</title>
		<link>http://www.weaselhat.com/2009/08/13/flapjax-2/</link>
		<comments>http://www.weaselhat.com/2009/08/13/flapjax-2/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 16:00:29 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Flapjax]]></category>
		<category><![CDATA[Papers]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=122</guid>
		<description><![CDATA[I am immensely pleased to report that our paper on Flapjax was accepted to OOPSLA 2009. This paper presents Flapjax, a language designed for contemporary Web applications. These applications communicate with servers and have rich, interactive interfaces. Flapjax provides two key features that simplify writing these applications. First, it provides event streams, a uniform abstraction [...]]]></description>
			<content:encoded><![CDATA[<p>I am immensely pleased to report that <a href="http://www.cis.upenn.edu/~mgree/papers/oopsla2009_flapjax.pdf">our paper on Flapjax</a> was accepted to <a href="http://www.oopsla.org/oopsla2009/" title="My favorite conference name to say, perhaps my least favorite to type.  OOPSPLA, every time.">OOPSLA 2009</a>.</p>
<blockquote><p>
This paper presents Flapjax, a language designed for contemporary Web applications. These applications communicate with servers and have rich, interactive interfaces. Flapjax provides two key features that simplify writing these applications. First, it provides event streams, a uniform abstraction for communication within a program as well as with external Web services. Second, the language itself is reactive: it automatically tracks data dependencies and propagates updates along those data?ows. This allows developers to write reactive interfaces in a declarative and compositional style.</p>
<p>Flapjax is built on top of JavaScript. It runs on unmodi?ed browsers and readily interoperates with existing JavaScript code. It is usable as either a programming language (that is compiled to JavaScript) or as a JavaScript library, and is designed for both uses. This paper presents the language, its design decisions, and illustrative examples drawn from several working Flapjax applications.
</p></blockquote>
<p>The real heroes of this story are my co-authors.  Leo, Arjun, and Greg were there for the initial, heroic-effort-based implementation.  Jacob and Aleks wrote incredible applications with our dog food.  Shriram, of course, saw the whole thing through.  Very few of my contributions remain: the original compiler is gone (thank goodness); my <a href="http://www.cis.upenn.edu/~mgree/papers/ugrad_thesis.pdf">thesis work</a> is discussed briefly in <i>How many DOMs?</i> on page 15.  Here&#8217;s to a great team and a great experience (and a great language)!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2009/08/13/flapjax-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

