static F1 codeToFunctionOnArbitraryType(S code, S type, Class javaType, S varName) {
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(final " + type + " " + varName + ") {\n" + tok_addReturn(code) + "\n}";
c = veryQuickJava(main);
methodName = 'calc;
}
final Method m = findMethod_precise_onTypes(c, methodName, javaType);
if (m == null) fail("Not a method on " + c + ": " + code + "(" + javaType + ")");
ret (F1) func(O o) -> O { invokeMethod(m, null, o) };
}