Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义函数计算过程透出 #94

Closed
xiagaohui opened this issue Dec 26, 2018 · 1 comment
Closed

自定义函数计算过程透出 #94

xiagaohui opened this issue Dec 26, 2018 · 1 comment

Comments

@xiagaohui
Copy link

问题一:自定义函数:max(a,b),想知道最后的结果到底是a还是b;a,b可能是表达式。
问题二:在4.0.0-RC版本中为什么新建了env?
image

@killme2008
Copy link
Owner

4.1.0 刚发布(可能要等个一天同步到 maven 中心仓库)

问题一: 你可以返回一个数组,第一个元素表示更大值,用 lambda 定义:

AviatorEvaluator.defineFunction("max",
        "lambda(a,b) ->  a > b ?  tuple(a, b) : tuple(b, a) end");
    Object[] ret = (Object[]) (AviatorEvaluator.execute("max(1,2)")); // 返回数组 [2, 1]
    assertArrayEquals(new Object[] {2, 1}, ret);

问题二: 4.0.0-RC 为了支持 lambda 闭包,引入了嵌套 env 的概念; 4.1.0 新增了选项 USE_USER_ENV_AS_TOP_ENV_DIRECTLY,默认是 true,也就是兼容老版本的行为, top 级别的 env 将直接使用用户传入的 map。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants