<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -6,10 +6,10 @@ class Sawdust extends Fu {
 	function run($body) {
 		$this-&gt;topLevelScope = with(new SawdustScope);
 		return $this-&gt;topLevelScope-&gt;body($body)-&gt;defs($this-&gt;fnsFromNames(array('at')))
-			-&gt;call(null, new FuTreeWriter); }
+			-&gt;call(null, with(new FuStruct)-&gt;output(new FuTreeWriter)); } # struct is hacky?
 
 	function fnsFromNames($names) {
-		$fns = array();
+		$fns = new ArrayObject;
 		foreach ($names as $name) {
 			$fnClass = &quot;SawdustFn$name&quot;;
 			$fns[$name] = with(new $fnClass)-&gt;scope($this-&gt;topLevelScope); }
@@ -19,11 +19,15 @@ class Sawdust extends Fu {
 
 class SawdustScope extends Fu {
 
-	var $body, $defs = array(), $macros = array(), $scope, $output;
+	var $body, $defs, $macros, $scope, $output;
 
-	function call($params, $output) {
+	function __construct() {
+		$this-&gt;defs = new ArrayObject;
+		$this-&gt;macros = new ArrayObject; }
+
+	function call($params, $scope) {
 		$this-&gt;params = $params;
-		$this-&gt;output = $output;
+		$this-&gt;output = $scope-&gt;output;
 		$node = $this-&gt;body;
 		$returnValue = null;
 		while ($node) {
@@ -32,8 +36,8 @@ class SawdustScope extends Fu {
 		return $returnValue; }
 
 	function evalSym($node) {
-		if ($scope = $this-&gt;scopeOfMacro($name = $node-&gt;value())) {
-			return $scope-&gt;macros[$name]-&gt;scope($this)-&gt;call($node-&gt;firstInner(), $this-&gt;output); }
+		if ($macro = $this-&gt;macro($name = $node-&gt;value())) {
+			return $macro-&gt;scope($this)-&gt;call($node-&gt;firstInner(), $this); }
 		if ($scope = $this-&gt;scopeOfDef($name)) { return $scope-&gt;defs[$name]; }
 		return $this-&gt;symIncomprisable($node); }
 
@@ -46,8 +50,8 @@ class SawdustScope extends Fu {
 		if ($this-&gt;scope) { return $this-&gt;scope-&gt;{__FUNCTION__}($name); } }
 
 	// Retrieves the first instance, looking back through scopes, that has macro of `$name` defined.
-	function scopeOfMacro($name) {
-		if (array_key_exists($name, $this-&gt;macros)) { return $this; }
+	function macro($name) {
+		if (isset($this-&gt;macros[$name])) { return $this-&gt;macros[$name]; }
 		if ($this-&gt;scope) { return $this-&gt;scope-&gt;{__FUNCTION__}($name); } }
 
 	function symIncomprisable($node) {
@@ -77,11 +81,14 @@ class SawdustScope extends Fu {
 	function symDefMacro($node) {
 		return $this-&gt;macros[$node-&gt;value()] = with(new $this)-&gt;body($node-&gt;next()); }
 
+	function symDefInline($node) {
+		return $this-&gt;macros[$node-&gt;value()] = with(new SawdustInline)-&gt;body($node-&gt;next()); }
+
 	function symCall($node) {
 		$fn = $node;
 		$params = new FuBranchWriter;
 		while ($node = $node-&gt;next) { $params-&gt;write(n($this-&gt;evalSym($node))); }
-		return $this-&gt;evalSym($fn)-&gt;call($params-&gt;first(), $this-&gt;output); }
+		return $this-&gt;evalSym($fn)-&gt;call($params-&gt;first(), $this); }
 
 	function symIf($node) {
 		if (fuTrue($this-&gt;evalSym($node))) { return $this-&gt;evalSym($node-&gt;next()); }
@@ -96,6 +103,13 @@ class SawdustScope extends Fu {
 			$this-&gt;output-&gt;popOut(); }
 		return $written; } }
 
+class SawdustInline extends SawdustScope {
+
+	function call($params, $scope) {
+		$this-&gt;defs = $scope-&gt;defs;
+		$this-&gt;macros = $scope-&gt;macros;
+		return parent::call($params, $scope); } }
+
 class SawdustFnAt extends SawdustScope {
-	function call($params, $output) {
+	function call($params, $scope) {
 		return $params-&gt;next()-&gt;value()-&gt;at($params-&gt;value()); } }
\ No newline at end of file</diff>
      <filename>lib/sawdust.php</filename>
    </modified>
    <modified>
      <diff>@@ -47,20 +47,12 @@ class TinyIncomprisablesSpec extends SawdustSpec {
 
 class WriteSpec extends SawdustSpec {
 
-	function _should_eval_first_param_and_create_node_from_evaluation_return() {
-		$this-&gt;subj-&gt;run(n('write', n('node', n('foo'))));
-		_($this-&gt;subj-&gt;output())-&gt;shouldEqual(n('foo')); }
+	function _should_eval_first_param_treewrite_it_and_return_first_written() {
+		_($this-&gt;subj-&gt;run($this-&gt;write('foo')))-&gt;shouldEqual(n('foo')); }
 
 	function _should_eval_remaining_args_with_successive_writes_appending_inners_of_last_written() {
-		$this-&gt;subj-&gt;run(n('write', n('node', n('foo')), $this-&gt;write('bar'), $this-&gt;write('zim')));
-		_($this-&gt;subj-&gt;output())-&gt;shouldEqual(n('foo', n('bar'), n('zim'))); }
-
-	function _should_be_able_to_write_a_whole_tree() {
-		$this-&gt;subj-&gt;run(n('write', n('node', $tree = n('foo', n('bar'), n('zim')))));
-		_($this-&gt;subj-&gt;output())-&gt;shouldEqual($tree); }
-
-	function _should_return_written_value() {
-		_($this-&gt;subj-&gt;run(n('write', n('node', n('foo')))))-&gt;shouldEqual(n('foo')); } }
+		$tree = n('write', n('node', n('foo')), $this-&gt;write('bar'), $this-&gt;write('zim'));
+		_($this-&gt;subj-&gt;run($tree))-&gt;shouldEqual(n('foo', n('bar'), n('zim'))); } }
 
 class ExprSpec extends SawdustSpec {
 
@@ -159,20 +151,37 @@ class LexicalScopeSpec extends SawdustSpec {
 
 class MacrosSpec extends SawdustSpec {
 
+	function name() { return 'defMacro'; }
+
 	function _should_be_called_by_normal_evaluation() {
 		_($this-&gt;subj-&gt;run(
-			nList(n('defMacro', $this-&gt;undefed(), n('true')), $this-&gt;undefed())))-&gt;shouldBe(true); }
+			nList(n($this-&gt;name(), $this-&gt;undefed(), n('true')), $this-&gt;undefed())))-&gt;shouldBe(true); }
 
 	function _params_to_macro_should_not_be_evaluated() {
 		_($this-&gt;subj-&gt;run(
-			nList(n('defMacro', $this-&gt;undefed(), n('params')), $this-&gt;undefed(n('true')))))
+			nList(n($this-&gt;name(), $this-&gt;undefed(), n('params')), $this-&gt;undefed(n('true')))))
 			-&gt;shouldEqual(n('true')); }
 
-	function _defs_created_inside_a_macro_should_be_scoped_to_the_macro() {
-		$tree = nList(n('defMacro', $this-&gt;undefed(), n('def', n('foo'), n('true'))), n('foo'));
+	function _defs_created_inside_macro_should_be_scoped_to_the_macro() {
+		$tree = nList(
+			n($this-&gt;name(), $this-&gt;undefed(), n('def', n('foo'), n('true'))),
+			$this-&gt;undefed(), n('foo'));
 		if (_($err = rescue(array($this-&gt;subj, 'run'), array($tree)))-&gt;shouldNotBe(null)) {
 			_($err-&gt;msg())-&gt;shouldBe('Undefined symbol'); } } }
 
+class InlineMarcosSpec extends MacrosSpec {
+
+	function name() { return 'defInline'; }
+
+	# Canceling this one.
+	function _defs_created_inside_macro_should_be_scoped_to_the_macro() { }
+
+	function _defs_created_inside_macro_should_be_defed_in_the_current_scope() {
+		$tree = nList(
+			n($this-&gt;name(), $this-&gt;undefed(), n('def', n('foo'), n('true'))),
+			$this-&gt;undefed(), n('foo'));
+		_($this-&gt;subj-&gt;run($tree))-&gt;shouldBe(true); } }
+
 class IncomprisableRetrieverSpec extends SawdustSpec {
 
 	function _should_eval_an_incomprisable() {</diff>
      <filename>spec/sawdust.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>3d6fff0fc5320da90c4056dfe1b27c468e5ce7da</id>
    </parent>
  </parents>
  <author>
    <name>ole</name>
    <email>oliver.saunders@gmail.com</email>
  </author>
  <url>http://github.com/olliesaunders/fluidics/commit/3e483e8b5c9a6e2318a64e6160dbf86847bb4923</url>
  <id>3e483e8b5c9a6e2318a64e6160dbf86847bb4923</id>
  <committed-date>2009-11-10T05:37:36-08:00</committed-date>
  <authored-date>2009-11-10T05:02:24-08:00</authored-date>
  <message>Sawdust: Added inline macros.</message>
  <tree>1bf8cbcbd01ba54a2b251db0e932cf303dbe30bf</tree>
  <committer>
    <name>ole</name>
    <email>oliver.saunders@gmail.com</email>
  </committer>
</commit>
