Difference between revisions of "Peer-nodal.as"

From Organic Design wiki
m
(resolve() creates on access)
Line 26: Line 26:
 
// values could be node-ref (index), list, lambda, or function-ref
 
// values could be node-ref (index), list, lambda, or function-ref
  
 +
// ==========================================================================================
  
// We'll fake a list-space with an array
+
// idcount is a accumulating-only counter for locally-unique-id number
// - create and delete are called internally from get/set
+
// nodes is the current number of instantiated node objects
 
 
 
nodal = { idcount: 0, nodes: 0 };
 
nodal = { idcount: 0, nodes: 0 };
  
Line 36: Line 36:
 
// - Actionscript failed ref-as-hashkey test,
 
// - Actionscript failed ref-as-hashkey test,
 
//  so we use a id (locally unique identifier) as a lookup-key
 
//  so we use a id (locally unique identifier) as a lookup-key
nodal.create = function( context, class ) {
+
nodal.create = function( context, key ) {
 +
this.nodes++;
 
var node = { id: this.idcount++ };
 
var node = { id: this.idcount++ };
return context[class.id] = node;
+
return context[key.id] = node;
this.nodes++;
 
 
};
 
};
  
nodal.delete = function( context, class ) {
+
nodal.delete = function( context, key ) {
 +
this.nodes--;
 
delete context[class.id];
 
delete context[class.id];
this.nodes--;
 
 
};
 
};
  
nodal.store = function( context, path, data ) {
+
// Resolve creates if non existent and returns reference to result
 +
// - no delete currently
 +
// - just get/set properties with normal object-accessor way
 +
// - but keep all hierarchy nodal
 +
nodal.resolve = function( context, path ) {
 +
while( path.length ) {
 +
var key = path.pop();
 +
if ( context[key.id] == null ) context = this.create( context, key );
 +
else context = context[ key.id ];
 +
}
 +
return context;
 
};
 
};
 
nodal.fetch = function( context, path) {
 
return data;
 
};
 
 
  
 
// This is the old ecma reduction tree taken from SIC code
 
// This is the old ecma reduction tree taken from SIC code
 
// - needs major modification, but has the core language features needed
 
// - needs major modification, but has the core language features needed
nodal.reduce = function() {
+
nodal.reduce = function( context ) {
 
cwd = root;
 
cwd = root;
 
for (var i = 1; i == 1;) {
 
for (var i = 1; i == 1;) {
Line 67: Line 72:
 
else i = 0;
 
else i = 0;
 
}
 
}
};
 
 
// - calling this resolve so not confused with list-space-trie process
 
nodal.resolve = function( path ) {
 
ptr = THIS;
 
for ( i in path ) ptr = ptr['i'+i];
 
return ptr;
 
 
};
 
};

Revision as of 08:39, 6 April 2006

// NODAL ASSOCIATIONS // - associations (maintained class:instance relationships) // instance.create/delete(class) calls class.create/delete(instance) // create inserts the instance into the classes instance-loop (list-aspect, next/prev) // ie. our list of current children (that our E divides amongst) is also our instance-loop // has or is are one, they're all just relationships that receive a portion of energy // laster: a chain of delegate classes is created between root and the instance // - the class of any assoc requires a portion of the quanta // remember, next/prev and complimented by parent/current (parent is also class) // - this allows alternate quanta be divided between parent and current, thus providing // energy for the class->instance relationship // - get retreives from class value if no instance value at each step of a path

// REDUCTION // - 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

// DATA STRUCTURE // A question that keeps cropping up is: // is it best to use the language's native list type, // or to use a linked list constructed of next and prev refs. // The best idea (since swf failed key-as-ref) is to use array-index-only as key, // but allow any datatype as value, that way we can use a list or not later on // values could be node-ref (index), list, lambda, or function-ref

// ==========================================================================================

// idcount is a accumulating-only counter for locally-unique-id number // nodes is the current number of instantiated node objects nodal = { idcount: 0, nodes: 0 };

// Create // - 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 nodal.create = function( context, key ) { this.nodes++; var node = { id: this.idcount++ }; return context[key.id] = node; };

nodal.delete = function( context, key ) { this.nodes--; delete context[class.id]; };

// Resolve creates if non existent and returns reference to result // - no delete currently // - just get/set properties with normal object-accessor way // - but keep all hierarchy nodal nodal.resolve = function( context, path ) { while( path.length ) { var key = path.pop(); if ( context[key.id] == null ) context = this.create( context, key ); else context = context[ key.id ]; } return context; };

// This is the old ecma reduction tree taken from SIC code // - needs major modification, but has the core language features needed nodal.reduce = function( context ) { cwd = root; 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; } };