Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active November 8, 2019 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenwebb/cb6f9a36070d1beab8a7ac8793146059 to your computer and use it in GitHub Desktop.
Save kenwebb/cb6f9a36070d1beab8a7ac8793146059 to your computer and use it in GitHub Desktop.
Challenge: Empty Set -> Open World
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Fri Nov 08 2019 18:38:21 GMT-0500 (Eastern Standard Time)-->
<XholonWorkbook>
<Notes><![CDATA[
constructXholon
------
Title: Challenge: Empty Set -> Open World
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: cb6f9a36070d1beab8a7ac8793146059
Keywords:
My Notes
--------
November 4, 2019
In this workbook I explore aspects of the challenge:
How to construct an Open World game/application starting with just an Empty Set.
See my notebook for November 2 +.
I will use standard JavaScript with no third-party libraries, to represent Set objects.
Code I can run from Dev Tools at timestep 0
-------------------------------------------
var outsider = temp0;
var arr = outsider.swirl;
var ix = 0;
console.log(arr.length); // 11
console.log(arr[ix]); // Object ...
console.log(arr[ix].name()); // "block_49"
console.log(arr[ix].first().name()); // "avatar_42"
var ava = arr[ix].first();
console.log(ava.name()); // "avatar_42"
console.log(ava.parent().name()); // "block_49"
ava.action("step");
arr[ix+1].append(arr[ix].first().remove());
console.log(arr); // Array ...
ix++;
console.log(ava.name()); // "avatar_42"
console.log(ava.parent().name()); // "block_51"
The Avatar cannot move from one array slot to another.
It knows nothing about the sort of space/universe (the array) in which it lives.
The above code DOES know about the array, so it can move the Avatar.
The Avatar does not share the Outsider's external (outside, extrinsic) view.
Structure
---------
Outsider
--- ----- ----- ----- ----- --- swirl --- ----- ----- ----- ----- ---
Block Block Block Block Block Block Block Block Block Block
Avatar
subtrees
BehaviorsST
beh1
...
behN
MathObjectsST
Blocks
Block1001
...
Block1012
SubtreesReporter
----------------
Use script SubtreesReporter to show the Avatar subtrees structure. Result:
avatar_42 has subtrees
BehaviorsST true
beh4_73
beh3_74
script_75
script_76
MathObjectsST true
blocks_79
block_57
block_59
block_53
block_65
block_61
To add a new BehaviorsST behavior at runtime (from Dev Tools)
--------------------------------------------
xh.avatar().subtrees.BehaviorsST.append('<script>var me, ava, beh = {postConfigure: function() {me = this.cnode; me.println("BEH998");}, act: function() {me.println("Hello from BehaviorsST BEH998");}}</script>');
OR
xh.avatar().subtrees.BehaviorsST.append(`<script>
var me, ava, beh = {
postConfigure: function() {
me = this.cnode; me.println("BEH999");
},
act: function() {
me.println("Hello from BehaviorsST BEH999");
}
}
</script>`);
References
----------
(1) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
(2) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
(3) https://stackoverflow.com/questions/20069828/how-to-convert-set-to-array
Indeed, there are several ways to convert a Set to an Array:
using Array.from
let array = Array.from(mySet);
Simply spreading the Set out in an array
let array = [...mySet];
The old fashion way, iterating and pushing to a new array (Sets do have forEach)
let array = [];
mySet.forEach(v => array.push(v));
(4) https://gist.github.com/kenwebb/6871e23c1eae1895b65c535a8d21c1d7
Mathematical Object
March 13, 2019
How should I think about mathematical objects, and how can I implemnt them in Xholon?
In this workbook, I want to be using only a programming analog of "mathematical objects".
uses XholonNull
(5) https://gist.github.com/kenwebb/d05acfc56798ee0a33470d2cac85b27f
A more flexible Xholon
October 10, 2017
see my notebook Oct 8
Xholon re-imagined, using ideas from Category Theory (CT), Set Theory, Bigraphs, etc.
I'm trying to simulate some new insights into how a Xholon app might be implemented, by simulating the ideas using Xholon.
(6) Erica Flapan, Knots, Molecules, and the Universe: An Introduction to Topology, 2017
idea of inside vs outside view; intrinsic and extrinsic
(7) https://en.wikipedia.org/wiki/Open_world
Open World
In video games, an open world is a virtual world in which the player can explore and approach objectives freely, as opposed to a world with more linear and structured gameplay.
(8) wikipedia Ring World
]]></Notes>
<_-.XholonClass>
<PhysicalSystem/>
<!-- a vaguely-defined entity that lives outside the swirl, outside what the Avatar can access -->
<Outsider/>
<!-- things that can exist inside the swirl -->
<XholonNull>
<Block/>
</XholonNull>
<!-- the root of a Xholon subtree where Avatar can cache Block nodes that it learns about -->
<Blocks/>
<!--<Beh3 superClass="script"/>-->
<Script>
<Beh3/>
<Beh4/>
<Beh5/>
</Script>
</_-.XholonClass>
<xholonClassDetails>
<Beh3><DefaultContent><![CDATA[
var me, ava, beh = {
postConfigure: function() {
me = this.cnode;
me.println("BEH333");
},
act: function() {
me.println("Hello from BehaviorsST Beh3");
}
}
]]></DefaultContent></Beh3>
<Beh4><DefaultContent><![CDATA[
var me, ava, beh = {
postConfigure: function() {
me = this.cnode;
me.println("BEH444");
}
}
]]></DefaultContent></Beh4>
</xholonClassDetails>
<PhysicalSystem>
<Outsider/>
</PhysicalSystem>
<Outsiderbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
/**
* How I might construct an initial Empty Set or non-empty set.
* I use a combination of JavaScript Array and Set.
* I use JavaScript Set as an intermediary, to ensure that all elements in the set are unique, as per the Math (Set Theory) definition of a Set.
* I prefer the flexibility and simplicity of a basic JavaScript Array, once I have ensured that all elements are unique.
* Note: Even if the resulting Array is a const, the contents of the Array can still be changed. The contents of the Array are not immutable.
* Note: Unlike a Math Set, a JavaScript Set is ordered by its insertion order.
*/
const emptyset = new Set();
console.log(emptyset);
this.println(emptyset);
const arr = [1, 3, 5, 5, 7]; // 5 is duplicated
console.log(arr);
this.println(arr);
const set = new Set(arr);
console.log(set);
this.println(set);
// Two ways to convert Set to Array.
const aout1 = Array.from(set);
console.log(aout1);
this.println(aout1);
const aout2 = [...set];
console.log(aout2);
this.println(aout2);
// Insert a new item into the const Array.
aout2.push(9);
console.log(aout2);
this.println(aout2);
//# sourceURL=Outsiderbehavior.js
]]></Outsiderbehavior>
<Outsiderbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
console.log(this);
// from ref 4
// create and examine a single instance of Block
const NUM_NODES = 10;
const root = $wnd.xh.root();
const arr = [];
// XholonNull.java is a concrete Java class. An instance of Block (XholonNull) is as minimal a Xholon node as can be created.
// is this instance of Block a mathematical object?
// is the array that it's inside of a mathematical object?
arr.push(root.append("<Block></Block>").last().remove());
console.log(arr);
// add more nodes to the array
for (var i = 0; i < NUM_NODES; i++) {
arr.push(root.append("<Block></Block>").last().remove());
}
this.println(arr.length); // 11
// place the system Avatar inside the first instance of Block
const ava = $wnd.xh.avatar();
ava.action("param shouldstep true;");
arr[0].append(ava);
ava.action("script;\nwho;\nwhere;\nlook;\nnext;\nprev;\nenter;\nexit;\nwhere;\nwhere;\nwhere;\nwhere;\nwhere;\nwhere;"); // You are the system Avatar avatar_42.You are in bloch_49.You are in block_49.
// Store the Array as an object inside the Outsider node, so I can access it later.
// I think that "swirl" is a good name for the array. It captures the idea of uncertainty and impermanence surrounding the structure and its elements.
// The swirl exists between the outside and the inside.
// Note: This Outsiderbehavior node will be automatically removed after executing this code, because it's not part of a beh object.
this.parent().swirl = arr;
console.log(this.parent());
//# sourceURL=Outsiderbehavior2.js
]]></Outsiderbehavior>
<Outsiderbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var me, ava, swirl, beh = {
postConfigure: function() {
me = this.cnode;
me.println("Outsiderbehavior3");
me.println(me.name());
ava = $wnd.xh.avatar();
var beh1 = `
/**
* Label the Block nodes.
* In Math, labels are optional. They can be added to help people distinguish between nodes.
* We could use Xholon id() or role().
*/
const LABEL_INIT = 1001;
var me, ava, label, beh = {
postConfigure: function() {
console.log("Hello from BehaviorsST beh1");
me = this.cnode;
me.println("ob1: " + this);
me.println("ob2: " + me.name()); // ob2: script_73
me.println("ob3: " + me.parent().name()); // ob3: behaviorsST_72
ava = me.parent().parent();
me.println("ob4:" + ava.first());
label = LABEL_INIT;
},
act: function() {
me.println("ob11: " + me.parent().name()); // ob4: behaviorsST_72
me.println("ob12: " + ava.name()); // ob5: avatar_42
me.println("ob4: " + ava.first());
// give the block node a new label/id
var avaCtxt = ava.parent();
//if (LABEL_INIT > avaCtxt.id()) {
// avaCtxt._id(label++);
//}
if (!avaCtxt.xhmath) {
avaCtxt.xhmath = {};
}
if (!avaCtxt.xhmath.label) {
avaCtxt.xhmath.label = label++;
}
me.println("ob5: " + label);
}
}`;
var beh2 = `
/**
* Build a connected structure that includes all the Block nodes that I know about.
* Save them as a single-linked list within a single container, a simple Xholon subtree.
*/
var me, ava, blocks, blocksSet, beh = {
postConfigure: function() {
console.log("Hello from BehaviorsST beh2");
me = this.cnode;
ava = me.parent().parent();
//me.append("&lt;Blocks/>");
//blocks = me.last().remove();
//blocks = ava.subtrees.MathObjectsST.first();
blocks = null;
blocksSet = new Set(); // use this JS Set to efficiently keep track of which blocks have been added to the Xholon subtree
},
act: function() {
me.println("Hello from BehaviorsST beh2");
if (blocks == null) {
blocks = ava.subtrees.MathObjectsST.first();
}
me.println(blocks.name());
var avaCtxt = ava.parent();
if (!blocksSet.has(avaCtxt)) {
blocksSet.add(avaCtxt);
blocks.append(avaCtxt);
console.log(blocks);
}
me.println("blocksSet size: " + blocksSet.size);
}
}`;
// beh1 and beh2 need to be specified in reverse order; beh2 before beh1
ava.append('<BehaviorsST>'
+ '<Beh4></Beh4>'
+ '<Beh3></Beh3>'
+ '<script>' + beh2 + '</script>'
+ '<script>' + beh1 + '</script>'
+ '</BehaviorsST>');
ava.append('<MathObjectsST>' + '<Blocks/>' + '</MathObjectsST>');
ava.action('param subtrees true BehaviorsST,MathObjectsST'); // this line is needed, and it must come after ava.append()
//console.log(ava);
swirl = me.parent().swirl;
},
act: function() {
console.log(ava);
var block = swirl[Math.floor(Math.random() * swirl.length)];
me.println(block.name());
block.append(ava.remove());
}
}
//# sourceURL=Outsiderbehavior3.js
]]></Outsiderbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Outsider</title>
<rect id="PhysicalSystem/Outsider" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>Outsider child</title>
<rect id="PhysicalSystem/Outsider/*" 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