Difference between revisions of "Peer-nodal.as"

From Organic Design wiki
(Remove old comments)
(Make more OO with node prototype)
Line 8: Line 8:
 
// nodes is the current number of instantiated node objects
 
// nodes is the current number of instantiated node objects
 
// queue is the root reduction queue
 
// queue is the root reduction queue
nodal = { queue: [], idcount: 0, nodes: 0 };
+
root = { queue: [], idcount: 0, nodes: 0 };
 +
 
 +
// NODE OBJECT
 +
function node() {
 +
 
 +
root.nodes++;
 +
this.id = root.idcount++;
 +
this.queue = [];
 +
 
 +
};
  
 
// NODAL METHODS
 
// NODAL METHODS
Line 17: Line 26:
 
// - just get/set properties with normal object-accessor way
 
// - just get/set properties with normal object-accessor way
 
// - but keep all hierarchy nodal
 
// - but keep all hierarchy nodal
 +
 +
node.prototype.set( value ) {
 +
};
 +
 +
node.prototype.get() {
 +
return value;
 +
};
  
 
// Resolve creates if non existent and returns reference to result
 
// Resolve creates if non existent and returns reference to result
nodal.resolve = function( context, path ) {
+
node.prototype.resolve = function( path ) {
 +
var context = this;
 
while( path.length ) {
 
while( path.length ) {
 
var key = path.shift();
 
var key = path.shift();
if ( context[key.id] == null ) {
+
context = context[key.id] == null ? context[key.id] = new node() : context[ key.id ];
this.nodes++;
 
var node = { queue: [], id: this.idcount++ };
 
context = context[key.id] = node;
 
}
 
else context = context[ key.id ];
 
 
}
 
}
 
return context;
 
return context;
Line 38: Line 50:
 
// - a functions parameters (and even further methods and tools) are child associations
 
// - a functions parameters (and even further methods and tools) are child associations
 
//  the structures necessary to build the fucntion are child assocs too
 
//  the structures necessary to build the fucntion are child assocs too
nodal.reduce = function( context ) {
+
node.prototype.reduce = function() {
 
+
var context = this;
 
if ( node = context.queue.pop() ) {
 
if ( node = context.queue.pop() ) {
  
 
// is there a local declaration?
 
// is there a local declaration?
// - if yes, execute it and also reduce( class )
+
// - if yes, execute it and also class.reduce()
// - if no, { reduce( node ) if it has a queue, back to root if not }
+
// - if no, { node.reduce() if it has a queue, back to root if not }
  
 
}
 
}

Revision as of 11:46, 6 April 2006

// ISSUES // - associations (maintained class:instance relationships) // - get should use class content as default - resolve() doesn't // so either add get/set which use resolve, or remove object-freedom and have only .data

// NODAL PROPERTIES // idcount is a accumulating-only counter for locally-unique-id number // nodes is the current number of instantiated node objects // queue is the root reduction queue root = { queue: [], idcount: 0, nodes: 0 };

// NODE OBJECT function node() {

root.nodes++; this.id = root.idcount++; this.queue = [];

};

// NODAL METHODS // - the delete-list is only needed for limited list-space env // - Actionscript failed ref-as-hashkey test, // so we use a id (locally unique identifier) as a lookup-key // - no delete currently // - just get/set properties with normal object-accessor way // - but keep all hierarchy nodal

node.prototype.set( value ) { };

node.prototype.get() { return value; };

// Resolve creates if non existent and returns reference to result node.prototype.resolve = function( path ) { var context = this; while( path.length ) { var key = path.shift(); context = context[key.id] == null ? context[key.id] = new node() : context[ key.id ]; } return context; };

// Consume one quanta // - each quantum is actually two, one for local instance, one for global class // - all instance-loops work by going cd this.current then assigning this.current.next to it // when a function executes, it can update the loop at that location (equiv to array.push) // - a functions parameters (and even further methods and tools) are child associations // the structures necessary to build the fucntion are child assocs too node.prototype.reduce = function() { var context = this; if ( node = context.queue.pop() ) {

// is there a local declaration? // - if yes, execute it and also class.reduce() // - if no, { node.reduce() if it has a queue, back to root if not }

}

// Old ECMA SIC reduction for ( var i = 1; i == 1; ) { var queue = cwd.queue; if ( queue.length > 0 ) { var todo = queue.shift(); if ( next = typeOf( todo ) == 'function' ? ( i = todo.call ) : ( cwd = todo ) ) queue.push( next ); } else i = 0; } };