theprogrammablemind_4wp 8.0.0-beta.41 → 8.0.0-beta.42

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -64,6 +64,6 @@
64
64
  "sort-json": "^2.0.0",
65
65
  "uuid": "^8.3.2"
66
66
  },
67
- "version": "8.0.0-beta.41",
67
+ "version": "8.0.0-beta.42",
68
68
  "license": "UNLICENSED"
69
69
  }
package/src/config.js CHANGED
@@ -990,21 +990,6 @@ class Config {
990
990
 
991
991
  // value is in response field
992
992
  // TODO maybe generalize out query+evaluate along the lines of set value and set reference
993
- /*
994
- getEvaluator (s, log, context) {
995
- const instance = s({ ...context, evaluate: true })
996
- if (!instance.evalue && !instance.verbatim && !instance.value) {
997
- this.warningNotEvaluated(log, context);
998
- }
999
- if (!instance.evalue) {
1000
- instance.evalue = instance.value
1001
- instance.edefault = true
1002
- }
1003
- delete instance.evaluate
1004
- instance.instance = true;
1005
- return instance
1006
- }
1007
- */
1008
993
  async getEvaluator (s, calls, log, context) {
1009
994
  const instance = await s({ ...context, evaluate: true })
1010
995
  calls.touch(instance)
package/src/semantics.js CHANGED
@@ -49,76 +49,50 @@ class Semantic {
49
49
  }
50
50
  }
51
51
 
52
- async matches (baseArgs, context, options = {}) {
53
- const hierarchy = baseArgs.hierarchy
54
- const config = baseArgs.config
55
-
56
- const objects = baseArgs.getObjects(this.uuid)
57
- // const ask = baseArgs.getAsk(this.uuid)
58
-
59
- // return this.matcher(Object.assign({}, argsBase, {args: contextArgs(context, hierarchy), objects: objects, global: objects, context: context, hierarchy: hierarchy, api: this.getAPI(config)})
60
- const callId = baseArgs.calls.current()
61
- const moreArgs = {
62
- uuid: this.uuid,
63
- args: contextArgs(context, hierarchy),
64
- objects,
65
- global: objects,
66
- context: context,
67
- // hierarchy: hierarchy,
68
- callId,
69
- api: this.getAPI(config),
70
- apis: this.getAPIs(config)
52
+ fixUpArgs (args, context) {
53
+ args.uuid = this.uuid
54
+ args.callId = args.calls.current()
55
+ const objects = args.getObjects(this.uuid)
56
+ args.objects = objects
57
+ args.global = objects
58
+ const config = args.config
59
+ args.api = this.getAPI(config)
60
+ args.apis = this.getAPIs(config)
61
+ args.args = contextArgs(context, args.hierarchy)
62
+ args.context = context
63
+ let n = (id) => id
64
+ if (config && 'nsToString' in config) {
65
+ n = (id) => config.nsToString(id)
71
66
  }
72
- const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
67
+ args.n = n
68
+ args.uuid = this.uuid
69
+ debugger
70
+ Object.assign(args, (args.getUUIDScoped || (() => { return {} }))(this.uuid))
71
+ }
73
72
 
73
+ async matches (args, context, options = {}) {
74
+ this.fixUpArgs(args, context)
74
75
  const matches = await this.matcher(args)
75
- if (matches && (options.debug || {}).match ||
76
- callId == this.callId) {
76
+ if (matches && (options.debug || {}).match || args.callId == this.callId) {
77
77
  debugger // next line is the matcher
78
78
  await this.matcher(args)
79
79
  }
80
80
  return matches
81
81
  }
82
82
 
83
- async apply (baseArgs, context, s, log, options = {}) {
84
- const { hierarchy, config, response } = baseArgs
85
- const objects = baseArgs.getObjects(this.uuid)
83
+ async apply (args, context, s, options = {}) {
84
+ const { config } = args
86
85
  if (config && config.debugLoops) {
87
86
  console.log('apply', this.toLabel())
88
87
  }
89
- if (baseArgs.calls && config && baseArgs.calls.stack.length > config.maxDepth) {
88
+ if (args.calls && config && args.calls.stack.length > config.maxDepth) {
90
89
  throw new Error(`Max depth of ${config.maxDepth} for calls has been exceeded. maxDepth can be set on the config object. To see the calls run with the --dl or set the debugLoops property on the config`)
91
90
  }
92
91
 
93
- // const ask = baseArgs.getAsk(this.uuid)
94
- if (!log) {
95
- console.trace()
96
- throw new Error('log is a required argument')
97
- }
98
92
  const contextPrime = Object.assign({}, context)
99
- let n = (id) => id
100
- if (config && 'nsToString' in config) {
101
- n = (id) => config.nsToString(id)
102
- }
103
- const callId = baseArgs.calls.current()
104
- const moreArgs = {
105
- uuid: this.uuid,
106
- callId,
107
- args: contextArgs(context, hierarchy),
108
- objects,
109
- log,
110
- global: objects,
111
- n,
112
- context: contextPrime,
113
- uuid: this.uuid,
114
- // config,
115
- response,
116
- api: this.getAPI(config),
117
- apis: this.getAPIs(config)
118
- }
119
- const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
120
- if ((options.debug || {}).apply ||
121
- callId == this.callId) {
93
+ this.fixUpArgs(args, contextPrime)
94
+
95
+ if ((options.debug || {}).apply || args.callId == this.callId) {
122
96
  debugger
123
97
  }
124
98
  if (args.breakOnSemantics) {
@@ -181,6 +155,7 @@ class Semantics {
181
155
  if (!(context instanceof Array || context instanceof Object)) {
182
156
  return context
183
157
  }
158
+ args = { ...args }
184
159
  const config = args.config
185
160
  let contextPrime = Object.assign({}, context)
186
161
  const s = (context, options) => this.apply(args, context, options)
@@ -188,6 +163,8 @@ class Semantics {
188
163
  const stack = args.calls.push()
189
164
  let counter = 0
190
165
  let seenQuestion = false
166
+ const deferred = []
167
+ args.log = (message) => { this.logs.push(message) }
191
168
  for (const isemantic in this.semantics) {
192
169
  const semantic = this.semantics[isemantic]
193
170
  if (!semantic) {
@@ -202,17 +179,28 @@ class Semantics {
202
179
  this.calls[counter] = 0
203
180
  }
204
181
  this.calls[counter] += 1
205
- const log = (message) => { this.logs.push(message) }
206
182
  try {
207
- contextPrime = await semantic.apply(args, context, s, log, options)
183
+ let deferWasCalled = false
184
+ const defer = (listener) => {
185
+ deferred.push({ semantic, listener })
186
+ deferWasCalled = true
187
+ }
188
+ args.defer = defer
189
+ contextPrime = await semantic.apply(args, context, s, options)
190
+ if (deferWasCalled) {
191
+ continue
192
+ }
208
193
  if (!contextPrime.controlKeepMotivation && semantic.oneShot) {
209
194
  // semantic.tied_ids.forEach((tied_id) => args.config.removeSemantic(tied_id))
210
195
  args.config.removeSemantic(semantic)
211
196
  }
197
+ for (const { listener } of deferred) {
198
+ listener(args)
199
+ }
212
200
  } catch (e) {
213
201
  contextPrime = null
214
202
  let errorMessage
215
- e.retryCall = () => semantic.apply(args, context, s, log, options)
203
+ e.retryCall = () => semantic.apply(args, context, s, options)
216
204
  const help = 'The error has a retryCall property that will recall the function that failed.'
217
205
  if (e.stack && e.message) {
218
206
  const info = `${semantic.notes ? semantic.notes : ''}${semantic.where ? semantic.where : ''}`
@@ -280,6 +268,13 @@ class Semantics {
280
268
  lines.setElement(0, 1, 'RESULT')
281
269
  lines.setElement(0, 2, `(HASHCODE ${helpers.hashCode(JSON.stringify(helpers.sortJson(contextPrime, { depth: 25 })))})`)
282
270
  lines.setElement(1, 2, JSON.stringify(contextPrime, null, 2))
271
+ for (const { semantic } of deferred) {
272
+ lines.setElement(0, 1, 'DEFERRED')
273
+ lines.setElement(0, 2, semantic.toLabel())
274
+ lines.newRow()
275
+ lines.setElement(0, 2, semantic.toString())
276
+ lines.newRow()
277
+ }
283
278
  this.logs.push(lines.toString())
284
279
  }
285
280
  applied = true