@graffiticode/basis 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/spec/spec.md +10 -0
- package/src/compiler.js +20 -0
- package/src/lexicon.js +8 -0
package/package.json
CHANGED
package/spec/spec.md
CHANGED
|
@@ -173,6 +173,7 @@ This approach draws inspiration from **Model-View-Update** (MVU) architectures,
|
|
|
173
173
|
| `get` | `<string record: any>` | Retrieves a value from a record by key |
|
|
174
174
|
| `hd` | `<list: any>` | First item of list |
|
|
175
175
|
| `isEmpty` | `<list: bool>` | Returns true if the list is empty |
|
|
176
|
+
| `log` | `<any: any>` | Logs the value to console and returns it (identity function) |
|
|
176
177
|
| `map` | `<function list: list>` | Applies function to each item |
|
|
177
178
|
| `max` | `<number number: number>` | Returns the larger of two numbers |
|
|
178
179
|
| `min` | `<number number: number>` | Returns the smaller of two numbers |
|
|
@@ -266,6 +267,15 @@ Return true if list is empty, otherwise return false
|
|
|
266
267
|
isEmpty [] | returns true
|
|
267
268
|
```
|
|
268
269
|
|
|
270
|
+
### log
|
|
271
|
+
|
|
272
|
+
Log a value to the console and return the value unchanged
|
|
273
|
+
|
|
274
|
+
```
|
|
275
|
+
log "Hello" | prints "Hello" to console and returns "Hello"
|
|
276
|
+
log (add 1 2) | prints 3 to console and returns 3
|
|
277
|
+
```
|
|
278
|
+
|
|
269
279
|
### map
|
|
270
280
|
|
|
271
281
|
Apply a function to each element
|
package/src/compiler.js
CHANGED
|
@@ -506,6 +506,13 @@ export class Checker extends Visitor {
|
|
|
506
506
|
resume(err, val);
|
|
507
507
|
});
|
|
508
508
|
}
|
|
509
|
+
LOG(node, options, resume) {
|
|
510
|
+
this.visit(node.elts[0], options, (err1, val1) => {
|
|
511
|
+
const err = [].concat(err1);
|
|
512
|
+
const val = node;
|
|
513
|
+
resume(err, val);
|
|
514
|
+
});
|
|
515
|
+
}
|
|
509
516
|
}
|
|
510
517
|
|
|
511
518
|
function enterEnv(ctx, name, paramc) {
|
|
@@ -1364,6 +1371,19 @@ export class Transformer extends Visitor {
|
|
|
1364
1371
|
}
|
|
1365
1372
|
});
|
|
1366
1373
|
}
|
|
1374
|
+
LOG(node, options, resume) {
|
|
1375
|
+
this.visit(node.elts[0], options, (e0, v0) => {
|
|
1376
|
+
const err = [].concat(e0);
|
|
1377
|
+
try {
|
|
1378
|
+
// Log the value to the console
|
|
1379
|
+
console.log(`LOG: ${v0}`);
|
|
1380
|
+
// Return the value unchanged (identity function)
|
|
1381
|
+
resume(err, v0);
|
|
1382
|
+
} catch (e) {
|
|
1383
|
+
resume([...err, `Error in LOG operation: ${e.message}`], null);
|
|
1384
|
+
}
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1367
1387
|
}
|
|
1368
1388
|
|
|
1369
1389
|
export class Renderer {
|
package/src/lexicon.js
CHANGED
|
@@ -270,5 +270,13 @@ export const lexicon = {
|
|
|
270
270
|
"length": 2,
|
|
271
271
|
"arity": 2,
|
|
272
272
|
"description": "Appends an element to the end of a list."
|
|
273
|
+
},
|
|
274
|
+
"log": {
|
|
275
|
+
"tk": 1,
|
|
276
|
+
"name": "LOG",
|
|
277
|
+
"cls": "function",
|
|
278
|
+
"length": 1,
|
|
279
|
+
"arity": 1,
|
|
280
|
+
"description": "Logs the value to the console and returns the value (identity function)."
|
|
273
281
|
}
|
|
274
282
|
};
|