Last active
March 16, 2020 11:03
-
-
Save kenwebb/568ffc4faf650b8e8ef4317bc0bc561b to your computer and use it in GitHub Desktop.
Xholon Visit - experiments
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, Mon Mar 16 2020 07:02:21 GMT-0400 (Eastern Daylight Time)--> | |
<XholonWorkbook> | |
<Notes><![CDATA[ | |
Xholon | |
------ | |
Title: Xholon Visit - experiments | |
Description: | |
Url: http://www.primordion.com/Xholon/gwt/ | |
InternalName: 568ffc4faf650b8e8ef4317bc0bc561b | |
Keywords: | |
My Notes | |
-------- | |
March 14, 2020 | |
Xholon nodes provide a visit method, which I experiment with in this workbook. | |
I believe that visit is similar to some basic functional programming concepts. | |
See VisitTest.js, and pages in my notebook from March 12+ (Visitor + Map, Reduce). | |
To get access to xhmath JavaScript library: | |
http://127.0.0.1:8888/XholonXhmath.html?app=Xholon+Visit+-+experiments&src=lstr&gui=clsc | |
References | |
---------- | |
(1) search: visitor pattern, visitor pattern hierarchical, visitor pattern map reduce | |
() | |
]]></Notes> | |
<_-.XholonClass> | |
<PhysicalSystem/> | |
<Block/> | |
<Brick/> | |
<!-- quantities --> | |
<Height superClass="Quantity"/> | |
<VisitTest superClass="script"/> | |
<Example/> | |
<!-- Haskell --> | |
<foldl superClass="script"/> | |
<foldr superClass="script"/> | |
<!-- examples from Hutton Haskell book, p. 66+ --> | |
<product superClass="foldr"/> | |
<drop superClass="script"/> | |
</_-.XholonClass> | |
<xholonClassDetails> | |
<Block> | |
<port name="height" connector="Height"/> | |
</Block> | |
</xholonClassDetails> | |
<PhysicalSystem> | |
<Example roleName="one"> | |
<Block> | |
<Height>0.1 m</Height> | |
</Block> | |
<Brick multiplicity="2"/> | |
<VisitTest roleName="eins"><![CDATA[ | |
var me, count, arr, testing; | |
var beh = { | |
postConfigure: function() { | |
me = this.cnode.parent(); | |
testing = Math.floor(Math.random() * 10); | |
count = 0; | |
me.length = 0; // makes me somewhat array-like | |
arr = []; | |
me.visit(this.cnode); | |
//this.cnode.remove(); | |
}, | |
act: function() { | |
me.println(this.toString()); | |
}, | |
visit: function(visitor) { | |
//me.println("visited by " + visitor); | |
this.doReduceCount(); | |
this.doReduceLength(); | |
this.doMapArrIXholon(visitor); | |
return true; | |
}, | |
doReduceCount: function() { | |
count++; | |
}, | |
doReduceLength: function() { | |
me.length++; | |
}, | |
doMapArrIXholon: function(visitor) { | |
arr.push(visitor.name()); | |
}, | |
// testing:6 count:3 arr:helloWorldSystem_0,hello_2,world_3 | |
toString: function() { | |
return "testing:" + testing + " count:" + count + " arr:" + arr; | |
} | |
} | |
//# sourceURL=eins.js | |
]]></VisitTest> | |
</Example> | |
<Example roleName="two"> | |
<Block multiplicity="5"/> | |
<!-- count, 0 --> | |
<VisitTest roleName="zwei" initval="0"><![CDATA[ | |
var vstee, count; | |
var beh = { | |
postConfigure: function() { | |
vstee = this.cnode; | |
vstee.println(vstee); | |
vstee.println(vstee.initval); | |
count = vstee.initval; | |
this.cnode.parent().visit(vstee); | |
vstee.println(vstee.name() + " count: " + count); | |
this.cnode.remove(); | |
}, | |
visit: function(visitor) { | |
vstee.println(vstee.name() + " was visited by " + visitor); | |
count++; | |
return true; | |
} | |
} | |
//# sourceURL=zwei.js | |
]]></VisitTest> | |
</Example> | |
<Example roleName="three"> | |
<Block multiplicity="41"/> | |
<?xhmath.pSet01 {One, Two, Three, Four, Five}?> | |
<?xhmath.pSiblings01 | |
nodes = {0,1,2} | |
roles = {A,B,C} | |
roleMapping = {(0,A), (1,B), (2,C)} | |
typeMapping = {(0,Attribute_int), (1,Attribute_int), (2,Attribute_int)} | |
vals = {1,2,3} | |
valMapping = {(0,1), (1,2), (2,4)} | |
?> | |
<?xhmath.pSiblings01 | |
nodes = {0,1,2} | |
roles = {D,E,F} | |
roleMapping = {(0,D), (1,E), (2,F)} | |
typeMapping = {(0,Attribute_String), (1,Attribute_String), (2,Attribute_String)} | |
texts = {summer,winter,spring} | |
textMapping = {(0,summer), (1,winter), (2,spring)} | |
?> | |
<!-- minimal amount of code; Note: 0 is the unit for addition (count) n + 0 = n; count :: [Int] -> Int --> | |
<VisitTest roleName="drei" unit="0"><![CDATA[ | |
var vstee, beh = { | |
postConfigure: function() { | |
vstee = this.cnode; | |
vstee.count = vstee.unit; | |
vstee.parent().visit(vstee); | |
vstee.println(vstee.name() + " count: " + vstee.count).remove(); | |
}, | |
visit: function(vstr) { | |
vstee.count++; | |
return true; | |
} | |
} | |
]]></VisitTest> | |
</Example> | |
<Example roleName="four"> | |
<Attribute_int>1</Attribute_int> | |
<Attribute_int>2</Attribute_int> | |
<Attribute_int>3</Attribute_int> | |
<!-- Hutton Haskell example | |
- - initial type definition | |
product :: [Int] -> Int | |
- - final definition | |
product :: Num a => [a] -> a | |
product = foldr (*) 1 | |
- - Note: 1 is the unit for multiplication (product) n * 1 = n | |
--> | |
<product roleName="vier" unit="1"><![CDATA[ | |
var vstee, beh = { | |
postConfigure: function() { | |
vstee = this.cnode; | |
vstee.product = vstee.unit; | |
vstee.parent().visit(vstee); | |
vstee.println(vstee.name() + " product: " + vstee.product).remove(); | |
}, | |
visit: function(vstr) { | |
if (vstr != vstee.parent()) { | |
vstee.print(vstee.product + " * " + vstr.val() + " = "); | |
vstee.product *= vstr.val(); | |
vstee.println(vstee.product); | |
} | |
return true; | |
} | |
} | |
]]></product> | |
</Example> | |
<Example roleName="five"> | |
<Block multiplicity="10"/> | |
<script> | |
this.println("SCRIPT"); | |
this.println(this.name()); | |
this.println(this.prev().name()); | |
this.next().tick(this.parent()); | |
this.next().remove(); | |
</script> | |
<!-- Hutton Haskell example | |
- - initial type definition | |
drop :: Int -> [a] -> [a] | |
- - final definition | |
drop :: Int -> [a] -> [a] | |
drop 0 xs = xs | |
drop _ [] = [] | |
drop n (_:xs) = drop (n-1) xs | |
- - Note: [] is the unit for arrays | |
--> | |
<drop roleName="funf" n="3" unit="[]"><![CDATA[ | |
var vstee, counter, arr, beh = { | |
postConfigure: function() { | |
vstee = this.cnode; | |
counter = vstee.n; // countdown counter | |
arr = JSON.parse(vstee.unit); | |
//vstee.parent().visit(vstee); | |
//vstee.println(vstee.name() + " n:" + vstee.n + " arr:" + JSON.stringify(arr)); //.remove(); | |
}, | |
tick: function(node) { | |
vstee.println("TICK"); | |
node.visit(vstee); | |
vstee.println(vstee.name() + " n:" + vstee.n + " arr:" + JSON.stringify(arr)); //.remove(); | |
return arr; | |
}, | |
visit: function(vstr) { | |
if (vstr != vstee.parent()) { | |
if (counter == 0) { | |
arr.push(vstr.name()); | |
} | |
else { | |
counter--; // ignore the first n visitors | |
} | |
} | |
return true; | |
} | |
} | |
]]></drop> | |
</Example> | |
</PhysicalSystem> | |
<Blockbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
var a = 123; | |
var b = 456; | |
var c = a * b; | |
if (console) { | |
console.log(c); | |
} | |
//# sourceURL=Blockbehavior.js | |
]]></Blockbehavior> | |
<Heightbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
var myHeight, testing; | |
var beh = { | |
postConfigure: function() { | |
testing = Math.floor(Math.random() * 10); | |
myHeight = this.cnode.parent(); | |
}, | |
act: function() { | |
myHeight.println(this.toString()); | |
}, | |
toString: function() { | |
return "testing:" + testing; | |
} | |
} | |
//# sourceURL=Heightbehavior.js | |
]]></Heightbehavior> | |
<Brickbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
$wnd.xh.Brickbehavior = function Brickbehavior() {} | |
$wnd.xh.Brickbehavior.prototype.postConfigure = function() { | |
this.brick = this.cnode.parent(); | |
this.iam = " red brick"; | |
}; | |
$wnd.xh.Brickbehavior.prototype.act = function() { | |
this.brick.println("I am a" + this.iam); | |
}; | |
//# sourceURL=Brickbehavior.js | |
]]></Brickbehavior> | |
<Brickbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
console.log("I'm another brick behavior"); | |
]]></Brickbehavior> | |
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml, | |
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg"> | |
<g> | |
<title>Example</title> | |
<rect id="PhysicalSystem/Example" fill="#98FB98" height="50" width="50" x="25" y="0"/> | |
<g> | |
<title>Block</title> | |
<rect id="PhysicalSystem/Example/Block" fill="#6AB06A" height="50" width="10" x="80" y="0"/> | |
</g> | |
</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