<?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>Subvert the dominant paradigm</title>
	<atom:link href="http://subvert-the-dominant-paradigm.net/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://subvert-the-dominant-paradigm.net/blog</link>
	<description></description>
	<lastBuildDate>Mon, 09 Aug 2010 15:19:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Climbing trees</title>
		<link>http://subvert-the-dominant-paradigm.net/blog/?p=86</link>
		<comments>http://subvert-the-dominant-paradigm.net/blog/?p=86#comments</comments>
		<pubDate>Mon, 09 Aug 2010 15:18:07 +0000</pubDate>
		<dc:creator>jewel</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://subvert-the-dominant-paradigm.net/blog/?p=86</guid>
		<description><![CDATA[Here is a solution to an ACM programming problem requiring one to analyse trees describing parental relationships.
I wrote this in Maude even though the classic tool for this kind of problem is Prolog.
The solution
The output
We start by importing integers and quoted identifiers (symbols):

mod CLIMBING is
    protecting INT .
    protecting [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a solution to an <a href="http://acm.uva.es/p/v1/115.html">ACM programming problem requiring one to analyse trees describing parental relationships</a>.</p>
<p>I wrote this in Maude even though the classic tool for this kind of problem is Prolog.</p>
<p><a href="http://subvert-the-dominant-paradigm.net/~jewel/blog_images/2010/climbing.maude">The solution</a><br />
<a href="http://subvert-the-dominant-paradigm.net/~jewel/blog_images/2010/climbing_output.txt">The output</a></p>
<p>We start by importing integers and quoted identifiers (symbols):<br />
<code><br />
mod CLIMBING is<br />
    protecting INT .<br />
    protecting QID .<br />
</code></p>
<p>Next we define the sorts used in the program. Rel means any kind of relationship, NamePair is a just pair of names. The sorts Parent, Sibling and Cousing are all relationship types.</p>
<p><code><br />
        sort Rel .</p>
<p>        sorts NamePair .<br />
        sorts Parent Sibling Cousin RelType .<br />
        subsorts Parent Sibling Cousin < RelType .<br />
</code></p>
<p>The following operators (or constructors) are used to construct various relationship facts.</p>
<p><code><br />
      op Parent : Nat -> Parent .<br />
        op Cousin : Nat Nat -> Cousin .<br />
        op Sibling : -> Sibling .</p>
<p>        op pair : Qid Qid -> NamePair .<br />
        op rel : NamePair RelType -> Rel .<br />
        op parent : Qid Qid -> Rel .</p>
<p>        op Empty : -> Rel [ ctor ] .<br />
        op __ : Rel Rel -> Rel [ ctor assoc comm id: Empty ] .</p>
<p></code></p>
<p>The problem set is initialized with the following set of parent-child facts</p>
<p><code>       op init : -> Rel .<br />
        eq init =<br />
parent('alonzo.church, 'oswald.veblen)<br />
parent('stephen.kleene, 'alonzo.church)<br />
parent('dana.scott, 'alonzo.church)<br />
parent('martin.davis, 'alonzo.church)<br />
parent('pat.fischer, 'hartley.rogers)<br />
parent('mike.paterson, 'david.park)<br />
parent('dennis.ritchie, 'pat.fischer)<br />
parent('hartley.rogers, 'alonzo.church)<br />
parent('les.valiant, 'mike.paterson)<br />
parent('bob.constable, 'stephen.kleene)<br />
parent('david.park, 'hartley.rogers) .<br />
</code></p>
<p>We use the following variables to name various objects in our rules:</p>
<p><code><br />
      vars A B : Qid .<br />
        vars X Y Z : Qid .</p>
<p>        vars N M O P : Nat .<br />
        vars R : RelType .<br />
        vars REST : Rel .<br />
</code></p>
<p>These four rules describe the different relationship types:</p>
<p><code><br />
---- Note that the input is in (child, parent) format, but we want to output (parent, child)</p>
<p>        rl [ parent ] : parent(A, B) => rel( pair(B, A), Parent(0)) .</p>
<p>        rl [ grandparent ] :<br />
                         rel( pair(X, Y), Parent(0))<br />
                         rel( pair(Y, Z), Parent(N)) => rel( pair(X, Z), Parent(N + 1)) .</p>
<p>---- sibling is reflexive</p>
<p>        rl [ sibling ] :<br />
                         rel( pair(X, Y), Parent(0))<br />
                         rel( pair(X, Z), Parent(0)) => rel( pair(Y, Z), Sibling) rel( pair(Z, Y), Sibling) .</p>
<p>---- check least ancestor<br />
        rl [ cousin ] :<br />
                         rel( pair(X, Y), Parent(N))<br />
                         rel( pair(X, Z), Parent(M)) => rel( pair(Y, Z), Cousin(min(N,M), abs(N - M))) .<br />
endm<br />
</code></p>
<p>These search expressions describe the input queries (we could make an effort to parse these properly instead)</p>
<p><code><br />
search [1] in CLIMBING : init =>+ rel (pair ('stephen.kleene, 'bob.constable), R) REST .<br />
search [1] in CLIMBING : init =>+ rel (pair ('hartley.rogers, 'stephen.kleene), R) REST .</p>
<p>----- search [1] in CLIMBING : init =>+ rel (pair ('les.valiant, 'alonzo.church), R) REST .<br />
----- swap this query to search for father instead of child</p>
<p>search [1] in CLIMBING : init =>+ rel (pair ('alonzo.church, 'les.valiant), R) REST .</p>
<p>search [1] in CLIMBING : init =>+ rel (pair ('les.valiant, 'dennis.ritchie), R) REST .<br />
search [1] in CLIMBING : init =>+ rel (pair ('dennis.ritchie, 'les.valiant), R) REST .<br />
search [1] in CLIMBING : init =>+ rel (pair ('pat.fischer, 'michael.rabin), R) REST .</p>
<p>quit</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://subvert-the-dominant-paradigm.net/blog/?feed=rss2&amp;p=86</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loop macros</title>
		<link>http://subvert-the-dominant-paradigm.net/blog/?p=83</link>
		<comments>http://subvert-the-dominant-paradigm.net/blog/?p=83#comments</comments>
		<pubDate>Fri, 04 Jun 2010 14:39:32 +0000</pubDate>
		<dc:creator>jewel</dc:creator>
				<category><![CDATA[Church]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[State]]></category>

		<guid isPermaLink="false">http://subvert-the-dominant-paradigm.net/blog/?p=83</guid>
		<description><![CDATA[I have released the latest version of Church-State here:
http://subvert-the-dominant-paradigm.net/~jewel/church/church-alpha-4.tar.gz
You can also get the source code via mercurial:
hg clone http://subvert-the-dominant-paradigm.net/repos/bootstrap
or browse it.
In the previous version of Church loop constructs were expanded in the Church compiler directly to the State &#8220;tagbody&#8221; form. I have removed this code and implemented it as a Church macro which expands to [...]]]></description>
			<content:encoded><![CDATA[<p>I have released the latest version of Church-State here:<br />
<a href="http://subvert-the-dominant-paradigm.net/~jewel/church/church-alpha-4.tar.gz">http://subvert-the-dominant-paradigm.net/~jewel/church/church-alpha-4.tar.gz</a></p>
<p>You can also get the source code via mercurial:</p>
<p><code>hg clone http://subvert-the-dominant-paradigm.net/repos/bootstrap</code></p>
<p>or <a href="http://subvert-the-dominant-paradigm.net/repos/hgwebdir.cgi/bootstrap/">browse it</a>.</p>
<p>In the previous version of Church loop constructs were expanded in the Church compiler directly to the State &#8220;tagbody&#8221; form. I have removed this code and implemented it as a Church macro which expands to a new Church &#8220;tagbody&#8221; form.</p>
<p>The aim behind this is to make it easier to do optimization and flow analysis on Church code in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://subvert-the-dominant-paradigm.net/blog/?feed=rss2&amp;p=83</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>User extensible parsing</title>
		<link>http://subvert-the-dominant-paradigm.net/blog/?p=80</link>
		<comments>http://subvert-the-dominant-paradigm.net/blog/?p=80#comments</comments>
		<pubDate>Mon, 29 Mar 2010 14:13:19 +0000</pubDate>
		<dc:creator>jewel</dc:creator>
				<category><![CDATA[Church]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://subvert-the-dominant-paradigm.net/blog/?p=80</guid>
		<description><![CDATA[I have been experimenting with user-extensible parsers in Church, even though I don&#8217;t have a use for them yet.
I added a new language construct called &#8220;extend-grammar&#8221;, ie:


extend-grammar ometa testg {
test-rule = "test" ws+ cname:a -> >
}


This test-rule will match the string &#8220;test&#8221;, followed by a name. The rule will ignore its input and return the [...]]]></description>
			<content:encoded><![CDATA[<p>I have been experimenting with user-extensible parsers in Church, even though I don&#8217;t have a use for them yet.</p>
<p>I added a new language construct called &#8220;extend-grammar&#8221;, ie:</p>
<pre>
<code>
extend-grammar ometa testg {
test-rule = "test" ws+ cname:a -> << 42 >>
}
</code>
</pre>
<p>This test-rule will match the string &#8220;test&#8221;, followed by a name. The rule will ignore its input and return the value 42.</p>
<p>This grammar is processed during parse time, converted to church code and dynamically compiled and linked into the running process.</p>
<p>At present this happens after the whole file is parsed, so it&#8217;s currently not possible to add a new grammar rule and use it in the same source file.</p>
<p>To activate the rule I added another construct, &#8220;eval-when&#8221;, ie:</p>
<pre>
<code>
eval-when compile load
      church-add-parser-extension 'test-rule
</code>                                                                                    </pre>
<p>What this does is to execute this code when this file is compiled (load doesn&#8217;t work yet).</p>
<p>In this example we add &#8216;test-rule to the list of ometa functions to be called by a special new grammar rule called &#8216;user-form.</p>
<p>The new version of &#8216;user-form is compiled and linked into the process, immediately making it available to the parser.</p>
<p>For this test case I then load the following file:</p>
<pre>
<code>
dotest
        print "in dotest"
        print (test notanumber)
</code>
</pre>
<p>which prints 42 because the parser has intercepted what would normally be a method call.</p>
]]></content:encoded>
			<wfw:commentRss>http://subvert-the-dominant-paradigm.net/blog/?feed=rss2&amp;p=80</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rude repl</title>
		<link>http://subvert-the-dominant-paradigm.net/blog/?p=74</link>
		<comments>http://subvert-the-dominant-paradigm.net/blog/?p=74#comments</comments>
		<pubDate>Sun, 14 Mar 2010 10:52:25 +0000</pubDate>
		<dc:creator>jewel</dc:creator>
				<category><![CDATA[Church]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[State]]></category>

		<guid isPermaLink="false">http://subvert-the-dominant-paradigm.net/blog/?p=74</guid>
		<description><![CDATA[I have added eval and a repl (read eval print loop) to Church.


> + 3 4
7
> length "foobar"
6
> eval "* 19 3"
57
> load "church/test/hello.church"
true
> (main)
"hello"
true


Up to now I have only been using Church as a command-line compiler which produces executable files. Yet I have always preferred interactive language environments (lisp, smalltalk, python etc) to  [...]]]></description>
			<content:encoded><![CDATA[<p>I have added <strong>eval</strong> and a <strong>repl</strong> (read eval print loop) to Church.</p>
<p><code></p>
<pre>
> + 3 4
7
> length "foobar"
6
> eval "* 19 3"
57
> load "church/test/hello.church"
true
> (main)
"hello"
true
</pre>
<p></code></p>
<p>Up to now I have only been using Church as a command-line compiler which produces executable files. Yet I have always preferred interactive language environments (lisp, smalltalk, python etc) to  stop-compile-run languages.</p>
<p>All the machinery for writing a repl has been in Church for a while, including</p>
<ul>
<li>Church parser available as a library</li>
<li>Church compiler available at runtime</li>
<li>Machine code generator and dynamic linker available at runtime</li>
<li>The ability to modify the dispatch table at runtime</li>
</ul>
<p>This makes the repl easy to implement:</p>
<p><code></p>
<pre>
repl
        loop
                do
                        rstr = (read-line)
                        if (null? rstr)
                                return-from repl nil
                        else
                                print (eval rstr)
</pre>
<p></code></p>
<p>Eval is a little bit more messy because the compiler is designed to compile a whole method at a time and doesn&#8217;t know what to do with  variables that are not either a global or local variable.</p>
<p>To implement eval I wrapped the eval string in a lambda that I return from a method which gets run after compilation.</p>
<p><code></p>
<pre>
set-eval-compiled-function
   eval-compiled-function = (fn -- eval_str)
</pre>
<p></code></p>
<p>This works for certain language expressions, but does not presently provide the ability to assign to &#8220;repl&#8221; variables.</p>
<p>Another drawback is that multiline statements are currently not possible (unlike python and lisp).</p>
<p>In the future I hope to experiment with a <a href="http://common-lisp.net/project/slime/">SLIME</a>-like extension to emacs which communicates to Church across a socket, allowing interactive evaluation and compilation of source code from within the editor.</p>
]]></content:encoded>
			<wfw:commentRss>http://subvert-the-dominant-paradigm.net/blog/?feed=rss2&amp;p=74</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prolog in Church</title>
		<link>http://subvert-the-dominant-paradigm.net/blog/?p=59</link>
		<comments>http://subvert-the-dominant-paradigm.net/blog/?p=59#comments</comments>
		<pubDate>Tue, 24 Nov 2009 13:18:11 +0000</pubDate>
		<dc:creator>jewel</dc:creator>
				<category><![CDATA[Church]]></category>

		<guid isPermaLink="false">http://subvert-the-dominant-paradigm.net/blog/?p=59</guid>
		<description><![CDATA[As a step towards implementing an experimental type inferencing or type checking system I have built a prolog interpreter in Church. The interpreter is based on the example in Peter Norvig&#8217;s book, &#8220;Paradigms of Artificial Intelligence Programming&#8221;.
As a first step I wrote the grammar for parsing prolog programs. Here is a sample &#8216;parent&#8217; program describing [...]]]></description>
			<content:encoded><![CDATA[<p>As a step towards implementing an experimental type inferencing or type checking system I have built a prolog interpreter in Church. The interpreter is based on the example in Peter Norvig&#8217;s book, &#8220;Paradigms of Artificial Intelligence Programming&#8221;.</p>
<p>As a first step I wrote the grammar for parsing prolog programs. Here is a sample &#8216;parent&#8217; program describing parent and grandparent relationships between Debian derivatives:</p>
<pre>
<code>
parent(ubuntu,kubuntu).
parent(ubuntu,edubuntu).

parent(debian, ubuntu).

grandparent(X,Z) :- parent(X,Y), parent(Y,Z).
</code>
</pre>
<p>and here is the OMeta grammar for parsing prolog programs:</p>
<pre>
<code>
ometa prolog <: ometa {

comment = "/*" (~cnewline anything)* cnewline -> << '_comment >>,

ws = $  | $	,
wsnl = ws | cnewline,

prolog-top-levels = (comment | prolog-rule)*,

prolog-rule = wsnl* prolog-clause:rhead ws* (":-" ws* prolog-or:body -> << body >>)* ws* $. wsnl*  -> <<`[rule ,rhead ,body]>>,

prolog-or = listof("prolog-impl", ";"):e  wsnl* -> << `[or ,e] >>,
prolog-impl = wsnl* prolog-clause:a wsnl* "->" wsnl* prolog-or:b wsnl* -> << `[implies ,a ,b] >> | prolog-and,
prolog-and = wsnl* listof("prolog-expr", ","):e wsnl* -> << `[and ,e] >>,

prolog-clause = wsnl* prolog-name:name wsnl* prolog-arg-list:args wsnl* -> <<`[,name | ,args]>>,
prolog-arg-list = $( listof("prolog-expr", ","):args wsnl* $) wsnl* -> << args >>,

prolog-expr = wsnl* (
	         $[ wsnl* $] wsnl* -> << `[]>> |
	      	 $[ wsnl* listof("prolog-expr", ","):list-head ws* ($| wsnl* prolog-expr)*:list-tail wsnl* $] wsnl* -> << (append! list-head (if list-tail (first list-tail) nil)) >> |
	      	 $( wsnl* prolog-or:e wsnl* $) wsnl* -> << e >> |
		 prolog-clause:c wsnl* -> << c >> |
                 prolog-number |
                 prolog-variable:v wsnl* -> << v >>),

prolog-number = "-"*:sign digit+:d -> << (convert-number sign d)>>,

prolog-variable = (letter | digit | $_)+:l -> << (intern (coerce l 'string)) >>,

prolog-name = (letter | digit | $_)+:l -> << (intern (coerce l 'string)) >>  }
</code>
</pre>
<p>The core of prolog lies in the unification and backtracking algorithms.</p>
<p>Unification will try to match its two inputs or else bind a variable to the corresponding value:</p>
<pre>
<code>
unify x y bindings
	cond
		(eq? bindings prolog-fail) prolog-fail
		(eq? x y) bindings
		(eq? x '_) bindings
		(eq? y '_) bindings
		(variable-symbol? x) (unify-variable x y bindings)
		(variable-symbol? y) (unify-variable y x bindings)
		(and (cons? x) (cons? y)) (unify (rest x) (rest y) (unify (first x) (first y) bindings))
		true prolog-fail

unify-variable var x bindings
	cond
		(get-binding var bindings) (unify (lookup var bindings) x bindings)
		(and (variable-symbol? x) (get-binding x bindings)) (unify var (lookup x bindings) bindings)
		(and occurs-check? (occurs-check var x bindings)) prolog-fail
		true (extend-bindings var x bindings)
</code>
</pre>
<p>Backtracking is achieved by allowing each clause to provide multiple solutions and trying all of these possibilities:</p>
<pre>
<code>
prove-all pi:prolog-interpreter goals bindings
	cond
		(eq? bindings prolog-fail) nil
		(null? goals) (list bindings)
		true
			mapcan (fn goal1-solution
				prove-all pi (rest goals) goal1-solution
) (prove pi (first goals) bindings)
</code>
</pre>
<p>As a test I used <a href="http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_9.html">this map coloring program from a prolog tutorial</a>:</p>
<pre>
<code>
member(X,[X|_]).
member(X,[_|List]) :- member(X,List).

adjacent(X,Y,Map) :-  member([X,Y],Map) ; member([Y,X],Map). 

find_regions([],R,R).
find_regions([[X,Y]|S], R,A) :-
 (member(X,R) ->
  (member(Y,R) -> find_regions(S,R,A)     ; find_regions(S,[Y|R],A))  ;
  (member(Y,R) -> find_regions(S,[X|R],A) ; find_regions(S,[X,Y|R],A) )). 

color(Map,Colors,Coloring) :-
        find_regions(Map,[],Regions),
        color_all(Regions,Colors,Coloring),
        not(conflict(Map,Coloring)).
color_all([R|Rs],Colors,[[R,C]|A]) :-
        member(C,Colors),
        color_all(Rs,Colors,A).
color_all([],_,[]). 

conflict(Map,Coloring) :- member([R1,C],Coloring),
        member([R2,C],Coloring),
        adjacent(R1,R2,Map). 

map1([[1,2],[1,3],[1,4],[1,5],[2,3],[2,4],[3,4],[4,5]]).
</code>
</pre>
<p>which yields the following colourings:</p>
<pre>
<code>
"query"
[[map1 M] [color M [red green blue yellow] Coloring]]

M = [[1 2] [1 3] [1 4] [1 5] [2 3] [2 4] [3 4] [4 5]]
Coloring = [[5 red] [4 green] [3 red] [1 blue] [2 yellow]]
;
M = [[1 2] [1 3] [1 4] [1 5] [2 3] [2 4] [3 4] [4 5]]
Coloring = [[5 red] [4 green] [3 red] [1 yellow] [2 blue]]
...
</code>
</pre>
<p>You can browse the source files for the prolog interpreter <a href="http://subvert-the-dominant-paradigm.net/repos/hgwebdir.cgi/bootstrap/file/723871f2f056/genesis/church/prolog">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://subvert-the-dominant-paradigm.net/blog/?feed=rss2&amp;p=59</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>jonesforth64</title>
		<link>http://subvert-the-dominant-paradigm.net/blog/?p=54</link>
		<comments>http://subvert-the-dominant-paradigm.net/blog/?p=54#comments</comments>
		<pubDate>Sun, 19 Jul 2009 19:32:05 +0000</pubDate>
		<dc:creator>jewel</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[forth]]></category>

		<guid isPermaLink="false">http://subvert-the-dominant-paradigm.net/blog/?p=54</guid>
		<description><![CDATA[I have ported jonesforth to 64-bit x86 code.
jonesforth is a tutorial-style implementation of forth which explains in detail how the compiler and runtime is implemented. Porting the code to a slightly different assembly language helped me to think carefully about what each primitive does and about how they are used in the runtime code.
As noted [...]]]></description>
			<content:encoded><![CDATA[<p>I have ported <a href="http://http://www.annexia.org/forth">jonesforth</a> to 64-bit x86 code.</p>
<p>jonesforth is a tutorial-style implementation of forth which explains in detail how the compiler and runtime is implemented. Porting the code to a slightly different assembly language helped me to think carefully about what each primitive does and about how they are used in the runtime code.</p>
<p>As noted in the jonesforth comments, the original advantage of using direct-threaded code on a 16-bit machine is that calling each word can be encoded in two bytes instead of three. That&#8217;s a savings of 33%. On 32-bit x86, it&#8217;s four bytes versus five, saving 20%. In my 64-bit implementation I chose to extend the 4-byte addresses to 8-byte words. This actually results in wasting space rather than saving it because on x86-64 calls and branches are usually encoded with a 5-byte instruction using relative displacement.</p>
<p>The port was fairly straightforward, I mostly just replaced 32-bit registers (eax, esp, esi etc) with the 64-bit equivalents (rax, rsp, rsi etc) and changed every reference to the word-size from 4 to 8.</p>
<p>The biggest difference is that syscalls use different registers on 64-bit linux and these registers can be clobbered during the call.</p>
<p>You can get the code from the mercurial repository:</p>
<p><code>hg clone http://subvert-the-dominant-paradigm.net/repos/jonesforth64/</code></p>
<p>To compile it:</p>
<p><code><br />
gcc -m64 -nostdlib -static -Wl,-Ttext,0 -Wl,--build-id=none -o jonesforth64 jonesforth64.S<br />
</code></p>
<p>To run it:</p>
<p><code><br />
cat jonesforth64.f - | ./jonesforth64<br />
JONESFORTH VERSION 45<br />
6393 CELLS REMAINING<br />
OK<br />
1 2 3 4<br />
.S<br />
4 3 2 1<br />
ROT<br />
.S<br />
3 2 4 1<br />
</code></p>
<p>I&#8217;ve tested most of the code in the .f file, but I haven&#8217;t yet implemented C strings, file-io or the built-in assembler.</p>
<p>I&#8217;ve tried to keep the comments intact, but haven&#8217;t updated them to reflect different word sizes or registers etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://subvert-the-dominant-paradigm.net/blog/?feed=rss2&amp;p=54</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hullabaloo in the Guava Orchard</title>
		<link>http://subvert-the-dominant-paradigm.net/blog/?p=49</link>
		<comments>http://subvert-the-dominant-paradigm.net/blog/?p=49#comments</comments>
		<pubDate>Wed, 01 Jul 2009 13:28:53 +0000</pubDate>
		<dc:creator>jewel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://subvert-the-dominant-paradigm.net/blog/?p=49</guid>
		<description><![CDATA[

This book and &#8220;The Inheritance of Loss&#8221; make Kiran Desai one of my favourite authors.
]]></description>
			<content:encoded><![CDATA[<p><img src="http://subvert-the-dominant-paradigm.net/~jewel/blog_images/2009/Guava3.jpg" alt="Hullabaloo in the Guava Orchard" /></p>
<p>
This book and &#8220;The Inheritance of Loss&#8221; make Kiran Desai one of my favourite authors.</p>
]]></content:encoded>
			<wfw:commentRss>http://subvert-the-dominant-paradigm.net/blog/?feed=rss2&amp;p=49</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ICFP &#8216;09</title>
		<link>http://subvert-the-dominant-paradigm.net/blog/?p=46</link>
		<comments>http://subvert-the-dominant-paradigm.net/blog/?p=46#comments</comments>
		<pubDate>Tue, 30 Jun 2009 16:29:05 +0000</pubDate>
		<dc:creator>jewel</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://subvert-the-dominant-paradigm.net/blog/?p=46</guid>
		<description><![CDATA[I had the pleasure of participating in the ICFP contest again this year. I think I joined a haskell team in 2002 (which is funny because I&#8217;m not proficient in haskell at all!). But since then I&#8217;ve only been part of a Lisp team in 2007. That time I failed to implement a ropes-like library [...]]]></description>
			<content:encoded><![CDATA[<p>I had the pleasure of participating in the <a href="http://www.icfpcontest.org/index.php">ICFP</a> contest again this year. I think I joined a haskell team in 2002 (which is funny because I&#8217;m not proficient in haskell at all!). But since then I&#8217;ve only been part of a Lisp team in 2007. That time I failed to implement a ropes-like library in enough time to get us enough momentum.</p>
<p>So this year it was great to try again, our team ended up being just myself and another Lisp hacker from New Zealand. Since I&#8217;m in South Africa there was quite a time zone difference between us and we both stayed up till early hours during the last two days.</p>
<p>As always it didn&#8217;t take long to write up the initial code for the interpreter, but we spent several hours tracking down bugs, parsing the inputs and figuring out how to approach the problem.</p>
<p>My partner then took over, he wrote all the physics and modeling code while I tried to provide moral support and starting hacking a visualizer.</p>
<p>Initially we used a lisp library called cgn, which was ok for the initial runs but proved too slow later on. cgn writes out data points to a text file (and we had to patch it to write double-floats correctly) and then feeds this to gnuplot.</p>
<p>The writing and reading of these ascii files was too slow for the kinds of scenarios we were modeling (tens of thousands of data points), so I started over, trimming the dataset by only using every 100th data point and writing data files in binary format.</p>
<p>Since I had never really used gnuplot before I spent several hours reading documentation and poking around until I was able to generate scripts like the following to render our data:</p>
<p><code><br />
set key bottom right<br />
plot [-100000000:100000000] 'plots/ROCKET.dat' binary record=11951X11951 format="%float64%float64" title 'plots/ROCKET', 'plots/TARGET.dat' binary record=11951X11951 format="%float64%float64" title 'plots/TARGET'<br />
pause -1<br />
</code></p>
<p>I was quite pleased with the results, but there are obviously better ways to display the trace if you have the time and create the right tools.</p>
<p><img src="http://subvert-the-dominant-paradigm.net/~jewel/blog_images/2009/sats2.png" alt="Satellite visualization" /></p>
<p>(Note the start and end labels are swapped in this picture)</p>
<p>In the end we never really got a solution for the 4th task, but managed to score about 2000 points with our solutions.</p>
]]></content:encoded>
			<wfw:commentRss>http://subvert-the-dominant-paradigm.net/blog/?feed=rss2&amp;p=46</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Church alpha 3</title>
		<link>http://subvert-the-dominant-paradigm.net/blog/?p=45</link>
		<comments>http://subvert-the-dominant-paradigm.net/blog/?p=45#comments</comments>
		<pubDate>Fri, 20 Mar 2009 14:36:14 +0000</pubDate>
		<dc:creator>jewel</dc:creator>
				<category><![CDATA[Church]]></category>
		<category><![CDATA[State]]></category>

		<guid isPermaLink="false">http://subvert-the-dominant-paradigm.net/blog/?p=45</guid>
		<description><![CDATA[This release fixes some bugs:
http://subvert-the-dominant-paradigm.net/~jewel/church/church-alpha-3.tar.gz

When I first wrote some of the church compiler passes and the sexp parser I used global variables to store state specific to that pass. I knew that only one thread would be running and that these passes didn&#8217;t have to be reentrant. Later I added functionality to compile macros on [...]]]></description>
			<content:encoded><![CDATA[<p>This release fixes some bugs:</p>
<p><a href="http://subvert-the-dominant-paradigm.net/~jewel/church/church-alpha-3.tar.gz">http://subvert-the-dominant-paradigm.net/~jewel/church/church-alpha-3.tar.gz</a></p>
<ul>
<li>When I first wrote some of the church compiler passes and the sexp parser I used global variables to store state specific to that pass. I knew that only one thread would be running and that these passes didn&#8217;t have to be reentrant. Later I added functionality to compile macros on the fly and to compile dispatch matchers. When I did this I tried to rewrite all the modules that used global state, but I missed the sexp parser and this caused some strange bugs later on.</li>
<li>When allocating memory for dynamically allocated code, I was storing the address of the memory block in a fixnum. This worked fine until malloc started returning addresses from higher memory which used the most significant two bits in a word. These would get shifted out when tagging a fixnum and yield an invalid address. To work around this I now box the address by storing it in an array</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://subvert-the-dominant-paradigm.net/blog/?feed=rss2&amp;p=45</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Church alpha 2</title>
		<link>http://subvert-the-dominant-paradigm.net/blog/?p=44</link>
		<comments>http://subvert-the-dominant-paradigm.net/blog/?p=44#comments</comments>
		<pubDate>Wed, 11 Mar 2009 12:31:54 +0000</pubDate>
		<dc:creator>jewel</dc:creator>
				<category><![CDATA[Church]]></category>
		<category><![CDATA[State]]></category>

		<guid isPermaLink="false">http://subvert-the-dominant-paradigm.net/blog/?p=44</guid>
		<description><![CDATA[I have made a new release incorporating the performance work described in previous posts.
http://subvert-the-dominant-paradigm.net/~jewel/church/church-alpha-2.tar.gz
]]></description>
			<content:encoded><![CDATA[<p>I have made a new release incorporating the performance work described in previous posts.</p>
<p><a href="http://subvert-the-dominant-paradigm.net/~jewel/church/church-alpha-2.tar.gz">http://subvert-the-dominant-paradigm.net/~jewel/church/church-alpha-2.tar.gz</a></p>
]]></content:encoded>
			<wfw:commentRss>http://subvert-the-dominant-paradigm.net/blog/?feed=rss2&amp;p=44</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
