Last active
June 3, 2018 19:06
-
-
Save kenwebb/551f89589af35bf0a664d3c7705dab3c to your computer and use it in GitHub Desktop.
Recipes - Data Structures
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, Sun Jun 03 2018 15:05:30 GMT-0400 (EDT)--> | |
<XholonWorkbook> | |
<Notes><![CDATA[ | |
Xholon | |
------ | |
Title: Recipes - Data Structures | |
Description: | |
Url: http://www.primordion.com/Xholon/gwt/ | |
InternalName: 551f89589af35bf0a664d3c7705dab3c | |
Keywords: | |
My Notes | |
-------- | |
June 3, 2018 | |
Pass data structures in messages between Xholon Active Objects. | |
Types of structures: | |
1. list, array, JSON with optional hierarchy, CSV | |
2. stack | |
- push once for each output port instance | |
- pop once for each input port instance | |
JavaScript Array can function as an indexed list, or as a stack (LIFO), or as a queue (FIFO) | |
Note that a stack is typically used to pass variables between functions in many computer programming languages. | |
- call stack pointer | |
TODO list based | |
--------------- | |
- with a simple list, it's hard for a receiver to know what to take | |
- or maybe just take what they need and remove it | |
- alternatively, use a JSON structure with named objects | |
TODO | |
---- | |
- think about all the separate things going on, and how to really separate them into different concerns | |
- timing: how do different approaches in Cat Theory and Xholon deal with timing | |
- ex: EFLang uses "wait", Cat Theory can use "identity" | |
- Pawel's horizontal and vertical organization | |
- or just do an action when all the resources/inputs are ready | |
- what is the most basic way to think about each concern/aspect | |
TODO | |
---- | |
- put the behaviors directly into the Generators, so no one will have to see Generatorbuilder nodes | |
References | |
---------- | |
(1) https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics) | |
FIFO | |
FIFO is an acronym for first in, first out, a method for organizing and manipulating a data buffer, where the oldest (first) entry, or 'head' of the queue, is processed first. | |
It is analogous to processing a queue with first-come, first-served (FCFS) behaviour: where the people leave the queue in the order in which they arrive. | |
(2) https://en.wikipedia.org/wiki/Stack_(abstract_data_type) | |
LIFO | |
In computer science, a stack is an abstract data type that serves as a collection of elements, with two principal operations: | |
push, which adds an element to the collection, and | |
pop, which removes the most recently added element that was not yet removed. | |
The order in which elements come off a stack gives rise to its alternative name, LIFO (last in, first out). | |
Additionally, a peek operation may give access to the top without modifying the stack. | |
The name "stack" for this type of structure comes from the analogy to a set of physical items stacked on top of each other, | |
which makes it easy to take an item off the top of the stack, while getting to an item deeper in the stack may require taking off multiple other items first. | |
(3) https://en.wikipedia.org/wiki/List_of_data_structures | |
]]></Notes> | |
<params> | |
<param name="MaxPorts" value="5"/> | |
</params> | |
<_-.XholonClass> | |
<PhysicalSystem/> | |
<Recipe/> | |
<Generator/> | |
</_-.XholonClass> | |
<xholonClassDetails> | |
<Recipe xhType="XhtypePureActiveObject"> | |
<port name="port" index="0" connector="Generator[1]"/> <!-- egg --> | |
<port name="port" index="1" connector="Generator[2]"/> <!-- egg --> | |
<port name="port" index="2" connector="Generator[4]"/> <!-- sugar --> | |
<port name="port" index="3" connector="Generator[5]"/> <!-- mascarpone --> | |
<Color>green</Color> | |
</Recipe> | |
<Generator xhType="XhtypePureActiveObject"> | |
<port name="port" index="0" connector=".[@roleName='Crack Egg']/../Generator[@roleName='Whisk']"/> | |
<port name="port" index="1" connector=".[@roleName='Crack Egg']/../Generator[@roleName='Beat']"/> | |
<port name="port" index="0" connector=".[@roleName='Whisk']/../Generator[@roleName='Fold']"/> | |
<port name="port" index="0" connector=".[@roleName='Beat']/../Generator[@roleName='Stir']"/> | |
<port name="port" index="0" connector=".[@roleName='Stir']/../Generator[@roleName='Fold']"/> | |
<port name="port" index="0" connector=".[@roleName='Fold']/.."/> | |
<Color>indigo</Color> | |
</Generator> | |
</xholonClassDetails> | |
<PhysicalSystem> | |
<Recipe roleName="list based"> | |
<Generator roleName="Crack Egg"/> | |
<Generator roleName="Crack Egg"/> | |
<Generator roleName="Whisk"/> | |
<Generator roleName="Beat"/> | |
<Generator roleName="Stir"/> | |
<Generator roleName="Fold"/> | |
</Recipe> | |
</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> | |
<Recipebehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
var me, rlist, beh = { | |
postConfigure: function() { | |
me = this.cnode.parent(); | |
rlist = ["egg","egg","sugar","mascarpone"]; | |
me.port(0).msg(101, rlist, me); | |
me.port(1).msg(102, rlist, me); | |
me.port(2).msg(103, rlist, me); | |
me.port(3).msg(104, rlist, me); | |
$wnd.xh.root().append(this.cnode.remove()); | |
}, | |
act: function() { | |
me.println("testing"); | |
} | |
} | |
//# sourceURL=Recipebehavior.js | |
]]></Recipebehavior> | |
<Generatorbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
var me, rlist, beh = { | |
postConfigure: function() { | |
me = this.cnode.parent(); | |
//$wnd.xh.root().append(this.cnode.remove()); | |
}, | |
processReceivedMessage: function(msg) { | |
me.println(me.name() + " received: " + msg.signal + "|" + msg.data); | |
switch (me.role()) { | |
case "Crack Egg": | |
// look for one egg in msg.data, remove the egg, and send msg white to Whisk and yolk to Beat | |
var ix = msg.data.indexOf("egg"); | |
if (ix != -1) { | |
msg.data.splice(ix, 1); // remove that one egg | |
msg.data.push("white"); | |
msg.data.push("yolk"); | |
me.port(0).msg(111, msg.data, me); | |
me.port(1).msg(112, msg.data, me); | |
} | |
break; | |
case "Whisk": | |
break; | |
case "Beat": | |
break; | |
case "Stir": | |
break; | |
case "Fold": | |
break; | |
default: break; | |
} | |
} | |
} | |
//# sourceURL=Generatorbehavior.js | |
]]></Generatorbehavior> | |
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml, | |
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg"> | |
<g> | |
<title>Block</title> | |
<rect id="PhysicalSystem/Block" fill="#98FB98" height="50" width="50" x="25" y="0"/> | |
<g> | |
<title>Height</title> | |
<rect id="PhysicalSystem/Block/Height" 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