summaryrefslogtreecommitdiff
path: root/intellect-framework-from-internet/starts/bagel/nascent1.js
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2020-01-10 14:55:19 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2020-01-10 14:55:19 -0800
commitc8bb547bea279af2bb48c13260f98aa8add07131 (patch)
tree7f64265d514dc50427d2e5d8a70e09a46927dfbd /intellect-framework-from-internet/starts/bagel/nascent1.js
parent5601d1f3324c30651ad3f264ac2d6e7f12ea8b34 (diff)
downloadstandingwithresilience-c8bb547bea279af2bb48c13260f98aa8add07131.tar.gz
standingwithresilience-c8bb547bea279af2bb48c13260f98aa8add07131.zip
move intellect-framework-from-internet into folder
Diffstat (limited to 'intellect-framework-from-internet/starts/bagel/nascent1.js')
-rw-r--r--intellect-framework-from-internet/starts/bagel/nascent1.js107
1 files changed, 107 insertions, 0 deletions
diff --git a/intellect-framework-from-internet/starts/bagel/nascent1.js b/intellect-framework-from-internet/starts/bagel/nascent1.js
new file mode 100644
index 0000000..b6b5552
--- /dev/null
+++ b/intellect-framework-from-internet/starts/bagel/nascent1.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)
+})