sbool codeWithHintsToFunctionOnString_verbose;
static <A> F1<S, A> codeWithHintsToFunctionOnString(S code) {
ret codeWithHintsToFunctionOnString(code, "");
}
static <A> F1<S, A> codeWithHintsToFunctionOnString(S code, S hints) {
code = trim(code);
Class c;
S methodName;
if (isIdentifier(code)) { // name of standard function
c = loadFunctions_cached_withInit(code);
methodName = code;
} else if (jcontains(code, "calc(")) { // code defines its own calc function
c = veryQuickJava(code);
methodName = 'calc;
} else { // code is an expression or block working on variable s
S main = "sO calc(fS s) {\n" + tok_addReturn(code) + "\n}";
if (codeWithHintsToFunctionOnString_verbose) print(main);
c = veryQuickJava(main);
if (codeWithHintsToFunctionOnString_verbose) print(c);
methodName = 'calc;
}
final Method m = findMethod_precise(c, methodName, "");
if (m == null) fail("Not a method on a string: " + code);
ret func(S s) -> A { (A) invokeMethod(m, null, s) };
}download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1020643 |
| Snippet name: | codeWithHintsToFunctionOnString |
| Eternal ID of this version: | #1020643/11 |
| Text MD5: | d1b2c073a14d25d4268947326415be2c |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2019-02-05 14:47:19 |
| Source code size: | 1051 bytes / 28 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 882 / 903 |
| Version history: | 10 change(s) |
| Referenced in: | [show references] |