3 ms·
Without being able to call pure functions within pure functions, what use is this beyond the trivial simple examples? Couldn't it be possible to pass a "this" a
by vortico 11y ago
Without being able to call pure functions within pure functions, what use is this beyond the trivial simple examples? Couldn't it be possible to pass a "this" argument as the current JSON node and have it traverse the tree or something? For example:
{
"math": {
"sin": function(x) {...}
},
"numerics": {
"sin2": function(x) {
return this.parent.math.sin(x)
},
"parent": [automatically inserted by parser]
}
}
- TazeTSchnitzel 11y agoCalling the functions would give them a `this` anyway, but that only works if you don't need a function from two levels up.
- LightMachine 11y agoThere are many possibilities since you can pass any program/algorithm through LJSON while still having a good level of safety. You could it, for example, to allow your users to pick an AI strategy for their bots in a game, among billion of other things. But there are many restrictions, so you can't just write arbitrary JS functions. You have to design them much more carefully by requesting the proper primitives, using the technique I explained with the hypothenuse example. Of cours, you could just request `window` as a primitive and get everything, but yea...
- LightMachine 11y agoI added a file, `examples.js`, which shows how you can encode some array algorithms on λJSON. It may look extremely inexpressible due to so lack of loops, math, etc - but it is still able to encode any conceivable algorithm, although more carefully.