sbool codeWithHintsToFunctionOnString_verbose; static F1 codeWithHintsToFunctionOnString(S code) { ret codeWithHintsToFunctionOnString(code, ""); } static F1 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) }; }