Last active
March 3, 2020 19:14
-
-
Save kenwebb/e7f0e2911e38cfe052a28ec847d17d5e to your computer and use it in GitHub Desktop.
bplex explorations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Tue Mar 03 2020 14:14:31 GMT-0500 (Eastern Standard Time)--> | |
<XholonWorkbook> | |
<Notes><![CDATA[ | |
Xholon | |
------ | |
Title: bplex explorations | |
Description: | |
Url: http://www.primordion.com/Xholon/gwt/ | |
InternalName: e7f0e2911e38cfe052a28ec847d17d5e | |
Keywords: | |
My Notes | |
-------- | |
March 3, 2010 | |
In this workbook, I explore the Xholon concept of "bplex", and possibly how it relates to functional programming. | |
http://127.0.0.1:8888/Xholon.html?app=bplex+explorations&src=lstr&gui=clsc | |
http://127.0.0.1:8888/Xholon.html?app=bplex+explorations&src=lstr&gui=clsc&jslib=ramda.min | |
Ramda | |
----- | |
tick = (node, arg) => node.tick(arg) | |
R.pipe(tick)(bpone, 16) // 21 | |
TODO: | |
---- | |
- use Ramda pipe and compose to combine functions into chains | |
- a bplex is a chain or a cycle or possibly also other graphs | |
- expand on the Xholon idea of placing active objects (AOs) into an array, and then processing one or all AOs each time step | |
- this lets a node have locality within the overall Xholon tree, and can also execute in a controlled way by being in the array | |
- in this case, the AOs/functions within the array are NOT functional related and do NOT constitute a bplex | |
Implementing a list | |
------------------- | |
There are two approaches I can use to build a chain of function or actor nodes: | |
1. put the nodes in a named JavaScript array (an indexed data structure) ex: bpx = [node1, node2, node3], or | |
2. link the nodes together using named ports ex: node1.bpx -> node2.bpx -> node3.bpx | |
Note that Java offers ArrayList and LinkedList as the two main implementations of the List interface. | |
References | |
---------- | |
(1) see my handwritten notes in my notebook for March 1 and 2, 2020 | |
(2) at gist.github.com, query for "xholonworkbook bplex" | |
7 workbooks, including this one | |
(3) I searched for Xholon .java files that contain "blex", and found: | |
Xholon.java ISignal.java Behavior_gwtjs,java | |
(4) there are no Xholon XML or .js files that contain "bplex" | |
including JavaScript files in lib and script directories | |
]]></Notes> | |
<_-.XholonClass> | |
<PhysicalSystem/> | |
<bplex/> | |
<FunkPipeline/> | |
<AktorPipeline/> | |
<!-- pure functions --> | |
<Funk superClass="script"> | |
<FunkOne/> | |
<FunkTwo/> | |
<FunkThree/> | |
<FunkFour/> | |
<FunkFive/> | |
<FunkSix/> | |
<FunkSeven/> | |
<FunkEight/> | |
<FunkNine/> | |
</Funk> | |
<Aktor superClass="script"> | |
<AktorUn/> | |
<AktorDeux/> | |
<AktorTrois/> | |
</Aktor> | |
</_-.XholonClass> | |
<xholonClassDetails> | |
<Avatar><Color>red</Color></Avatar> | |
</xholonClassDetails> | |
<PhysicalSystem> | |
<!-- a functional pipeline consisting of Funk/Behavior nodes; nodes return a single result value --> | |
<FunkPipeline> | |
<!-- usage: funkone = temp0; funkone.tick(5); // 10 --> | |
<FunkOne><![CDATA[ | |
var beh = {tick: function(obj) { | |
var one = obj + 2; | |
return one; // this is traditiobnally functional because it returns a result | |
}} | |
//# sourceURL=FunkOne.js | |
]]> | |
</FunkOne> | |
<FunkTwo><![CDATA[ | |
var beh = {tick: function(obj) { | |
var two = obj + 3; | |
return two; | |
}} | |
//# sourceURL=FunkTwo.js | |
]]> | |
</FunkTwo> | |
<FunkThree><![CDATA[ | |
var beh = {tick: function(obj) { | |
return obj; | |
}} | |
//# sourceURL=FunkThree.js | |
]]> | |
</FunkThree> | |
</FunkPipeline> | |
<!-- a non-functional pipeline consisting of Aktor nodes; nodes send the result on to the next function --> | |
<AktorPipeline> | |
<AktorUn><![CDATA[ | |
var beh = {tick: function(obj) { | |
var result = obj + 2; | |
//console.log(this.cnode); | |
this.cnode["bpx"].tick(result); | |
}} | |
//# sourceURL=AktorUn.js | |
]]> | |
</AktorUn> | |
<AktorDeux><![CDATA[ | |
var beh = {tick: function(obj) { | |
var result = obj + 3; | |
//console.log(this.cnode); | |
this.cnode["bpx"].tick(result); | |
}} | |
//# sourceURL=AktorDeux.js | |
]]> | |
</AktorDeux> | |
<AktorTrois><![CDATA[ | |
var beh = {tick: function(obj) { | |
this.cnode.println("obj: " + obj); | |
}} | |
//# sourceURL=AktorTrois.js | |
]]> | |
</AktorTrois> | |
</AktorPipeline> | |
<!-- | |
TODO: work on designing a bplex mechanism | |
bplexName: name of the outgoing port in each node that belongs to the bplex | |
funcName: tick, msg, call, action, etc. | |
type: chain, cycle | |
nodeType: function, actor | |
direction: l2r (pipe), r2l (compose) | |
ramda: true, false (whether or not to use Ramda if it's available | |
Notes: | |
If the bplex, as in this example, is implemented using a JavaScript array, and if the nodeType is function, then the nodes do NOT need to contain ports that reference each other | |
- the array contains a reference to each node, and the array already has an order accessible using an array index | |
If the nodeType is actor, then the chain or cycle is already implemented using a linked list through ports, so an array is unnecessary | |
Could also specify whether to implement the List of nodes, (1) using an array, or (2) using a linkedList (ports), or (3) as a collection of Xholon siblings (perhaps specify that the start and end of a range of siblings) | |
dataStruct: array, linkedlist, siblings | |
--> | |
<bplex bplexName="bpx" funcName="tick" type="chain" nodeType="actor" dataStruct="linkedlist" direction="l2r" ramda="false"> | |
<Attribute_String roleName="nodeList"> | |
../AktorPipeline/AktorUn, ../AktorPipeline/AktorDeux, ../AktorPipeline/AktorTrois | |
</Attribute_String> | |
<script> | |
var bplex = this.parent(); | |
this.println("bplex " + bplex); | |
var text = bplex.first().remove().text(); | |
this.println(text); | |
var xparr = text.trim().split(","); | |
var $this = this; | |
if (bplex.dataStruct == "array") { | |
bplex[bplex.bplexName] = []; | |
} | |
var prevNode = null; | |
xparr.forEach(function(item) { | |
var xpathExpr = item.trim(); | |
$this.println(xpathExpr); | |
var node = bplex.xpath(xpathExpr); | |
$this.println(node); | |
if (bplex.dataStruct == "array") { | |
bplex[bplex.bplexName].push(node); | |
} | |
else if (bplex.dataStruct == "linkedlist") { | |
if (prevNode) { | |
prevNode[bplex.bplexName] = node; | |
} | |
else { | |
bplex[bplex.bplexName] = node; // the head of the list | |
} | |
prevNode = node; | |
} | |
}) | |
//# sourceURL=bplexInitScript.js | |
</script> | |
</bplex> | |
</PhysicalSystem> | |
<FunkPipelinebehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
var me, beh = { | |
postConfigure: function() { | |
me = this.cnode.parent(); | |
me.println(me.name()); | |
this.cnode.remove(); | |
this.makeBplex("bpf"); // build a bplex cycle called "bpf" | |
}, | |
makeBplex: function(bplexName) { | |
me.println(me.name()); | |
var bplex = me; | |
me.println(bplex.name()); | |
var node = bplex.first(); | |
while (node) { | |
var nnode = node.next(); | |
if (nnode) { | |
node[bplexName] = nnode; | |
} | |
else { | |
node[bplexName] = bplex.first(); | |
} | |
node = nnode; | |
} | |
} | |
} | |
//# sourceURL=FunkPipelinebehavior.js | |
]]></FunkPipelinebehavior> | |
<bplexbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
// temp0["tick"](123); // works | |
var bplex, beh = { | |
postConfigure: function() { | |
bplex = this.cnode.parent(); | |
bplex.println(this.cnode.name() + " " + bplex.name()); | |
}, | |
act: function() { | |
// testing the bplex | |
switch(bplex.nodeType) { | |
case "actor": this.doActorChain(); break; | |
case "function": this.doFunctionChain(); break; | |
default: break; | |
} | |
}, | |
doFunctionChain: function() { | |
var inval = 1; | |
var outval = bplex[bplex.bplexName][0].tick(inval); | |
bplex.println("" + inval + " -> " + outval); | |
}, | |
doActorChain: function() { | |
var inval = 1; | |
switch (bplex.funcName) { | |
case "tick": bplex[bplex.bplexName].tick(inval); break; | |
case "msg": bplex[bplex.bplexName].msg(101, inval, bplex); break; | |
case "call": bplex[bplex.bplexName].call(102, inval, bplex); break; | |
default: break; | |
} | |
}, | |
} | |
//# sourceURL=bplexbehavior.js | |
]]></bplexbehavior> | |
<NOAktorPipelinebehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
// I have changed the name of this element, so it won't be used | |
var me, beh = { | |
postConfigure: function() { | |
me = this.cnode.parent(); | |
me.println(me.name()); | |
this.cnode.remove(); | |
this.makeBplex("bpa"); // build a bplex cycle called "bpa" | |
}, | |
makeBplex: function(bplexName) { | |
me.println(me.name()); | |
var bplex = me; | |
me.println(bplex.name()); | |
var node = bplex.first(); | |
while (node) { | |
var nnode = node.next(); | |
if (nnode) { | |
node[bplexName] = nnode; | |
} | |
else { | |
node[bplexName] = bplex.first(); | |
} | |
node = nnode; | |
} | |
} | |
} | |
//# sourceURL=AktorPipelinebehavior.js | |
]]></NOAktorPipelinebehavior> | |
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml, | |
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg"> | |
<g> | |
<title>FunkPipeline</title> | |
<rect id="PhysicalSystem/FunkPipeline" fill="#98FB98" height="50" width="50" x="25" y="0"/> | |
</g> | |
</svg> | |
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient> | |
</XholonWorkbook> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment