5 ms·
To solve the readability issue, why not use Babel to transpile JS expressions into the equivalent syntax? To generate the first example in the readme: impor
by jond3k 10y ago
To solve the readability issue, why not use Babel to transpile JS expressions into the equivalent syntax?
To generate the first example in the readme:
import {solve} from 'logic'
function father(x,y) {
return x =='mcbob' && y == 'bob' ||
x =='bob' && y == 'bill';
}
solve(father) // a noop function used as a marker by babel
- AnkhMorporkian 10y agoIf you're going ES6, why not just: import {solve} from 'logic' solve((x,y) => x === "mcbob" && y === "bob" || x === "bob" && y === "bill");
- danappelxx 10y agoJust because you can use the shorthand syntax, doesn't mean you always should.
- hzoo 10y agoYeah, the transformation itself shouldn't be bad. Made a Babel transform real quick for this particular example: http://astexplorer.net/#/ZT6HYai08w http://astexplorer.net/#/ZT6HYai08w
- AgentME 10y agoI feel like that just obfuscates it. You can no longer dynamically use it, and it's completely unobvious what javascript expressions are supported or not.
- jond3k 10y agoBabel has to turn it into valid JS for it to work so you'd still have the 'and' and 'or' functions. In the bottom right corner of Hzoo's example you can see what I mean (http://astexplorer.net/#/ZT6HYai08w http://astexplorer.net/#/ZT6HYai08w) It should be more obvious what expressions are supported when it's validated by a Javascript parser. This is in contrast to the 'dynamic' approach which has no problem with the following until runtime: and(gherkin(or()))