summaryrefslogtreecommitdiff
path: root/nascent.js
diff options
context:
space:
mode:
authorKarl Semich <fuzzyTew@gmail.com>2019-10-16 16:45:39 -0400
committerKarl Semich <fuzzyTew@gmail.com>2019-10-16 16:45:39 -0400
commit7da8cc5684cd56616a7578756d40523973a608c9 (patch)
tree2e5292ccfbed0c03148e68ac88adc75467152399 /nascent.js
downloadstandingwithresilience-7da8cc5684cd56616a7578756d40523973a608c9.tar.gz
standingwithresilience-7da8cc5684cd56616a7578756d40523973a608c9.zip
simple code for functions that act on relevent data. if one codes it to run itself using relevence, it should grow if the relevence is fancy enough.
Diffstat (limited to 'nascent.js')
-rw-r--r--nascent.js107
1 files changed, 107 insertions, 0 deletions
diff --git a/nascent.js b/nascent.js
new file mode 100644
index 0000000..b6b5552
--- /dev/null
+++ b/nascent.js
@@ -0,0 +1,107 @@
+class ActiveMemory {
+ constructor() {
+ this.ram = []
+ this.cloned = false
+ }
+ clone() {
+ let ret = new ActiveMemory();
+ ret.ram = this.ram
+ ret.cloned = true
+ return ret
+ }
+ add(item) {
+ if (this.cloned) { this.ram = this.ram.slice(); this.cloned = false; }
+ this.ram.push(item)
+ }
+ del(item) {
+ if (this.cloned) { this.ram = this.ram.slice(); this.cloned = false; }
+ let index = this.ram.indexOf(item)
+ this.ram.splice(index, 1)
+ }
+ contains(item) {
+ for (let a of this.ram)
+ if (a == item) return a
+ return false
+ }
+ containsWith(prop, val) {
+ let ret = []
+ for (let a of this.ram)
+ if (a[prop] == val)
+ return true
+ return false
+ }
+ getWith(prop, val) {
+ let ret = []
+ //console.log('get-with ' + prop + ' ' + val)
+ for (let a of this.ram) {
+ //console.log(a + ' ' + prop + ' is ' + a[prop])
+ if (a[prop] == val)
+ ret.push(a)
+ }
+ if (ret.length > 0) return ret
+ return null
+ }
+}
+
+function sayhi() {
+ res = 'hi'
+ res.use = 'output'
+ console.log(res)
+ return 'said ' + res
+}
+sayhi.relevence = function(ram) {
+ return [ram.ram[0]];
+}
+
+function line2words(line) {
+ let res = line.split(' ')
+ res.type = 'list'
+ return res
+}
+line2words.relevence = function(ram) {
+ return ram.getWith('type', 'text')
+}
+
+all_parts = [ line2words, sayhi ]
+
+ram = new ActiveMemory()
+optstried = new Set()
+steps = []
+
+var readline = require('readline')
+readline.createInterface({
+ input: process.stdin
+}).on('line', (line) => {
+ line = new String(line)
+ line.use = 'input'
+ line.type = 'text'
+ ram.add(line)
+
+ let cont
+ do {
+ cont = false
+ for (let part of all_parts) {
+ //console.log('for-loop-of-parts ' + part.name)
+ let rel = part.relevence(ram)
+ if (rel) {
+ for (let a of rel) {
+ //console.log('for-loop-of-rel ' + part.name + ' ' + a)
+ if (optstried.has(part.name + ' ' + a)) continue;
+ //console.log('call-part ' + part.name + ' ' + a)
+ res = part(a)
+ //console.log('part-called')
+ step = [a, part.name, res]
+ steps.push(step)
+ console.log('made ' + step)
+ cont = true
+ optstried.add(part.name + ' ' + a)
+
+ }
+ }
+ //if (rel) {
+ // let ram2 = ram.clone()
+ // for
+ //}
+ }
+ } while (cont)
+})