This is the 29th day of my participation in the August More Text Challenge
5.2.6
A strongly recommended upgrading version if you are using 5.x versions.
Main changes:
- Fixed:
-
- Anonymous function can’t support variadic arguments.
- continue statement not work with if/else or nested if statements #394
-
- LambdaFunction ThreadLocal caching may leak environment context #392
- New features:
-
- New function: partial(f, &args) that takes a function f and fewer than the normal arguments to f, and returns a fn that takes a variable number of additional args. When called, the returned function calls f with args + additional args.
- Use soft reference for caching reflection result #386
-
- Added key info to exception message when sequence is null in seq.get function.
5.2.5
Main changes:
- Auto convert java boxing types into aviator number types when invoking java methods #369
- Adds a calcuator example which evaluate arithmetic expression in string.
- Bug fixes: can’t call overload getter/setter by reflection #368
- Used array-based hashmap for internal env to reduce memory consumption.
5.2.4
New features:
- Define anonymous function by
fn
syntax (instead oflambda ... -> ... end
),let add = fn(x, y) { x + y); add(1, 2)
for example. - Unpacking arguments(as sequence) by
*args
syntax like python, for example:
fn test(a, b, c, d) {
a * b + c * d
}
let a = tuple(1, 2);
let list = seq.list(3, 4);
p(test(*a, *list));
Copy the code
- Adds
AVIATOR_DEPS
environment variable to point third-party jar files directory foraviator
shell command-line, default is$HOME/.aviatorscript/deps
, all jar files under this directory will be added to JVMCLASSPATH
. - Improve
for
statement, supports index( List/Array sequence etc.) and key/value(Map) iterating:
let a = tuple(1, 2, 3, 4, 5, 6, 7, 8, 9); for i, x in a { assert(i + 1 == x); } let m = seq.map("a", 1, "b", 2, "c", 3); for k, v in m { if k == "a" { assert(v == 1); }elsif k == 'b' { assert(v == 2); }elsif k == 'c' { assert(v == 3); }else { throw "should not happen"; }}Copy the code
seq.array_of(Class, dimension1, dimension2, ... dimensions)
to create a multidimensional array.- New functions to add/retrieve/remove object’s metadata:
let a = 1;
p(meta(a)); ## retrieve meta ,null if not found
## associate key/value metadata to any objects by with_meta(obj, key, value)
a = with_meta(a, "key", tuple(1, 2, 3));
p(meta(a)); ## {"key" => [1, 2, 3]}
p(meta(a, "key")); ## [1, 2, 3]
## remove metadata by without_meta(obj, key)
a = without_meta(a, "key");
p(meta(a));
Copy the code
- Bugs fixed:
-
- Wrong size number of
Range
. - JUnit dependency issue, Thanks to DQinYuan
- Wrong size number of
5.2.3 requires
Main changes:
- Removed commons-beanutils #340
- Fixed
AviatorString#toString()
may print warning message.
- Fixed missing source file and line number in string interpolation expression when throws exception.
- New function
is_distinct(seq)
returns true when a sequence doesn’t have duplicated elements.
- Focus on performance turning:
Aviator 5.2.3 requires: Benchmark Mode Cnt Score Error Units PerfBenchmark. TestArith THRPT 5 108126.155 ± 6304.752 OPS /ms PerfBenchmark. TestArithByAviator THRPT. 5 to 2565.933 + 105.076 ops/ms PerfBenchmark testArithByBeetl THRPT 1625.887 + / - 5 291.247. Ops/ms PerfBenchmark testArithByScript THRPT 5 7050.305 + / - 69.529 ops/ms PerfBenchmark. TestCond THRPT 93099.759 5 Plus or minus 8554.585. Ops/ms PerfBenchmark testCondByAviator THRPT 5 1667.093 + / - 112.807 ops/ms PerfBenchmark. TestCondByBeetl THRPT 5 to 1617.045 + 93.373 ops/ms PerfBenchmark. TestCondByScript THRPT 5 6926.106 + / - 267.292 ops/ms PerfBenchmark. TestObject THRPT. 5 to 8537.937 + 272.512 ops/ms PerfBenchmark testObjectByAviator THRPT 5 to 1025.725 + 30.846 ops/ms PerfBenchmark. TestObjectByBeetl THRPT. 5 to 860.873 + 33.559 ops/ms PerfBenchmark testObjectByScript THRPT 4552.307 + / - 5 199.507 ops/ms Aviator 5.2.2: Benchmark Mode Cnt Score Error Units Perfbench. testArith THRPT 5 105095.308 ± 3861.646 OPS /ms PerfBenchmark. TestArithByAviator THRPT. 5 to 2405.785 + 78.325 ops/ms PerfBenchmark testArithByBeetl THRPT 1628.726 + / - 5 45.332. Ops/ms PerfBenchmark testArithByScript THRPT 5 7513.704 + / - 286.090 ops/ms PerfBenchmark. TestCond THRPT 92518.914 5 Plus or minus 1961.141. Ops/ms PerfBenchmark testCondByAviator THRPT 5 952.022 + / - 32.184 ops/ms PerfBenchmark. TestCondByBeetl THRPT 5 1647.736 + / - 19.300 ops/ms PerfBenchmark. TestCondByScript THRPT 5 7631.465 + / - 404.298 ops/ms PerfBenchmark. TestObject THRPT. 5 to 8847.069 + 261.799 ops/ms PerfBenchmark testObjectByAviator THRPT 5 to 873.944 + 26.327 ops/ms PerfBenchmark. TestObjectByBeetl THRPT. 5 to 826.758 + 30.071 ops/ms PerfBenchmark testObjectByScript THRPT 4647.178 + / - 5 237.783 ops/msCopy the code
-
- Benchmark improvements:
-
-
- TestArithByAviator 6.7%
- testCondByAviator 75%
-
-
-
- TestObjectByAviator 17.4%
-
5.2.2
Main changes:
- Fixed
Expression#getVariableNames()
andExpression#getVariableFullNames()
, they will return the global uninitialized variable names. # 277 # 335 - Adds
AviatorEvaluatorInstance#setCachedExpressionByDefault(boolean)
to configure whether to cache the compiled expression by default when invokecompile(string)
.execute(string, [env])
methods etc, default value is false. # 330
- Adds a new option
Options.ALLOWED_CLASS_SET
with aSet<Class>
value to control the allowed class list in new statement and static method/field invocation. # 325 - Adds new features
Feature.StaticFields
andFeature.StaticMethods
. # 326
5.2.1
If you are trying 5.2.0, please upgrade to this verson.
- New Features:
-
- Access java class’s static methods by reflection,
Long.parseLong("3")
for example. You mustuse
the class at first.
- Access java class’s static methods by reflection,
- Breaking changes:
-
- String interpolation only works on literal string in script. Runtime string will not work.
- Fixed:
-
- Weak reference queue memory leak in reflector.
- String interpolation compile error in some corner cases.
-
- Locked
commons-beanutils
Version to 1.9.4
- Locked
5.2.0
Deprecated, do use 5.2.1
- New Features:
-
- function overloading by parameter count, see function_overload.av.
- variadic function by define variable parameter by prefixed with
&
, see function_varargs.av.
-
- use statement to import java classes, such as
use java.util.Date;
, see use.av. - access class static variables by
.
, for exampleMath.PI
, see static_vars.av.
- use statement to import java classes, such as
-
- access or assign map’s value by
m[key]
syntax, the key can be a object or expression. - when use aviator commandline, there is a new internal variable
__MODULE__.dir
represents the file’s current directory absolute path.You may use it inrequire
for example:
- access or assign map’s value by
## examples/test_qsort.av
let q = require(__MODULE__.dir + '/qsort.av');
fn rand_list(n) {
let a = seq.list();
for i in range(0, n) {
seq.add(a, rand(n));
}
return a;
}
let a = rand_list(20);
println("before sorting: " + a);
q.sort(a);
println("after sorting: " + a);
Copy the code
The you can run the script by command aviator examples/test_qsort.av
, you don’t need to change the work directory into examples
as before.
- New Functions:
-
- more sequence functions:
-
-
take_while(seq, pred)
to take elements in sequence withpred(x)
is true.drop_while(seq, pred)
to drop elements in sequence withpred(x)
is true.
-
-
-
concat(list1, list2)
to concat two sequences.group_by(seq, keyfn)
to group elements bykeyfn(x)
.
-
-
-
distinct(seq)
to return a sequence of the elements of coll with duplicates removed.sort(seq, comparator)
to sort sequence with ajava.util.Comparator
.
-
-
-
reverse(seq)
to return a seq of the items in coll in reverse order.seq.keys(map)
to return the key set of map.
-
-
-
seq.vals(map)
to return the value set of map.zipmap(keys, vals)
to return a map with the keys mapped to the corresponding vals.
-
-
- more math functions:
-
-
math.atan(x)
math.acos(x)
-
-
-
math.asin(x)
math.ceil(x)
-
-
-
math.floor(x)
-
-
- more internal functions:
-
-
is_a(val, class)
Returns true when the value is a intance of the class, for exampleis_a("a", String)
returns true.comparator(pred)
Returns an implementation of java.util.Comparator based upon predicate.
-
-
-
repeat(n, x)
Returns a list of x which it’s lenght n.repeatedly(n, fn)
thefn
function takes no args, and returns a sequence of calls to it inn
times.
-
-
-
constantly(x)
Returns a function that takes any number of arguments and returns x.
-
- Improvements:
-
- improve error reporting, adds source file and source line number.
- performance tweak for variable syntax suger such as
a.b.c
ora.b[10].c
etc, replace thecommons-beanutils
by default, almost 2x speed up.
-
- Checking if function name is reserved when parsing script.
- Reduce memory consumption.