Last active
December 15, 2025 17:40
-
-
Save kenwebb/4e8563ff391e77e2029c8da3450e2d37 to your computer and use it in GitHub Desktop.
Simplicity copy-on-write
This file contains hidden or 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 Dec 15 2025 12:40:08 GMT-0500 (Eastern Standard Time)--> | |
| <XholonWorkbook> | |
| <Notes><![CDATA[ | |
| Xholon | |
| ------ | |
| Title: Simplicity copy-on-write | |
| Description: | |
| Url: http://www.primordion.com/Xholon/gwt/ | |
| InternalName: 4e8563ff391e77e2029c8da3450e2d37 | |
| Keywords: | |
| My Notes | |
| -------- | |
| 2025 Dec 15 | |
| Experiment with concepts in ref[1], especially copy-on-write (COW) in chapter 6. | |
| ### References | |
| (1) Eric Normand, grokking Simplicity, 2021 - chapter 6 | |
| chapter 6 - Staying immutable in a mutable labguage | |
| shopping cart operations using a copy-on-write discipline | |
| three steps: | |
| 1. Make a copy | |
| 2. Modify the copy (as much as you want) | |
| 3. Return the copy | |
| () | |
| ]]></Notes> | |
| <_-.XholonClass> | |
| <PhysicalSystem/> | |
| <Cow superClass="Script"/> | |
| </_-.XholonClass> | |
| <xholonClassDetails> | |
| <Cow><Color>orange</Color></Cow> | |
| <Avatar><Color>red</Color></Avatar> | |
| </xholonClassDetails> | |
| <PhysicalSystem> | |
| <Cow roleName="aldebaran"><![CDATA[ | |
| var me, shoppingCart, count, beh = { | |
| postConfigure: function() { | |
| me = this.cnode; | |
| shoppingCart = [ | |
| {name: "bread", price: 12.34}, | |
| {name: "broccoli", price: 5.66} | |
| ]; | |
| count = 0; | |
| }, | |
| act: function() { | |
| me.println(me.name() + " " + JSON.stringify(shoppingCart)); | |
| switch (count) { | |
| case 0: | |
| shoppingCart = this.remove_item_by_name(shoppingCart, "broccoli"); | |
| shoppingCart = this.add_item(shoppingCart, {name: "bananas", price: 0.33}); | |
| break; | |
| case 1: | |
| shoppingCart = this.remove_item_by_name(shoppingCart, "bread"); | |
| break; | |
| default: break; | |
| } | |
| count++; | |
| }, | |
| remove_item_by_name: function(cart, name) { | |
| // this is how the function is coded on p. 117 of the book | |
| var new_cart = cart.slice(); | |
| var idx = null; | |
| for (var i = 0; i < new_cart.length; i++) { | |
| if (new_cart[i].name === name) | |
| idx = i; | |
| } | |
| if (idx !== null) | |
| new_cart.splice(idx, 1); | |
| return new_cart; | |
| }, | |
| add_item: function(cart, item) { | |
| // this is my function | |
| var new_cart = cart.slice(); | |
| new_cart.push(item); | |
| return new_cart; | |
| } | |
| } | |
| //# sourceURL=aldebaran.js | |
| ]]></Cow> | |
| <Cow roleName="betelgeuse"><![CDATA[ | |
| var me, shoppingCart, beh = { | |
| postConfigure: function() { | |
| me = this.cnode; | |
| shoppingCart = [ | |
| {name: "tomatoes", price: 12.02}, | |
| {name: "potatoes", price: 5.01} | |
| ]; | |
| }, | |
| act: function() { | |
| me.println(me.name() + " " + JSON.stringify(shoppingCart)); | |
| } | |
| } | |
| //# sourceURL=betelgeuse.js | |
| ]]></Cow> | |
| </PhysicalSystem> | |
| <SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml, | |
| <svg width="100" height="50" xmlns="http://www.w3.org/2000/svg"> | |
| <g> | |
| <title>Cow</title> | |
| <rect id="PhysicalSystem/Cow" fill="#98FB98" height="50" width="50" x="25" y="0"/> | |
| <g> | |
| <title>Cow</title> | |
| <rect id="PhysicalSystem/Cow" 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