<?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>hatsuseno&#039;s blog</title>
	<atom:link href="http://blog.hatsuseno.org/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hatsuseno.org</link>
	<description>rantings on tech</description>
	<lastBuildDate>Thu, 25 Feb 2010 04:02:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Gentoo, awesome and themes</title>
		<link>http://blog.hatsuseno.org/index.php/gentoo-awesome-and-themes/</link>
		<comments>http://blog.hatsuseno.org/index.php/gentoo-awesome-and-themes/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 03:53:23 +0000</pubDate>
		<dc:creator>hatsuseno</dc:creator>
				<category><![CDATA[Gentoo errors]]></category>
		<category><![CDATA[awesome]]></category>
		<category><![CDATA[custom-scripts]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[wallpaper]]></category>

		<guid isPermaLink="false">http://blog.hatsuseno.org/?p=126</guid>
		<description><![CDATA[
I&#8217;ve been a Gentoo user since forever, and for some time I&#8217;ve been using awesome for a window manager instead of the desktop environments Gnome or KDE. One thing I never got around to change was the wallpaper. My terminals are pseudo-transparent, and I never disliked the default &#8216;awesome&#8217; wallpaper. @ZackLeonhart&#8217;s bitching and moaning changed [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://hammerfest.hatsuseno.org/~crashmatrix/awesome_logo.png" title="Awesome logo" class="alignleft" width="64" height="64" />
<p>I&#8217;ve been a Gentoo user since forever, and for some time I&#8217;ve been using awesome for a window manager instead of the desktop environments Gnome or KDE. One thing I never got around to change was the wallpaper. My terminals are pseudo-transparent, and I never disliked the default &#8216;awesome&#8217; wallpaper. <a href='http://twitter.com/ZackLeonhart'>@ZackLeonhart</a>&#8217;s bitching and moaning changed that.</p>
<p>Turns out that aside from editing the system-wide theme script, by default located in <code>/usr/share/awesome/themes/*</code> (which I consider to be a BadThink&#8482;), there is no straight forward way of doing it nicely in the Gentoo provided default setup. So here&#8217;s what you do.</p>
<p><ol>
<li>Create yourself a lua.rc in <code>${HOME}/.config/awesome</code><br /><code>$ cp /etc/xdg/awesome/rc.lua ~/.config/awesome</code></li>
<li>Recursively copy all themes from the system-wide dirs to your local configdir.<br /><code>$ cp -rvf /usr/share/awesome/themes ~/.config/awesome</code></li>
<li>In your copy of lua.rc you will find a variable called <code>theme_path</code>, change it to <code>theme_path = os.getenv("HOME") .. "/.config/awesome/themes/path/to/theme.lua"</code></li>
<li>Edit the variable <code>theme.wallpaper_cmd</code> to contain the string <code>"eval `cat ~/.fehbg`"</code></li>
<li>Choose a wallpaper you like, execute <code>$ feh --bg-scale /path/to/wallpaper.jpg</code></li>
</ol>
<p>And you&#8217;re done! If you want to change your wallpaper, simply use <code>feh</code> again with a random other file, and make sure the file is readable when awesome is starting up, and it&#8217;ll set it up automagically. Basically, awesome&#8217;s &#8216;beautiful&#8217; library takes your typed out command and executes that in order to set the wallpaper, feh has a convenient way of storing the default wallpaper by simply dumping the command that was used to set it up in the first place in a configuration file in your home directory, hence the <code>eval `cat whatever`</code> trick.
</p>
<div class="wp-caption alignnone" style="width: 450px"><a href='http://hammerfest.hatsuseno.org/~crashmatrix/screencap_250210.jpg'><img alt="Screenshot of my new wallpaper in Awesome" src="http://hammerfest.hatsuseno.org/~crashmatrix/screencap_250210.jpg" title="Screenshot" width="440" /></a><p class="wp-caption-text">Screenshot of my new wallpaper in Awesome</p></div>
<p>P.S.: Don&#8217;t think you can leave out the call to os.getenv() in step 3, awesome doesn&#8217;t expand the tilde (&#8217;~'), so the path it&#8217;ll try to access will be invalid.</p>
<p>P.P.S.: This is more of a note for me, in case I ever lose my epic new wallpaper. It can be found <a href='http://upload.wikimedia.org/wikipedia/commons/e/ec/LodalenPano.jpg'>here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hatsuseno.org/index.php/gentoo-awesome-and-themes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>building a programming language, part 2</title>
		<link>http://blog.hatsuseno.org/index.php/building-a-programming-language-part-2/</link>
		<comments>http://blog.hatsuseno.org/index.php/building-a-programming-language-part-2/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 13:02:30 +0000</pubDate>
		<dc:creator>hatsuseno</dc:creator>
				<category><![CDATA['cwx' project]]></category>
		<category><![CDATA[cwx]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://blog.hatsuseno.org/?p=90</guid>
		<description><![CDATA[Following up on my original post, this time, version 1.0 &#8220;final&#8221; for the basic structure and syntax of the language, still unnamed, although someone suggested I should integrate &#8216;two&#8217; and &#8216;hash&#8217; in there. Oh well.
The spirit remains, but there have been a few changes in the language as a whole. The entire codeblock-as-type feature has [...]]]></description>
			<content:encoded><![CDATA[<p>Following up on my original post, this time, version 1.0 &#8220;final&#8221; for the basic structure and syntax of the language, still unnamed, although someone suggested I should integrate &#8216;two&#8217; and &#8216;hash&#8217; in there. Oh well.</p>
<p>The spirit remains, but there have been a few changes in the language as a whole. The entire codeblock-as-type feature has been dropped until it can be further perfected syntactically, and I&#8217;ve taken a more pragmatic approach in general, things need to get done after all.</p>
<p><h2>Built-in types</h2>
<dl>
<dt><code>boolean</code></dt>
<dd>A boolean type, true or false.</dd>
<p></p>
<dt><code>integer</code></dt>
<dd>Pretty obvious, integer numbers, 64bit signed.</dd>
<p></p>
<dt><code>float</code></dt>
<dd>Less obvious, implemented as a C-style double.</dd>
<p></p>
<dt><code>string</code></dt>
<dd>A string type, most types can be cast to this.</dd>
<p></p>
<dt><code>list</code></dt>
<dd>Simple, LISP-style, linked-list.</dd>
<p></p>
<dt><code>array</code></dt>
<dd>Variable-length, numerically indexed arrays.</dd>
<p></p>
<dt><code>hash</code></dt>
<dd>Variable-length hashmap, /[[:alnum:]_]+?/ keys.</dd>
<p></p>
<dt><code>function</code></dt>
<dd>Standard first-class citizen functions.</dd>
<p></p>
<dt><code>class</code></dt>
<dd>First-class citizen classes.</dd>
<p></p>
<dt><code>dynamic</code></dt>
<dd>Special untyped variable, can contain *any* type value at any time, default type</dd>
<p>
</ul>
<h3>Examples of primitive types</h3>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">boolean b = true;
integer x = 5;
float j = 5.4E-4;
string s = 'test string';
list l = list(1, 2, 3, 4, 5);
array m = array('a', 'b', 'c', 'd', 'e');
hash z = hash(a: 1, b: 2, c: 3, d: 4, test_key: 666);
&nbsp;
function f = function(a, b, c, d) uses (m) {
  sum(a, b, c, d, m[1]);
};
&nbsp;
class c = class(
  private integer attr_name: 5,
  public function constructor myConstructor: function() {
    this.attr_name *= 10;
  }
);
dynamic y = 20;
p = 20;</pre></div></div>

<p>A few sidenotes;</p>
<ul>
<li>Keys in hash-maps are unquoted, because they are properly constrained.</li>
<li>Functions are <i>always</i> closures, but require explicit declaration of the enclosed variables.</li>
<li>Classes syntactically resemble hash-maps, but have modifier keywords, like private, protected, constructor and destructor.</li>
<li>The variables y and p are for all intents and purposes identical in content and type, untyped variables *are* dynamic variables.</li>
<li>All composite types (like lists, arrays and classes) have a constructor-function, which is an actual function that can be called with eval()-esque intent.</li>
</ul>
<p><h2>In-depth look into the composite types</h2>
<h3>Lists</h3>
<p>Lists are singly-linked lists, and the functions <code>list()</code>, <code>first()</code> and <code>rest()</code> are the primitive operators on lists.</p>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">x = list(1, 2, 3, 4, 5);
first(x);
  =&gt; 1
rest(x);
  =&gt; list(3, 4, 5)</pre></div></div>

<p><code>first()</code> and <code>rest()</code> are modifying functions, they pop from the list whatever they return, so the list <code>x</code> is now a list with the value <code>(2)</code>. Trying to pop from an empty array results in a &#8216;null&#8217; value being returned. While-loops can be constructed around this, but lists are iteratable, so the built-in <code>foreach()</code> will do just fine.</p>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">foreach(list(1, 2, 3, 4, 5) as li) { ... }</pre></div></div>

<h3>Arrays</h3>
<p>Arrays are numerically indexed, sparse datastructures. So you can have a value at index 1 and at 5, nothing stops you from breaking sequence. By default an array can contain values of any type (so it&#8217;s implicitly an array of dynamic values) but this behaviour can be changed easily.</p>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">integer array a = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
a[9] = 10;
a[1] = null;
a;
  =&gt; array(1, 3, 4, 5, 6, 7, 8, 9, 10);
&nbsp;
a[1];
  =&gt; null;</pre></div></div>

<p>Array <code>a</code> is explicitly an array of integer values, and so cannot be assigned anything else. Doing so will result in a run-time error. (Type-checking is always done in run-time).<br />
Unsetting array indecis is done by setting the value to <code>null</code>, as you can see when evaluating the array, index 1 does not exist. Evaluating a non-existant index of an array produces <code>null</code> as well. There is no difference between non-existing indecis and values set to <code>null</code>.</p>
<h3>Hash-maps</h3>
<p>Similar to arrays in syntax to arrays, maps are variable in length, and implicitly of type &#8216;dynamic&#8217;. This can be changed in the same way it can for arrays.</p>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">integer hash m = hash(a: 1, b: 2, c: 3, d: 4);
x = map(function (val, key) { ... }, m);</pre></div></div>

<p>Introducing the function <code>map</code>, although it could be easily constructed using lower-level operations, a high-order function provided by the language runtime.</p>
<h3>Functions</h3>
<p>Being first-class citizens, functions get assigned to variables, and nothing else. All functions are closures, but require a list of variables to enclose. This is to keep GC simpler and it requires the developer think about what he or she wants to enclose.</p>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">square = function(x) { return x^2; } // f(x) = x^2;
&nbsp;
deriv = function(f, dx) {
  return function(x) uses (f, dx) {
    return (f(x + dx) - f(x)) / dx
  };
};
&nbsp;
d_square = deriv(square, 0.001); // Approximates f'(x) = 2x;</pre></div></div>

<p>Provided is an example demonstrating the use of this language in creating a function that produces a function approximating the derivative of another function.</p>
<h3>Classes</h3>
<p>Classes are a bit different from the usual OOP approach, and are halfway between normal OOP classes and prototype-based languages. Classes are first-class citizens, and can be modified in run-time. Immediately the usual implied trust that a class will remain the same during it&#8217;s entire lifetime no longer exists, although there are methods of regaining that trust.</p>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">p = class(
  private integer x,
  private integer y,
&nbsp;
  public constructor function myConstructor: function() {
    this.x = 5; this.y = 5;
  },
&nbsp;
  public function toString() {
    return &quot;x: &quot; ~ x ~ &quot;, y: &quot; ~ y;
  }
);
&nbsp;
object = new p;
p.toString();
  =&gt; string &quot;x: 5, y: 5&quot;</pre></div></div>

<p>Looks reasonable enough, create a class, make an object, execute method, the usual. Inheritance is also mostly the same as PHP and Java classes.</p>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">k = class() extends p; // Empty class extending class p.
&nbsp;
z = interface(public function toList);
t = class(
  public function toList: function() {
    return list(this.x, this.y);
  }
) extends p implements z;</pre></div></div>

<p><code>t</code> is a class implementing interface <code>z</code> and extending class <code>p</code>. It&#8217;s a bit ugly with the modifiers at the bottom, but it works fine. But because classes are also first-class citizens, and not the global structures we know from Java and C++ for example, you can hide classes in context, effectively using the code-scope mechanism to implement a system similar to namespaces in that it provides some classes can be directly accessed from the entire project, and some are internal to a function, a class or any other scope-seperating block.</p>
<p>The role/mixin/trait feature described in the first post about this programming language has been dropped until I get my head around it well enough to see the implications of adding it.
</p>
<p>
That about sums it up for the built-in types for version 1.0 of the language specification, though I&#8217;m sure there are flaws in here that need resolving before it can be implemented properly. Critisism, as always, is appreciated, save for spelling errors and such, I am already aware my English skill needs upgrading <img src='http://blog.hatsuseno.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  For now, I can start working on the grammar/syntacical parser of the interpreter. After that comes a symbol table and after that I&#8217;ll be sure to post an update here.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hatsuseno.org/index.php/building-a-programming-language-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>building a programming language, part 1</title>
		<link>http://blog.hatsuseno.org/index.php/building-a-programming-language-part-1/</link>
		<comments>http://blog.hatsuseno.org/index.php/building-a-programming-language-part-1/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 11:27:32 +0000</pubDate>
		<dc:creator>hatsuseno</dc:creator>
				<category><![CDATA['cwx' project]]></category>
		<category><![CDATA[cwx]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://blog.hatsuseno.org/?p=48</guid>
		<description><![CDATA[As a follow-up from a school assignment (where I had to build a full parser for a very simple language) I decided to construct a language of my own, just for fun.
Orignally, I was a C programmer, my part-time job entails PHP, and I have a fondness for languages like Scheme, Lua and Javascript. Drawing [...]]]></description>
			<content:encoded><![CDATA[<p>As a follow-up from a school assignment (where I had to build a full parser for a very simple language) I decided to construct a language of my own, just for fun.</p>
<p>Orignally, I was a C programmer, my part-time job entails PHP, and I have a fondness for languages like Scheme, Lua and Javascript. Drawing inspiration from all these language, I have (for now) decided on a syntax like this;</p>
<p><h2>Variables</h2>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">int x = 42;
dynamic j = 'x';
y = 'x';</pre></div></div>

<p><code>j</code> and <code>y</code> are both of the same type, &#8216;<code>dynamic</code>&#8216;, in the case of <code>y</code>, this is implied. Dynamic variables can contain any type of content, others are type strict.
</p>
<p><h2>Built-in types</h2>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">int x = 42;
float j = 4.5;
string s = &quot;hello world&quot;;
array l = (1, 2, 3, 4, 'a', 'b', 'c', 'd');
map m = [a: 1, b: 2, c: 3, d: 4];
code c = { a = 5; a++; doSomething(a); };
function f = function() {};
class c = class [];</pre></div></div>

<p>Statements are first class citizens of the language, albeit not for the right reasons yet.
</p>
<p><h2>Functions</h2>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">string s = &quot;Amount &quot;;
&nbsp;
f = function(int x, function y, z) uses (s) {
  x += y(z);
  return s ~ x;
}</pre></div></div>

<p>This here example shows literal strings as a language construct, and first class citizenship of functions. All functions are closures, but require (<a href="http://wiki.php.net/rfc/closures">like</a> in PHP) the desired variables in the closure to be explicitly summed up. String concatenation is done through the &#8216;<code>~</code>&#8216; operator.
</p>
<p><h2>Classes</h2>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">surface = class [
  private x : 0,
  private int y,
&nbsp;
  public constructor makeNew : function {
    this-&gt;x = 5;
    this-&gt;y = 7;
  },
]</pre></div></div>

<p>Classes, in my opinion, are more like hash-tables than functions, as such, the syntax reflects this. &#8216;<code>constructor</code>&#8216; is a special keyword that indicates that the method defined is the constructor of said object. As shown, the name of this method can be anything. I haven&#8217;t quite decided on overloading and it&#8217;s implications, so I&#8217;ve left it at that. As with functions, classes are first class citizens of the language. That means they can be assigned to variables, copied and have operations performed on them. An example:</p>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">// Class with two attributes, implied public, of undefined type
a = class [ x, y ];
&nbsp;
// 'b' is an empty class that extends 'a'
b = class [] extends a; 
&nbsp;
c = interface [ public int x, public function getName ];
d = class []; // 'd' is an empty class
d implements c; // which now implements 'c'</pre></div></div>

<p>Operators like &#8216;<code>extends</code>&#8216; and &#8216;<code>implements</code>&#8216; can be applied to a class during it&#8217;s entire lifetime. Instances of those classes made before the operations do not change with them.</p>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">/* Classes can be extended with anonymous classes,
 * same for interfaces.
 * Not really useful, but syntactically it's valid
 * sidenote: newlines are regarded as whitespace */
a = class [ x, y ] extends class [ 
     function getName() { return 'name'; }, int c ]
     implements interface [ function getType ];
&nbsp;
x = class [ function getThing(a, b) { return a + b; } ];
&nbsp;
a has x;     // 'a' now has a method 'getThing'
b extends a; // but 'b' does not.</pre></div></div>

<p>A trick I picked up from Perl 6, class-traits. I believe this will be very beneficial in bridging traditional classes and prototype-based languages by allowing class extending without adding to the inheritance chain.
</p>
<p><h2>Operators</h2>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">/* All common symbolic operators (+, -, &amp;&amp;, extends) have
 * function-like counterparts. Internally, the symbolic ops
 * are just syntactic sugar for the function-like ops */
print(2 + 2);
print(add(2, 2));
&nbsp;
print(true &amp;&amp; false);
print(and(true, false));
&nbsp;
// Variable amount of parameters when it makes sense
print(and(true, true, true, true, true, true, false));
print(subtract(40, 3, 4, 6, 2, 13));</pre></div></div>

<p>But also</p>

<div class="wp_syntax"><div class="code"><pre class="cwx" style="font-family:monospace;">/* Symbol quoting stolen from Lisp,
 * symbols a, b and c are not evaluated */
function a = _function(('a, 'b, 'c), (x, y, z), {
  return add(a, b, c) * subtract(x, y, z); });</pre></div></div>

<p>Which, as you can see is exceedingly ugly. Neither concise nor elegant, the syntax has grown to represent what I want to avoid in general. This either means I will need to get a clue as to resolving this syntactically, or I will have to remove the operators-as-functions feature from the language, but I haven&#8217;t decided. The entire concept of code as a first class citizen of the language (like in Smalltalk) was created out of necessity to make this work.
</p>
<p><h2>Conclusion (for now, anyway)</h2>
<p>Although I have started with a parser for the basic language, stuff like the operators-as-functions and first class citizenship of codeblocks need to be resolved to add to the whole of the language instead of looking like I just clobbered it all together. Also, I still need to name it&#8230; &#8216;project cwx&#8217; sounds increasingly cheezy.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hatsuseno.org/index.php/building-a-programming-language-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP and XML manipulation</title>
		<link>http://blog.hatsuseno.org/index.php/php-and-xml-manipulation/</link>
		<comments>http://blog.hatsuseno.org/index.php/php-and-xml-manipulation/#comments</comments>
		<pubDate>Thu, 28 May 2009 23:19:30 +0000</pubDate>
		<dc:creator>hatsuseno</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[SimpleXML]]></category>

		<guid isPermaLink="false">http://blog.hatsuseno.org/?p=32</guid>
		<description><![CDATA[Recently I&#8217;ve been fiddeling around with an old project of mine, and decided to extend it into a full-blown framework, just for kicks. Born from GDO, a ORM layer for PHP, it&#8217;s supposed to serve no real purpose but personal gratification.
Anyway, parallel with the framework I am building a website to showcase it. I also [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been fiddeling around with an old project of mine, and decided to extend it into a full-blown framework, just for kicks. Born from <acronym title='Generic Database Object'>GDO</acronym>, a <acronym title='Object-relational mapping'>ORM</acronym> layer for PHP, it&#8217;s supposed to serve no real purpose but personal gratification.</p>
<p>Anyway, parallel with the framework I am building a website to showcase it. I also decided that in this specific case all the HTML documents should be built from either PHPs DOM or SimpleXML libraries, I personally dislike having HTML strewn across the project, so I&#8217;ve seperated structures like forms and tables into classes and the idea is that I can simply append them to the current page at a specific node and it&#8217;ll render the HTML when everything is added. </p>
<h3>The problem</h3>
<p>Here in lies the problem, PHPs XML libraries (at least the ones that I tried) require you to drag the top node to which you want to append whatever around in all helper classes and such, allow me to demonstrate.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$document</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$table</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMElement<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'table'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMElement<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tr'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> DOMElement<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'td'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test element'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$document</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>One would expect this all to work out fine and produce the following XML document;</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">'1.0'</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">'utf-8'</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>test element<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>In fact, it won&#8217;t. It won&#8217;t even run. PHP bails out during run time with the error &#8220;<code>DOMException: No Modification Allowed Error</code>&#8220;. This is because every <code>DOMElement</code> object not created with <a href='http://php.net/manual/en/domdocument.createelement.php'><code>DOMDocument::createElement()</code></a> is by default <i>read-only</i>, as you can read in the description of <a href='http://php.net/manual/en/domelement.construct.php'><code>DOMDocument::__construct()</code></a>.</p>
<p>Besides begging the PHP developers to make every <code>DOMElement</code> not read-only on construction, the obvious solution would be to add the <code>DOMElement</code> in question to the <code>DOMDocument</code> and continue building from there, but that&#8217;s the problem. It seems counter-intuitive to pass the <code>DOMElement</code> or <code>DOMDocument</code> that you want to append your seperate structure to to every constructor of every XML producing class (or via normal methods of course).</p>
<p>I&#8217;ve taken the literal example of PHPs DOM classes, but I&#8217;ve tested SimpleXML as well, which provides even less flexibilty regarding node reuse and other fancy stuff one could want to do with XML documents.</p>
<h3>Workarounds</h3>
<p>There are several solutions to this problem, to name a few:</p>
<ul>
<li>Create a singleton class that holds one instance of <code>DOMDocument</code>, and use a wrapper method somewhere to either get a valid <code>DOMElement</code></li>
<li>Have all classes that produce XML nodes use a fake <code>DOMDocument</code>, and then use <a href='http://php.net/manual/en/domdocument.importnode.php'><code>DOMDocument::importNode()</code></a> at the return-point to import the nodes (very inefficient, especially when using a deep-copy).</li>
<li>Have the classes that produce XML nodes return nested arrays containing all name -> content relations of the nodes and run through them when it&#8217;s sensible to do so.</li>
</ul>
<p>I&#8217;ll leave it as an exercise to the reader to pick out the best method. I haven&#8217;t found a solution yet, but I hope to contact the DOM XML module maintainer and discuss this with him/her.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hatsuseno.org/index.php/php-and-xml-manipulation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>gnome-terminal gconfd bullshit</title>
		<link>http://blog.hatsuseno.org/index.php/gnome-terminal-gconfd-bullshit/</link>
		<comments>http://blog.hatsuseno.org/index.php/gnome-terminal-gconfd-bullshit/#comments</comments>
		<pubDate>Tue, 19 May 2009 12:32:53 +0000</pubDate>
		<dc:creator>hatsuseno</dc:creator>
				<category><![CDATA[Gentoo errors]]></category>
		<category><![CDATA[awesome]]></category>
		<category><![CDATA[gconfd]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[gnome-terminal]]></category>
		<category><![CDATA[roxterm]]></category>

		<guid isPermaLink="false">http://blog.hatsuseno.org/?p=12</guid>
		<description><![CDATA[So I&#8217;ve been a long time proponent of GNOME and all, but I recently switched to awesome instead.
Even so I like gnome-terminal a bit too much, and decided to keep it around until I found a new terminal that doesn&#8217;t pull the rest of GNOME with it when I install it.
The problem
Enter emerge -uDNvat and [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_13" class="wp-caption alignleft" style="width: 138px"><a href="http://blog.hatsuseno.org/wp-content/uploads/2009/05/gnome-terminal.png"><img class="size-full wp-image-13" title="gnome-terminal" src="http://blog.hatsuseno.org/wp-content/uploads/2009/05/gnome-terminal.png" alt="bad gnome-terminal" width="128" height="128" /></a><p class="wp-caption-text">bad gnome-terminal</p></div>
<p>So I&#8217;ve been a long time proponent of <a href="http://www.gnome.org"><acronym title='GNU Network Object Model Environment'>GNOME</acronym></a> and all, but I recently switched to <a title="awesome" href="http://awesome.naquadah.org">awesome</a> instead.</p>
<p>Even so I like gnome-terminal a bit too much, and decided to keep it around until I found a new terminal that doesn&#8217;t pull the rest of GNOME with it when I install it.</p>
<h3>The problem</h3>
<p>Enter <code>emerge -uDNvat</code> and all of a sudden gnome-terminal complains about <code>Failed to contact GConf daemon; exiting.</code>. So I ask around, people reply with something along the lines of &#8220;is gconfd-2 started&#8221;, &#8220;have you installed gconfd?&#8221; and &#8220;you dumb fuck, why do you use gnome-terminal when you&#8217;re not using gnome!&#8221;.</p>
<h3>The solution</h3>
<p>Seems in the end it was a version mismatch, I was using gnome-terminal 2.26.x and my gnome-light package was still 2.24.x. Downgraded gnome-terminal and all was well again.</p>
<p>P.S. I switched to <a href="http://roxterm.sourceforge.net/">ROXTerm</a> instead, it&#8217;s almost a clone, without all the GConf bullshit, or pulling the rest of GNOME in.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hatsuseno.org/index.php/gnome-terminal-gconfd-bullshit/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
