Agena v. 2.36.2 (5/2/2023, Alexander Walz) |
Readme/What's new |
2.36.2, February 05, 2023
- New `curry` transforms a function with multiple arguments into a sequence of single-argument functions, i.e. f(a, b, c, ...) becomes f(a)(b)(c)...
> f := << x, y, z -> x*y + z >>
> t := curry(f, 10); # returns f(10, y, z)
> t(20, 30):
230
> u := curry(t, 20); # returns t(10, 20)(z) = f(10, 20, z)
> u(30):
230
- `reduce` now accepts a new option, counter=true, which will assign an internal counter value, starting from one and incremented by one,
to the last argument of the given function. This is 20 % faster than the existing _c=true option.
- `reduce` now supports folding, which means that the first value in a structure or strings is taken as the initialiser, with the new
fold=true option. In this case you do not need to - and should not - pass an initialiser explicitly as the first argument. Examples:
> reduce(<< x, a, c -> a + x * 10^(c - 1) >>, seq(0, 3, 3, 3), counter = true, fold = true):
333
With strings, you should place an embedded zero, represented by '\000', at its start:
> reduce(<< x, a -> a & x & '|' >>, '\0001234', fold=true):
1|2|3|4|
- The new function `fold` works like `reduce` with the fold = true option.
- `skycrane.email` has been further improved and now also returns a reason why an address is invalid.
- Metamethods can now be assigned to procedures. This may be useful only with closures, which can be used to store data for faster access
than is possible with tables, sequences or registers. Data stored in closures usually are called `upvalues`. Depending on the platform,
the increase in speed when reading or writing upvalues is zero to nine percent, with generally less memory required.
- To store data in closures, use the `tuples.new` function:
> import tuples
> t := tuples.new(10, 20, 30)
The `tuples` package provides functions and metamethods to work with tuples, see Chapter 10.12 of the Primer and Reference.
- If a procedure name is indexed with square brackets, the respective upvalues are returned if the procedure is a closure:
> t[1], t[2], t[3]:
10 20 30
- Procedures now support the '__index', '__writeindex', '__tostring', '__in', '__notin', '__filled', '__empty', '__union', '__minus',
'__intersect', '__eq', '__aeq', '__eeq' and '__size' metamethods. |
Agena v. 2.36.2 (5/2/2023, Alexander Walz) |
Readme/What's new |
2.36.2, February 05, 2023
- New `curry` transforms a function with multiple arguments into a sequence of single-argument functions, i.e. f(a, b, c, ...) becomes f(a)(b)(c)...
> f := << x, y, z -> x*y + z >>
> t := curry(f, 10); # returns f(10, y, z)
> t(20, 30):
230
> u := curry(t, 20); # returns t(10, 20)(z) = f(10, 20, z)
> u(30):
230
- `reduce` now accepts a new option, counter=true, which will assign an internal counter value, starting from one and incremented by one,
to the last argument of the given function. This is 20 % faster than the existing _c=true option.
- `reduce` now supports folding, which means that the first value in a structure or strings is taken as the initialiser, with the new
fold=true option. In this case you do not need to - and should not - pass an initialiser explicitly as the first argument. Examples:
> reduce(<< x, a, c -> a + x * 10^(c - 1) >>, seq(0, 3, 3, 3), counter = true, fold = true):
333
With strings, you should place an embedded zero, represented by '\000', at its start:
> reduce(<< x, a -> a & x & '|' >>, '\0001234', fold=true):
1|2|3|4|
- The new function `fold` works like `reduce` with the fold = true option.
- `skycrane.email` has been further improved and now also returns a reason why an address is invalid.
- Metamethods can now be assigned to procedures. This may be useful only with closures, which can be used to store data for faster access
than is possible with tables, sequences or registers. Data stored in closures usually are called `upvalues`. Depending on the platform,
the increase in speed when reading or writing upvalues is zero to nine percent, with generally less memory required.
- To store data in closures, use the `tuples.new` function:
> import tuples
> t := tuples.new(10, 20, 30)
The `tuples` package provides functions and metamethods to work with tuples, see Chapter 10.12 of the Primer and Reference.
- If a procedure name is indexed with square brackets, the respective upvalues are returned if the procedure is a closure:
> t[1], t[2], t[3]:
10 20 30
- Procedures now support the '__index', '__writeindex', '__tostring', '__in', '__notin', '__filled', '__empty', '__union', '__minus',
'__intersect', '__eq', '__aeq', '__eeq' and '__size' metamethods. |
Comments
Alexander Walz
Sat, 13/05/2017 - 20:06
Permalink
Hello,
Add new comment