{"action":"created","issue":{"url":"https://api.github.com/repos/killme2008/aviator/issues/191","repository_url":"https://api.github.com/repos/killme2008/aviator","labels_url":"https://api.github.com/repos/killme2008/aviator/issues/191/labels{/name}","comments_url":"https://api.github.com/repos/killme2008/aviator/issues/191/comments","events_url":"https://api.github.com/repos/killme2008/aviator/issues/191/events","html_url":"https://github.com/killme2008/aviator/issues/191","id":546611040,"node_id":"MDU6SXNzdWU1NDY2MTEwNDA=","number":191,"title":"【建议】是否能增加科学计数法、多行等新特性","user":{"login":"hug3id","id":21352838,"node_id":"MDQ6VXNlcjIxMzUyODM4","avatar_url":"https://avatars2.githubusercontent.com/u/21352838?v=4","gravatar_id":"","url":"https://api.github.com/users/hug3id","html_url":"https://github.com/hug3id","followers_url":"https://api.github.com/users/hug3id/followers","following_url":"https://api.github.com/users/hug3id/following{/other_user}","gists_url":"https://api.github.com/users/hug3id/gists{/gist_id}","starred_url":"https://api.github.com/users/hug3id/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hug3id/subscriptions","organizations_url":"https://api.github.com/users/hug3id/orgs","repos_url":"https://api.github.com/users/hug3id/repos","events_url":"https://api.github.com/users/hug3id/events{/privacy}","received_events_url":"https://api.github.com/users/hug3id/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2020-01-08T02:34:31Z","updated_at":"2020-01-08T08:57:34Z","closed_at":null,"author_association":"NONE","body":"感谢作者提供如此好用的脚本引擎！最近做一些数据处理方面的工作，例如下面通过aviator代码实现了分组操作：\r\n```\r\nlist = seq.list(\r\n    seq.map(\"年份\", 2018, \"气温\", 20),\r\n    seq.map(\"年份\", 2019, \"气温\", 30),\r\n);\r\ngroupingBy(list, lambda(v) -> v.年份 end, counting);\r\ngroupingBy(list, lambda(v) -> v.年份 end, summing(lambda(v) -> v.气温 end));\r\ngroupingBy(list, lambda(v) -> v.年份 end, averaging(lambda(v) -> v.气温 end));\r\ngroupingBy(list, lambda(v) -> v.年份 end, maxBy(lambda(v) -> v.气温 end));\r\ngroupingBy(list, lambda(v) -> v.年份 end, minBy(lambda(v) -> v.气温 end));\r\nget = lambda(field) -> lambda(v) -> seq.get(v, field) end end;\r\ngroupingBy(list, get(\"年份\"), counting);\r\n```\r\n\r\n函数实现：\r\n```\r\n// classifier = 分组依据，reduceOp = 聚集操作\r\ngroupingBy = lambda(list, classifier, reduceOp) ->\r\n    list = reduce(list, lambda(container, v) ->\r\n        key = classifier(v);\r\n        item = seq.get(container, key);\r\n        supplier = reduceOp.supplier; // 直接调用 reduceOp.supplier() 报错：函数不存在\r\n        item = item == nil ? supplier() : item;\r\n        accumulator = reduceOp.accumulator;\r\n        item = v == nil ? item : accumulator(item, v);\r\n        seq.add(container, key, item);\r\n        container\r\n    end, seq.map());\r\n    finisher = reduceOp.finisher;\r\n    finisher == nil ? list : map(list, lambda(e) -> seq.add(list, e.key, finisher(e.value)) end);list\r\nend;\r\n\r\ncounting = make_reduce_op(\r\n    lambda() -> 0 end,\r\n    lambda(u, v) -> u + 1 end,\r\n    nil\r\n);\r\n\r\nsumming = lambda(mapper) -> make_reduce_op(\r\n    lambda() -> 0 end,\r\n    lambda(u, v) -> u + mapper(v) end,\r\n    nil\r\n) end;\r\n\r\naveraging = lambda(mapper) -> make_reduce_op(\r\n    lambda() -> tuple(0, 0) end,\r\n    lambda(u, v) ->\r\n        u[0] = u[0] + mapper(v);\r\n        u[1] = u[1] + 1;\r\n        u\r\n    end,\r\n    lambda(v) -> v[0] / double(v[1]) end\r\n) end;\r\n\r\nmaxBy = lambda(mapper) -> make_reduce_op(\r\n    lambda() -> -99999999999999999999 end, // 不支持科学计数法\r\n    lambda(u, v) -> max(u, mapper(v)) end,\r\n    nil\r\n) end;\r\n\r\nminBy = lambda(mapper) -> make_reduce_op(\r\n    lambda() -> 99999999999999999999 end,\r\n    lambda(u, v) -> min(u, mapper(v)) end,\r\n    nil\r\n) end;\r\n\r\nmake_reduce_op = lambda(supplier, accumulator, finisher) -> seq.map(\r\n    \"supplier\", supplier != nil ? supplier : lambda() -> 0 end,\r\n    \"accumulator\", accumulator != nil ? accumulator : lambda(u, v) -> u end,\r\n    \"finisher\", finisher != nil ? finisher : identity\r\n) end;\r\n```\r\n\r\n一些建议：\r\n1. 能否支持多行的书写形式？目前看仅需要将换行字符替换为空格即可实现，能大大提高脚本可读性\r\n2. 能否支持单行和多行注释？同样对调试代码帮助很大\r\n3. 能否支持直接调用map中的函数？例如：m = seq.map(\"func\", lambda()->0 end); m.func()，\r\n目前需要这样：func = m.func; func()\r\n4. 能否支持科学计数法，无法简洁表达很大或很小的数\r\n5. 能否简化lambda 函数的定义，比如去掉lambda关键字？\r\n\r\n非常感谢！"},"comment":{"url":"https://api.github.com/repos/killme2008/aviator/issues/comments/571952575","html_url":"https://github.com/killme2008/aviator/issues/191#issuecomment-571952575","issue_url":"https://api.github.com/repos/killme2008/aviator/issues/191","id":571952575,"node_id":"MDEyOklzc3VlQ29tbWVudDU3MTk1MjU3NQ==","user":{"login":"hug3id","id":21352838,"node_id":"MDQ6VXNlcjIxMzUyODM4","avatar_url":"https://avatars2.githubusercontent.com/u/21352838?v=4","gravatar_id":"","url":"https://api.github.com/users/hug3id","html_url":"https://github.com/hug3id","followers_url":"https://api.github.com/users/hug3id/followers","following_url":"https://api.github.com/users/hug3id/following{/other_user}","gists_url":"https://api.github.com/users/hug3id/gists{/gist_id}","starred_url":"https://api.github.com/users/hug3id/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hug3id/subscriptions","organizations_url":"https://api.github.com/users/hug3id/orgs","repos_url":"https://api.github.com/users/hug3id/repos","events_url":"https://api.github.com/users/hug3id/events{/privacy}","received_events_url":"https://api.github.com/users/hug3id/received_events","type":"User","site_admin":false},"created_at":"2020-01-08T08:57:34Z","updated_at":"2020-01-08T08:57:34Z","author_association":"NONE","body":"关于多行的问题，4.2.9版本运行 AviatorEvaluator.execute(\"a=3;\\r\\na+4\"); 会报以下错误\r\nException in thread \"main\" com.googlecode.aviator.exception.CompileExpressionErrorException: Aviator doesn't support multi-lines expression at 5\r\n\tat com.googlecode.aviator.lexer.ExpressionLexer.scan(ExpressionLexer.java:134)\r\n\tat com.googlecode.aviator.parser.ExpressionParser.move(ExpressionParser.java:840)\r\n\tat com.googlecode.aviator.parser.ExpressionParser.statement(ExpressionParser.java:869)\r\n\tat com.googlecode.aviator.parser.ExpressionParser.parse(ExpressionParser.java:855)\r\n\tat com.googlecode.aviator.AviatorEvaluatorInstance.innerCompile(AviatorEvaluatorInstance.java:857)\r\n\tat com.googlecode.aviator.AviatorEvaluatorInstance.compile(AviatorEvaluatorInstance.java:836)\r\n\tat com.googlecode.aviator.AviatorEvaluatorInstance.execute(AviatorEvaluatorInstance.java:948)\r\n\tat com.googlecode.aviator.AviatorEvaluator.execute(AviatorEvaluator.java:519)\r\n\tat com.googlecode.aviator.AviatorEvaluator.execute(AviatorEvaluator.java:531)\r\n\tat com.googlecode.aviator.AviatorEvaluator.execute(AviatorEvaluator.java:552)\r\n\r\n如果将换行符替换为空格就正常了，请验证。非常感谢！"}}
{"actor":{"display_login":"hug3id"}}