You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See Coconut's
[documentation](http://coconut.readthedocs.io/en/develop/DOCS.html) for
more information on all of the features listed below.
Bugfixes:
* #851, #852: Fixed comments inside of parentheses in the Jupyter
kernel.
Language features:
* #846: `reduce`, `takewhile`, and `dropwhile` now support keyword
arguments.
* #848: Class and data patterns now support keyword argument name
elision.
* #847: New pattern-matching syntax for matching anonymous named tuples.
Compiler features:
* #843: Added compiler warnings for (some cases of) undefined variables.
Copy file name to clipboardExpand all lines: DOCS.md
+13-11Lines changed: 13 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1006,7 +1006,7 @@ Coconut also allows a single `?` before attribute access, function calling, part
1006
1006
1007
1007
When using a `None`-aware operator for member access, either for a method or an attribute, the syntax is `obj?.method()` or `obj?.attr` respectively. `obj?.attr` is equivalent to `obj.attr if obj is not None else obj`. This does not prevent an `AttributeError` if `attr` is not an attribute or method of `obj`.
1008
1008
1009
-
The `None`-aware indexing operator is used identically to normal indexing, using `?[]` instead of `[]`. `seq?[index]` is equivalent to the expression `seq[index] is seq is not None else seq`. Using this operator will not prevent an `IndexError` if `index` is outside the bounds of `seq`.
1009
+
The `None`-aware indexing operator is used identically to normal indexing, using `?[]` instead of `[]`. `seq?[index]` is equivalent to the expression `seq[index] if seq is not None else seq`. Using this operator will not prevent an `IndexError` if `index` is outside the bounds of `seq`.
1010
1010
1011
1011
Coconut also supports None-aware [pipe operators](#pipes) and [function composition pipes](#function-composition).
1012
1012
@@ -1204,6 +1204,7 @@ base_pattern ::= (
1204
1204
| NAME "(" patterns ")" # classes or data types
1205
1205
| "data" NAME "(" patterns ")" # data types
1206
1206
| "class" NAME "(" patterns ")" # classes
1207
+
| "(" name "=" pattern ... ")" # anonymous named tuples
1207
1208
| "{" pattern_pairs # dictionaries
1208
1209
["," "**" (NAME | "{}")] "}" # (keys must be constants or equality checks)
1209
1210
| ["s" | "f" | "m"] "{"
@@ -1269,7 +1270,8 @@ base_pattern ::= (
1269
1270
- Classes or Data Types (`<name>(<args>)`): will match as a data type if given [a Coconut `data` type](#data) (or a tuple of Coconut data types) and a class otherwise.
1270
1271
- Data Types (`data <name>(<args>)`): will check that whatever is in that position is of data type `<name>` and will match the attributes to `<args>`. Generally, `data <name>(<args>)` will match any data type that could have been constructed with `makedata(<name>, <args>)`. Includes support for positional arguments, named arguments, default arguments, and starred arguments. Also supports strict attributes by prepending a dot to the attribute name that raises `AttributError` if the attribute is not present rather than failing the match (e.g. `data MyData(.my_attr=<some_pattern>)`).
1271
1272
- Classes (`class <name>(<args>)`): does [PEP-634-style class matching](https://www.python.org/dev/peps/pep-0634/#class-patterns). Also supports strict attribute matching as above.
1272
-
- Mapping Destructuring:
1273
+
- Anonymous Named Tuples (`(<name>=<pattern>, ...)`): checks that the object is a `tuple` of the given length with the given attributes. For matching [anonymous `namedtuple`s](#anonymous-namedtuples).
1274
+
- Dict Destructuring:
1273
1275
- Dicts (`{<key>: <value>, ...}`): will match any mapping (`collections.abc.Mapping`) with the given keys and values that match the value patterns. Keys must be constants or equality checks.
1274
1276
- Dicts With Rest (`{<pairs>, **<rest>}`): will match a mapping (`collections.abc.Mapping`) containing all the `<pairs>`, and will put a `dict` of everything else into `<rest>`. If `<rest>` is `{}`, will enforce that the mapping is exactly the same length as `<pairs>`.
1275
1277
- Set Destructuring:
@@ -1735,7 +1737,7 @@ The syntax for a statement lambda is
where `arguments` can be standard function arguments or [pattern-matching function definition](#pattern-matching-functions) arguments and `statement` can be an assignment statement or a keyword statement. Note that the `async`, `match`, and [`copyclosure`](#copyclosure-functions) keywords can be combined and can be in any order.
1740
+
where `arguments` can be standard function arguments or [pattern-matching function definition](#pattern-matching-functions) arguments and `statement` can be any non-compound statement—that is, any statement that doesn't open a code block below it (so `def x => assert x` is fine but `def x => if x: True` is not). Note that the `async`, `match`, and [`copyclosure`](#copyclosure-functions) keywords can be combined and can be in any order.
1739
1741
1740
1742
If the last `statement` (not followed by a semicolon) in a statement lambda is an `expression`, it will automatically be returned.
1741
1743
@@ -2233,7 +2235,7 @@ as a shorthand for
2233
2235
f(long_variable_name=long_variable_name)
2234
2236
```
2235
2237
2236
-
Such syntax is also supported in [partial application](#partial-application) and [anonymous `namedtuple`s](#anonymous-namedtuples).
2238
+
Such syntax is also supported in [partial application](#partial-application), [anonymous `namedtuple`s](#anonymous-namedtuples), and [`class`/`data`/anonymous `namedtuple` patterns](#match).
2237
2239
2238
2240
_Deprecated: Coconut also supports `f(...=long_variable_name)` as an alternative shorthand syntax._
2239
2241
@@ -2262,7 +2264,7 @@ main_func(
2262
2264
2263
2265
### Anonymous Namedtuples
2264
2266
2265
-
Coconut supports anonymous [`namedtuple`](https://docs.python.org/3/library/collections.html#collections.namedtuple) literals, such that `(a=1, b=2)` can be used just as `(1, 2)`, but with added names. Anonymous `namedtuple`s are always pickleable.
2267
+
Coconut supports anonymous [`namedtuple`](https://docs.python.org/3/library/collections.html#collections.namedtuple) literals, such that `(a=1, b=2)` can be used just as `(1, 2)`, but with added names. Anonymous `namedtuple`s are always pickleable and support [`__match_args__`](https://peps.python.org/pep-0622/) on all Python versions.
2266
2268
2267
2269
The syntax for anonymous namedtuple literals is:
2268
2270
```coconut
@@ -3803,9 +3805,9 @@ _Can’t be done quickly without Coconut’s iterable indexing, which requires m
Coconut re-introduces Python 2's `reduce` built-in, using the `functools.reduce` version.
3810
+
Coconut re-introduces Python 2's `reduce` built-in, using the `functools.reduce` version. Additionally, unlike `functools.reduce`, Coconut's `reduce` always supports keyword arguments.
3809
3811
3810
3812
##### Python Docs
3811
3813
@@ -3935,9 +3937,9 @@ result = itertools.zip_longest(range(5), range(10))
3935
3937
3936
3938
#### `takewhile`
3937
3939
3938
-
**takewhile**(_predicate_, _iterable_, /)
3940
+
**takewhile**(_predicate_, _iterable_)
3939
3941
3940
-
Coconut provides `itertools.takewhile` as a built-in under the name `takewhile`.
3942
+
Coconut provides `itertools.takewhile` as a built-in under the name `takewhile`. Additionally, unlike `itertools.takewhile`, Coconut's `takewhile` always supports keyword arguments.
Coconut provides `itertools.dropwhile` as a built-in under the name `dropwhile`.
3976
+
Coconut provides `itertools.dropwhile` as a built-in under the name `dropwhile`. Additionally, unlike `itertools.dropwhile`, Coconut's `dropwhile` always supports keyword arguments.
0 commit comments