Simple, elegant, Pythonic functional programming.

Overview

Coconut

Backers on Open Collective Sponsors on Open Collective

Coconut (coconut-lang.org) is a variant of Python that adds on top of Python syntax new features for simple, elegant, Pythonic functional programming.

Coconut is developed on GitHub and hosted on PyPI. Installing Coconut is as easy as opening a command prompt and entering:

pip install coconut

after which the entire world of Coconut will be at your disposal. To help you get started, check out these links for more information about Coconut:

  • Tutorial: If you're new to Coconut, a good place to start is Coconut's tutorial.
  • Documentation: If you're looking for info about a specific feature, check out Coconut's documentation.
  • Online Interpreter: If you want to try Coconut in your browser, check out Coconut's online interpreter.
  • FAQ: If you have general questions about Coconut—like who Coconut is built for and whether or not you should use it—Coconut's frequently asked questions are often the best place to start.
  • Create a New Issue: If you're having a problem with Coconut, creating a new issue detailing the problem will allow it to be addressed as soon as possible.
  • Gitter: For any questions, concerns, or comments about anything Coconut-related, ask around at Coconut's Gitter, a GitHub-integrated chat room for Coconut developers.
  • Releases: Want to know what's been added in recent Coconut versions? Check out the release log for all the new features and fixes.

Credits

Contributors

This project exists thanks to all the people who contribute! Become a contributor.

https://opencollective.com/coconut/contributors.svg?width=890&button=false

Backers

Thank you to all our backers! Become a backer.

https://opencollective.com/coconut/backers.svg?width=890

Sponsors

Support Coconut by becoming a sponsor. Your logo will show up here with a link to your website. Become a sponsor.

Comments
  • Automatically return value of last expression in a function

    Automatically return value of last expression in a function

    Would it be possible to have the Coconut compiler automatically return the value of the last expression in a function?

    Having to explicitly use the return keyword in front of the last expression of a function is not the end of the world, but it would be nice to be able to drop it, as is the case in a number of other functional languages.

    I'd rank this in the same category as being able to drop the lambda keyword. Not a biggie, but it sure is convenient and keeps code (and typing) to a minimum (and thus, arguably, cleaner).

    feature resolved 
    opened by chuckwondo 20
  • PermissionError: [Errno 13] Permission denied: '/usr/share/jupyter'

    PermissionError: [Errno 13] Permission denied: '/usr/share/jupyter'

    [email protected]:~/.local/lib/python3.9/site-packages/lenses$ coconut --ipython notebook
    Traceback (most recent call last):
      File "/home/gurkenglas/.local/lib/python3.9/site-packages/coconut/command/command.py", line 293, in handling_exceptions
        yield
      File "/home/gurkenglas/.local/lib/python3.9/site-packages/coconut/command/command.py", line 129, in cmd
        self.use_args(parsed_args, interact, original_args=args)
      File "/home/gurkenglas/.local/lib/python3.9/site-packages/coconut/command/command.py", line 255, in use_args
        self.start_jupyter(args.jupyter)
      File "/home/gurkenglas/.local/lib/python3.9/site-packages/coconut/command/command.py", line 719, in start_jupyter
        custom_kernel_dir = install_custom_kernel()
      File "/home/gurkenglas/.local/lib/python3.9/site-packages/coconut/kernel_installer.py", line 64, in install_custom_kernel
        os.makedirs(kernel_dest)
      File "/usr/lib/python3.9/os.py", line 215, in makedirs
        makedirs(head, exist_ok=exist_ok)
      File "/usr/lib/python3.9/os.py", line 215, in makedirs
        makedirs(head, exist_ok=exist_ok)
      File "/usr/lib/python3.9/os.py", line 225, in makedirs
        mkdir(name, mode)
    PermissionError: [Errno 13] Permission denied: '/usr/share/jupyter'
    (you should report this at https://github.com/evhub/coconut/issues/new)
    Exiting due to PermissionError.
    [email protected]:~/.local/lib/python3.9/site-packages/lenses$ coconut -v
    Coconut: Version 1.5.0 [Fish License] running on Python 3.9.5 and Cython
    cPyparsing v2.4.5.0.1.2
    

    got coconut via python3.9 -m pip install coconut.

    oversight resolved 
    opened by Gurkenglas 16
  • Support tail call optimization without requiring a decorator

    Support tail call optimization without requiring a decorator

    Requiring the programmer to annotate tail recursion with @recursive is a bit awkward for a language that isn't Python. It should be able to analyze the function and perform it automatically.

    feature resolved 
    opened by darkf 16
  • Use == instead of = for equality checking in pattern-matching

    Use == instead of = for equality checking in pattern-matching

    I finally managed to write a match clause

              match None in reso:
                pass
              match =ConflictResolution.MINE in reso:
                pass
              match =ConflictResolution.THEIRS in reso:
                pass
              match =ConflictResolution.NEXT in reso:
                pass
    

    it seems to work, but the syntax for comparison seems odd... it should be == not =. My initial confusion was how to refer to the "in" expression inside the match expression. There is no it defined. The =X syntax looks more like an assignment though, quite unpythonic.

    Am I seeing this wrong? Also, how would I check membership? match "1".in in expr?

    The documentation is leaving lots of questions and lacks good examples, imho.

    modification resolved 
    opened by ArneBachmann 14
  • Failure to Install in Pythonista

    Failure to Install in Pythonista

    Pythonista is an app for working with python on iOS and I was hoping to bring some of my favourite functional programming goodness to it! However, install via StaSh (a shell for pythonista which emulates pip) fails with the following error:

    ImportError('No module named requirements',)
    

    I suspect this is an issue down to some issues with StaSh, but I thought I might bring it up in any case just in case.

    I'd love to get it working, so if you can think of anything that I can experiment with to do so I'm very happy to try!

    oversight resolved 
    opened by iamrecursion 13
  • Rewrite of testing system

    Rewrite of testing system

    In response to #151 I have rewritten the testing system to use unittest. The makes the Travis file simpler, and it is easier to preform all the tests without Travis.

    It currently runs all the tests in the cocotest library, but I will be adding more.

    Also the repos are merged as per #151.

    Thanks!

    tests cleanup resolved 
    opened by Boscillator 13
  • Add zip_longest built-in

    Add zip_longest built-in

    These two libraries are very commonly used, especially in a functional style. Most programmers know what these functions/classes do and where they are implemented, and both modules have a negligible import time.

    feature resolved 
    opened by fredcallaway 13
  • Better way to type Coconut data types

    Better way to type Coconut data types

    I wanted to do something like A = TypeVar("A", bound = DA) where data DA(a:int, b:str) but it wasn't allowed to reference the _coconut definitions

    feature resolved 
    opened by ArneBachmann 12
  • Ipython and Jupyter aren't working

    Ipython and Jupyter aren't working

    Hi, I was trying to get Coconut to work with jupyter and ipython, but when I try to run anything, I get the following error message:

    ----------------------------------------------------------
    TypeError                Traceback (most recent call last)
    /usr/local/lib/python3.8/site-packages/IPython/core/async_helpers.py in _pseudo_sync_runner(coro)
     66     """
     67     try:
    ---> 68         coro.send(None)
     69     except StopIteration as exc:
     70         return exc.value
    
    /usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/coroutines.py in coro(*args, **kw)
    122         @functools.wraps(func)
    123         def coro(*args, **kw):
    --> 124             res = func(*args, **kw)
    125             if (base_futures.isfuture(res) or inspect.isgenerator(res) or
    126                     isinstance(res, CoroWrapper)):
    
    TypeError: run_cell_async() got an unexpected keyword argument 'transformed_cell'
    

    This happens in Jupyter notebooks, in Jupyterlab and in the ipython repl.

    What I've tried so far:

    • removing and reinstalling the coconut kernels
    • uninstalling coconut and installing coconut-develop
    • searching through the github issues for the same problem.

    my OS is macOS Catalina, 10.15.6. I have python 3.8 installed via homebrew.

    Is this something that has happened to more people? Is there a fix already or is this a new bug?

    Thanks for coconut though, it's a really cool language (and much less scary than something like Haskell (-; )

    compatibility resolved 
    opened by regr4 11
  • Pattern matching raises ParseError when using return type annotation

    Pattern matching raises ParseError when using return type annotation

    def h(a is int, b is int): return a + b  # compiles
    def h(a is str, b is str) = a + b  # fine
    def g(a is int, b is int) -> int: return a + b  # raises error
    def g(a is str, b is str) -> str = a + b
    
    feature resolved 
    opened by ArneBachmann 11
  • Performance

    Performance

    Sorry for not being very constructive, but the Coconut compiler|s performance is somewhat abysmal. For a 500 LOC tool it takes about 10 seconds on my Linux laptop, and 15s on my 4 years old Windows PC. This is simply too slow for the typical Python REPL testing/prototyping workflow.

    Any ideas on how to improve on speed?

    performance question resolved 
    opened by ArneBachmann 11
  • Return type annotations for statement lambdas

    Return type annotations for statement lambdas

    Unfortunately, since -> is used for the lambda itself, we can't also use it for the return type annotation. Thus, instead, we'd be forced to implement something like

    f = def (x: int): int -> x
    

    which is somewhat confusing, making this a bit questionable.

    feature 
    opened by evhub 0
  • Improve set matching

    Improve set matching

    Should match dictionary mapping semantics, such that

    {1, 2, 3} = some_set
    

    matches if {1, 2, 3} <= some_set, rather than {1, 2, 3} == some_set, with explicit syntax in the form of

    {1, 2, 3, *()} = some_set
    

    for checking {1, 2, 3} == some_set.

    Note that this would be a breaking change, as was the previous change to dict matching.

    modification feature 
    opened by evhub 0
  • Fix imports binding `sys` to a local

    Fix imports binding `sys` to a local

    We need to use the actual variable name sys because mypy requires it, so our only real option here is to make sys an unredefinable built-in, like _coconut names, so that we can guarantee that the name sys will always globally refer to what we want and thus we don't have to redefine it locally.

    oversight 
    opened by evhub 1
  • Make typing functions using protocols more ergonomic

    Make typing functions using protocols more ergonomic

    Should compile

    def func[T <: (+) & (*)](x: T, y: T) -> T = x + x * y
    

    to the equivalent of

    def func[T <: ProtocolIntersection[SupportsAdd, SupportsMul]](x: T, y: T) -> T = x + x * y
    

    where SupportsAdd is some special Coconut typing.Protocol for supporting __add__ and ProtocolIntersection is from here.

    feature 
    opened by evhub 0
  • Add syntax for implicit coefficients

    Add syntax for implicit coefficients

    Should compile

    5 x**2 + 2 x
    

    to

    5 * x**2 + 2 * x
    

    The biggest problem, unfortunately, is that this would have a different precedence than implicit function application f x currently has, since

    a x**2 + b x
    

    is currently valid and compiles to

    a(x)**2 + b(x)
    

    Probably, the best way to do this is to change the precedence of implicit function application to be just tighter than */@ and have implicit function application check if the function is an int/float/numpy dtype and in that case use multiplication rather than function application. However, this would be a breaking change.

    modification feature 
    opened by evhub 2
Releases(v2.2.0)
  • v2.2.0(Dec 30, 2022)

    See Coconut's documentation for more information on all of the features listed below.

    Major changes:

    • #694: New multiset built-in based on collections.Counter, including new multiset literal syntax (m{1, 1, 2, 3, 3, 4}).
    • #691: New Expected built-in based on Haskell's Either, plus new safe_call built-in that calls a function while collecting any errors into an Expected. Additionally, the of built-in has been renamed to call (of is still available as a deprecated alias when compiled without --strict).
    • #701: New windowsof built-in for iterating over sliding windows of the given iterable.
    • #688: New cartesian_product built-in as an enhanced version of itertools.product including numpy support.
    • #690: New cycle built-in as an enhanced version of itertools.cycle.
    • #704, #703, #702, #693, #692: Lots of improvements to existing built-ins:
      • map now supports a strict=True keyword-only argument that works as in zip.
      • flatten now supports a levels argument for how many levels to flatten.
      • groupsof now supports a fillvalue argument to pad the last group.
      • addpattern now accepts any number of pattern-matching functions.
      • memoize now accepts a function to memoize as the first argument.
    • #710: New None-aware function composition pipes (e.g. f ..?> g).

    Minor changes:

    • #686: Type parameter bounds can (and should) now use <: syntax instead of : or <= (e.g. def f[T <: int[])(xs: T) -> T = ...).
    • #711: Backwards None-aware pipes now supported (e.g. <?|).
    • #708: Pattern-matching against data types with default arguments now allows those defaults to be elided in the match.
    • #697: :: now produces a reiterable object when called on reiterable objects.
    • #706: Multiple Coconut projects should now be able to seamlessly use each other's MatchErrors when compiled in --package mode.
    • #695: Set literal syntax now supports star unpacking.
    • #699: Support for __bool__ magic method fixed on Python 2.
    • #687: Jupyter kernel and other automatic compilations now uses --no-wrap.
    • #685, #684: Improved detection of code issues on and off --strict.
    • #700: Some confusing unicode alternatives were removed.
    • #698: Typing for fmap has been improved.
    • #689: Improved numpy support for some built-ins.
    • #705: Many Coconut built-ins have now been made weakrefable.
    Source code(tar.gz)
    Source code(zip)
  • v2.1.1(Nov 14, 2022)

    v2.1.1 is a relatively small release on top of v2.1.0 primarily releasing now to provide Python 3.11 support, though v2.1.1 also has a couple of exciting new features, primarily Coconut's new type parameter syntax. See Coconut's documentation for more information on all of the features listed below.

    Bugfixes:

    • #682: Coconut no longer errors out on Python 3.11.

    Major changes:

    • #677: New type parameter syntax following PEP 695! For example: type a generic function as def ident[T](x: T) -> T = x.

    Minor changes:

    • #679: Error and logging output is now colored on terminals that support it.
    • #678: Non-mypy type checkers should now have an easier time type-checking Coconut code.
    • #680: New async (...) -> ... and (..., **P) -> ... enhanced type annotation constructs for Callables following PEP 677.
    • #644: f = async def x -> x async statement lambda syntax now supported.
    • #624: x |> (.+1) syntax now produces better optimized compiled Python.
    • #681: case/match syntax now deprecated on --strict in favor of Python 3.10 match/case syntax.
    Source code(tar.gz)
    Source code(zip)
  • v2.1.0(Oct 25, 2022)

    Though a small release relative to v2.0.0, v2.1.0 includes a couple of pretty exciting changes, most notably custom operators and substantial performance improvements. See Coconut's documentation for more information on all of the features listed below.

    Major changes:

    • #4, #674: Coconut now supports custom operators! See the documentation for more information on how to declare, define, and use custom operators.
    • #147: Very substantial performance improvements (up to 100x) when compiling small quantities of code (e.g. at the interpreter, in Jupyter notebooks, when using xonsh, etc.). Compile times for large files should be unchanged.
    • #673: New multi_enumerate built-in for enumerating multi-dimensional arrays (e.g. numpy arrays).

    Minor changes:

    • #385: Universalized imports no longer trigger mypy errors.
    • xonsh support updated to the latest xonsh version, should now be enabled by default without requiring xonsh install coconut, and should now be substantially faster.
    • #672: New in <expr> pattern for easier containment checking in pattern-matching.
    • #556: Coconut now respects NOQA/noqa comments when showing warnings for unused imports in --strict mode.
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Sep 26, 2022)

    Coconut v2 is here! This is Coconut's first ever major version release since Coconut was first published, and it comes with some breaking changes, detailed below. Care has been taken to keep v2 as backwards-compatible as possible, but Python 3.10 adding pattern-matching of its own that conflicted with some of Coconut's old pattern-matching rules meant that breaking changes were going to be inevitable to ensure full compatibility.

    Additionally, v2 introduces some pretty major new features such as multidimensional array literal/concatenation syntax! Check it all out below and see Coconut's documentation for more information on all of the features listed.

    Breaking changes:

    • #605: Coconut pattern-matching is now fully unified with Python 3.10 pattern-matching: pattern-matching always works the same way regardless of where it is used, always uses Python 3.10 rules, but also always supports all additional Coconut pattern-matching features. Some implications of this:
      • Coconut now fully supports class patterns everywhere, including in pattern-matching function definition and destructuring assignment.
      • As a result, x is int type-checking syntax is now deprecated in favor of using the int(x) class pattern. For cases where there is no rewriting as a class pattern, x `isinstance` int syntax is also supported.
      • Pattern-matching for dictionaries has been changed so that {"a": a} now matches a dictionary with at least "a" as a key rather than exactly "a" as its only key to be consistent with Python 3.10. Coconut will warn if such syntax is detected and suggest the explicit {"a": a, **_} or {"a": a, **{}} syntax instead.
    • #639: Coconut data types no longer support adding or multiplying them like tuples unless explicitly added via __add__/__mul__ methods.
    • #623: fmap over a Mapping (e.g. dict) now does a normal map instead of a starmap. Thus, you'll need to do fmap$(def ((k, v)) -> (new_k, new_v)) instead of fmap$((k, v) -> (new_k, new_v)). Old behavior can also be recovered with fmap$(starmap_over_mappings=True).
    • #615: ($[]) spelling for the iterator slicing operator function has been removed in favor of .$[] and the normal getitem operator has been added as .[].
    • #613: Precedence of the function composition operator .. has been lowered such that f x .. g y is now equivalent to (f x) .. (g y) rather than ((f x) .. g) y.
    • #635: initializer keyword argument in scan changed to initial to match the function signature of reduce.

    New language features:

    • #628, #670: New multidimensional array literal and concatenation syntax! Concatenate two arrays with [a ; a], write out 2D array literals as [1, 2;; 3, 4], with the number of semicolons denoting the axis from the end on which to concatenate.
    • #258, #669: New syntax for partially applying operator functions: (.+1), (a+.), (.<|x), including support for custom operators as (. `plus` x).
    • #663: Better syntax for typing tuples: instead of x: typing.Tuple[int, str], just: x: (int; str).
    • #633: New pattern-matching for loops, allowing for arbitrary destructuring pattern-matching in for loops.
    • #622, #650: New anonymous named tuples for giving names to fields in temporary tuples. Just: (a=1, b=2).
    • #626: New syntax for using partial application to convert a keyword argument into a positional argument. Just: func$(kwd_arg=?).
    • #612: Combinators! Use lift to "lift" a function up so that its arguments become unary functions. Also: ident, flip, const, of.
    • #616, #620: New all_equal and collectby built-ins for working with iterables.
    • #124: fmap now supports asynchronous iterators.
    • #365 (thanks @ArneBachmann!): Equality checking with =<expr> has been deprecated in favor of ==<expr>; the former syntax will now raise an error in --strict mode.
    • #648: Class patterns now support a strict .attr=<match> syntax that raises an error if the attr isn't present rather than failing the match.
    • #641: Iterable destructuring patterns now support a substantially wider array of allowable destructuring constructs (e.g. [1] + x + [2] + y + [3]).
    • #603: New as x (to explicitly bind a variable) and is x (to do an identity check) pattern-matching constructs.
    • #434 (thanks @ArneBachmann!): Conditional assignment using pattern-matching; infix patterns have been improved to support a `pred` or b = <expr> syntax that binds to a if pred and b otherwise.
    • #670: jax support in fmap and multidimensional array literal/concatenation.
    • #617, #647: New comma operator function (,) for joining arguments into a tuple and new (raise) operator function for raising an exception.
    • #625: Matrix multiplication operator @ now supported on all Python versions.
    • #649 (thanks @hlizard!): Zero-argument super() now supported on all Python versions.
    • #664: Coconut will now automatically backport typing imports into typing_extensions imports when necessary.
    • #490 (thanks @pavelbraginskiy!): := assignment expressions can now be chained without parentheses.
    • #640: f-strings now supported in pattern-matching string patterns.

    New compiler features:

    • #632: Substantially improved syntax error messages with much finer-grained identification of the error location.
    • #636: Coconut can now be used as a xontrib in the xonsh shell to enable Coconut syntax.
    • #658: Coconut now supports papermill.
    • #575: Better interpreter auto-completing.
    • #629 (thanks @tbsexton!): New coconut[kernel] installation option for installing only lightweight Jupyter kernel dependencies compared to the full support offered by coconut[jupyter].
    • #646: Better coconut.convenience API.

    Bugfixes:

    • #638 (thanks @ivanmkc!): coconut --watch for watching files for changes to be recompiled fixed.
    • #657 (thanks @tbsexton!): Jupyter kernel compatibility with new Jupyter/IPython versions fixed.
    • #616: Iterator slicing no longer exhausts the entire iterator except when strictly necessary.
    • #631: Fixed pattern-matching on numpy arrays by registering them as Sequences.
    • #656 (thanks @hlizard!): Compilation on Windows should no longer convert names of compiled files to lowercase.
    • #627 (thanks @fakuivan!): Support for starred function arguments before positional function arguments.
    • #653 (thanks @fakuivan!): Fixed dotted names in class/data patterns.
    • #655 (thanks @hlizard!): Certain complex f-strings no longer trigger internal Coconut exceptions.
    • #667 (thanks @tom-a-horrocks!): Rare interpreter crashes fixed.
    Source code(tar.gz)
    Source code(zip)
  • v1.6.0(Nov 6, 2021)

    Barring any necessary hotfixes, this release, v1.6.0, will be the last release on the v1.X.X branch—which means next up is Coconut v2! Coconut v2 will include substantial backwards-incompatible changes to Coconut's pattern-matching syntax, as well as likely including other backwards-incompatible changes as well.

    Coconut v1.6.0 includes a substantial list of new features, many of which have been added in anticipation of Coconut v2. See Coconut's documentation for more information on all of the features and bugfixes listed below.

    New language features:

    • #558, #601: Coconut now fully supports Python 3.10 pattern-matching syntax, including compiling Python 3.10 pattern-matching syntax to any Python version and mixing and matching between Python 3.10 pattern-matching and Coconut pattern-matching (including in destructuring assignment and pattern-matching function definition).
    • #566: Coconut can now specifically target Python 3.9, Python 3.10, and/or Python 3.11.
    • #425 (thanks @ExpHP for the issue!): Coconut pattern-matching now supports view patterns that allow calling a function in pattern-matching and matching on the result.
    • #607: Coconut pattern-matching now supports infix patterns that allow calling a binary boolean function in pattern-matching and matching only if the return value is truthy.
    • #570: Coconut now supports an @override built-in that, when used to decorate a method, asserts that it is overwriting some method from a base class.
    • #582, #583 (thanks @aananko for the issue!): Coconut now supports a flatten built-in for flattening one layer of an iterable of iterables.
    • #574: Coconut now supports reveal_type and reveal_locals built-ins that will print the inferred type of the contained expression when compiled with coconut --mypy.
    • #421: Coconut now supports yield def function definition syntax for explicitly specifying that you want a generator function, regardless of whether a yield actually occurs somewhere in the function.
    • #598: Coconut now supports if condition then x else y ternary syntax in addition to Python's x if condition else y ternary syntax.
    • #544: Coconut now supports the additional .[0][1] and .a.b(c) implicit partials.
    • #348 (thanks @ArneBachmann for the issue!): Pattern-matching functions now support return type annotations (though not argument type annotations).
    • #289: Coconut now supports dict, tuple, and list star and double-star unpackings across all Python versions.
    • #571 (thanks @tbsexton for the issue!): Coconut now fully supports Python 3.10 int | bool type annotation syntax, including compiling it to any Python version.
    • #572: Coconut's zip and zip_longest built-ins now supports a Python-3.10-style strict keyword argument on all Python versions.
    • #307: Coconut now supports class A(metaclass=...) syntax on all Python versions, including compiling to universal code to support Python 2.
    • #495 (thanks @pavelbraginskiy for the issue!): Coconut now supports exec as a function on all Python versions.
    • #352 (thanks @ArneBachmann for the issue!): Coconut will now compile enum imports into aenum imports on targets that don't support enum.
    • #365 (thanks @ArneBachmann for the issue!): Coconut now supports == instead of = as the prefix for equality checking in pattern-matching (this will be made mandatory in Coconut v2).
    • #576: Coconut's case syntax now allows a cases keyword to be used at the top level instead of the case keyword for clarity.
    • #603: Coconut now supports optional as x explicit name-binding syntax in pattern-matching.
    • #567: Coconut now supports in-line augmented global/nonlocal assignments.

    New compiler features:

    • #586, #591 (thanks @tbsexton for the issue!): Coconut now has an official VSCode highlighting extension.
    • #587, #595 (thanks @nlipsyc for the PR!): Coconut now supports an --and src dest flag for compiling additional files/directories with the same coconut command, including splitting the compilation across multiple processes when --jobs is passed.
    • #497 (thanks @matanagasauce for the issue!): Coconut now supports a # coding: coconut header in .py files to use Coconut syntax along with a coconut --site-install command to make all such automatic compilation behavior available without first importing coconut.convenience.
    • #596, #597 (thanks @lazyprop for the PR!): Coconut now supports a --vi-mode flag and COCONUT_VI_MODE environment variable for enabling vi mode in the interpreter.
    • #386 (thanks @ArneBachmann for the issue!): Coconut will now throw more informative error messages for many common syntax errors.
    • #611: Installing all the dependencies that Coconut uses to backport old code is now be done by installing coconut[backports] rather than individually as in installing coconut[asyncio].

    Bugfixes:

    • #577: As long as a dataclasses library exists at runtime, all Coconut targets now support x: int syntax for specifying the fields of a dataclass.
    • #578: Bound method are now properly tail call optimized.
    • #604: When pattern-matching fails, it should no longer make any variable assignments (though in case of a guard, the variable assignments will still occur prior to the guard being run and will persist if the guard fails).
    • #580 (thanks @leogao2 for the issue!): Coconut's parallel_map is now substantially more efficient in processing very large iterators.
    • #602: or and | in pattern-matching will no longer sometimes run duplicate checks.
    • #593: --no-wrap now disables from __future__ import annotations on Python 3.7+.
    • #334: In-place pipe operators are now optimized the same as normal pipe operators.
    • #543: Keyword-only function arguments will now raise a more informative error on unsupported targets.
    • #588 (thanks @servadestroya for the issue!): Coconut will now properly compile vanilla Python destructuring assignment in with statements.
    • #592 (thanks @servadestroya for the issue!): Coconut will now properly concatenate naked f-strings placed next to each other.
    • #519 (thanks @bj0 for the issue!): Coconut will no longer compile := operators inside of :: expressions to invalid Python.
    • #585 (thanks @Gurkenglas for the issue!): Coconut now has better handling of permission errors in Jupyter kernel installation.

    Coconut v1.6.0 should also compile about 10% faster on average than Coconut v1.5.0.

    Source code(tar.gz)
    Source code(zip)
  • v1.5.0(Mar 6, 2021)

    See Coconut's documentation for more information on everything listed below.

    Features

    • #545: Added support for embedding a Coconut interpreter for debugging; just from coconut import embed; embed().
    • #562: All lazy lists are now reiterable.
    • #550: All enhanced built-ins are now reiterable when given an iterable.
    • #542: New None-aware pipe operators.
    • #105: New zip_longest built-in.
    • #552: Full PEP 553 (breakpoint built-in) support on all Python versions.
    • #531: Add support for = specifier in f-strings.
    • #508: Added .multiple_sequential_calls() context managers to parallel_map and concurrent_map.
    • #540: Add nb_conda_kernel support (thanks @tbsexton for reporting the issue).
    • #514, #523: Added --no-wrap flag (thanks @QuestofIranon for the PR!).
    • #547: Added Coconut homebrew installation (thanks @SeekingMeaning for making this happen!)

    Bugfixes:

    • #548: Significantly improve pattern-matching performance.
    • #561: Fix Python 3.9 issues (thanks @BruceEckel for reporting the issue).
    • #551: Fix issues with new Jupyter kernel (thanks @regr4 for reporting the issue and @bj0 for finding the root cause).
    • #281: Fix coconut --jupyter calling the wrong Jupyter installation (thanks @betabrain for reporting the issue).
    • #560: Fix error on non-numeric setuptools versions (thanks @fabianhjr for the PR!).
    • #559: Fix nested f-string parsing (thanks @bjo for reporting the issue).
    • #553: Proper PEP 563 support (now Coconut doesn't wrap annotations in strings when they'll be deferred anyway).
    • #536: Fixes iterator returns on all Python versions.
    • #541: Prevent accidentally compiling to source files (thanks @dryprogrammer for reporting the issue).
    Source code(tar.gz)
    Source code(zip)
  • v1.4.3(Jan 7, 2020)

    See Coconut's documentation for more information on everything listed below.

    Bugfixes:

    • #527: Coconut once again builds properly on Python 2 (thanks @hasufell for the issue!)
    • #526: fixes = function definition returning string literals not working (thanks @vietspaceanh for the issue!)
    • attributes now work properly in implicit function application (e.g. f b.x c.y)
    Source code(tar.gz)
    Source code(zip)
  • v1.4.2(Dec 9, 2019)

    See Coconut's documentation for more information on all of the features listed below.

    Bugfixes:

    • #521: prevents Coconut from installing an incompatible version of cPyparsing by default
    • #515: prevents Coconut from installing trollius on Python 3 when doing pip install coconut[all] (thanks @DennisMitchell for the issue!)

    New features:

    • #496, #506: addpattern now issues a warning if passed a non-pattern-matching function unless allow_any_func=True is passed (thanks @m-burst for the PR and @pavelbraginskiy for the issue!)
    • #517: simple implicit function application such as f x y is now supported
    Source code(tar.gz)
    Source code(zip)
  • v1.4.1(Aug 8, 2019)

    See Coconut's documentation for more information on all of the features listed below.

    New features:

    • #465: new addpattern def shorthand syntax (thanks @MichalMarsalek for the issue!)
    • #301, #504, #505: full support for Python 3.6 f-strings on all targets including (thanks @m-burst for the PR!)
    • #323: added support for |**> kwargs pipes (thanks @ArneBachmann for the issue!)
    • #490: new (assert) operator function (thanks @arnauorriols for the issue!)
    • #503: added support for Python 3.8 positional-only arguments (thanks @pavelbraginskiy fo the issue!)
    • #483: fmap now works on numpy arrays (thanks @hoishing for the issue!)
    • #494: added support for pattern-matching in data definitions (thanks @arnauorriols for the issue!)
    • #493: added truncation for long MatchError messages (thanks @arnauorriols for the issue!)
    • #482: added support for Python 3.8 assignment expressions under --target 3.8 (thanks @terrdavis for the issue!)
    • #446, #458: data types are now hashable (thanks @m-burst for the PR!)
    • #502: addpattern, recursive_iterator, and TCO'd functions are now pickleable
    • #488: fewer __coconut__.py files are created when compiling in --package mode

    Plus lots and lots of bugfixes!

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Aug 16, 2018)

    See Coconut's documentation for more information on all of the features listed below.

    New features:

    • #320: added import hook to automatically compile imported Coconut files (thanks @ArneBachmann!)
    • #347: added where clauses
    • #270: added a memoize decorator (thanks @iamrecursion!)
    • #403: added a TYPE_CHECKING constant
    • #409: added support for M `bind` x -> y syntax
    • #419: data type equality is now typed (thanks everyone in #418!)
    • #331: support negative pattern-matching with match ... not in ...
    • #411: count now supports a step size of 0
    • #394: scan now has an initializer argument
    • #398: creating a new indented block after a colon is no longer necessary for any statement
    • #229: --strict now warns on unused imports
    • #327: interpreter now supports reload built-in (thanks, @ArneBachmann!)
    • #382: interpreter now supports compiling to arbitrary file names
    • #393: unicode operators for multiplication and matrix multiplication have been switched
    • #153: function composition precedence is now such that f..g(x) is the same as f..(g(x)) not (f..g)(x)
    • #395: built-in attributes changed to remove initial underscores

    Plus lots and lots of bugfixes!

    Source code(tar.gz)
    Source code(zip)
  • v1.3.1(Oct 23, 2017)

    This is a bugfix release for v1.3.0. See v1.3.0 below for all the most recently added features.

    Fixes:

    • #326: fixed Jupyter kernel installation (thanks, @auscompgeek!)
    • #333: fixed --watch placing compiled files in the wrong location (thanks, @dileep-kishore!)
    • #337: fixed --jupyter console on Windows (thanks, @mlarocca!)
    • #317: fixed numerous MyPy errors (thanks, @ArneBachmann!)
    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Sep 4, 2017)

    See Coconut's documentation for more information on all of the features listed below.

    New features:

    • #220: new function composition pipe operators (thanks, @cgarciae!)
    • #243: new none-aware operators
    • #200: new enhanced type annotation syntax (thanks, @fredcallaway!)
    • #257: data types now support default arguments
    • #276: data types now support type annotations (thanks, @jonathanplatzer!)
    • #275: pipes and infix calls now support lambdas in them
    • #256: new string destructuring pattern-matching
    • #267: improved dictionary pattern-matching (thanks, @cgarciae!)
    • #284: new starmap built-in
    • #271: new reiterable built-in (thanks, @pchampin!)
    • #266: new scan built-in
    • #297, #309: new groupsof built-in (thanks, @kbaskett248!)
    • #303: datamaker deprecated in favor of new makedata built-in
    • #283: prepattern deprecated
    • #282: fmap of a mapping now iterates over its .items()
    • #286: new --argv command-line option
    • #300: Coconut now installable via conda
    • #53: now supports cPyparsing for faster parsing

    Fixes:

    • #280: fixed infix notation associativity
    • #268: tail call optimization now significantly faster
    • #147: removed interpreter lag on first line of code
    • #279: prettier interpreter errors
    • #298: pattern-matching function docstrings now actually get bound to __doc__
    • #285: type: ignore comments now work properly
    • #255: fixed nested attribute getter implicit partial (thanks, @Socialery!)
    • #269: fixed segfault in non-iterator functions (thanks, @pchampin!)
    • #264: fixed recursive_iterator error (thanks, @pchampin!)
    • #308: fixed importing StringIO and BytesIO on Python 2 (thanks, @cgarciae!)
    • #295: fixed Cygwin error (thanks, @halloleo!)
    • #288: fixed Pythonista installation error (thanks, @iamrecursion!)
    • #277: fixed Jupyter kernel installation error (thanks, @petrilli!)
    • #311: now gracefully handles old pyparsing versions
    • #294: piping into partials no longer creates intermediate partial objects
    Source code(tar.gz)
    Source code(zip)
  • v1.2.3(May 15, 2017)

    See Coconut's documentation for more information on all of the features listed below.

    New features:

    • #237: new fmap built-in that preserves data types (thanks, @hasufell!)
    • #214: data name(*args) syntax now supported
    • #227: data from syntax for data type inheritance
    • #232: --no-tco option to disable tail call optimization (also implied by --mypy)
    • #228: .method(**kwargs) implicit partial now supported
    • #231: .[a:b, c:d] implicit partial now supported (thanks, @cgarciae!)
    • #226: PEP 542 dotted function names now supported

    Fixes:

    • #221, #234: Jupyter kernel issues resolved (thanks, @cgarciae!)
    • #224, #189: issues with --watch flag resolved (thanks, @Nexus6!)
    • #246: conda installation bug fixed (thanks, @bmcguirk!)
    • #238: dependencies weakened for easier installation (thanks, @hasufell!)
    • #215: mingw/cygwin bug fixed (thanks, @marawuti!)
    Source code(tar.gz)
    Source code(zip)
  • v1.2.2(Feb 20, 2017)

    See the previous release, v1.2.1, for information on recently released features. v1.2.2 is simply a bugfix release for v1.2.1.

    Fixes:

    • Version-dependent requirements are now properly installed when installing Coconut (thanks @Nexus6!)
    • Jupyter kernel works properly on Python 2 (thanks @DavidPratten!)
    • Jupyter kernel performance significantly improved (thanks @cgarciae!)
    • MyPy support is faster and emits fewer spurious errors
    • Fails nicely on missing optional dependencies (thanks @Nexus6!)
    Source code(tar.gz)
    Source code(zip)
  • v1.2.1(Feb 15, 2017)

    See Coconut's documentation for more information on all of the features listed below.

    New features:

    • --mypy flag for automatic type-checking (including real-time in the REPL)
    • Support for Python type annotations on all versions
    • New enhanced partial application (e.g. func$(?, y)) (thanks @Sitwon!)
    • Tail recursion elimination added in addition to tail call optimization
    • Support for %magic commands on Coconut's Jupyter kernel
    • Syntax highlighting for Coconut's Jupyter kernel
    • Support for keyword and star arguments in pattern-matching function definition
    • Support for pattern-matching in statement lambdas (e.g. def (x is int) -> x)
    • Adds coconut-run command with shebang support (e.g. #!/usr/bin/env coconut-run)
    • Support for COCONUT_STYLE environment variable for setting a default --style
    • New CONTRIBUTING.md
    • New Czech translation (thanks @Tovim!)

    Fixes:

    • Method calls are now valid implicit partials (e.g. .method(args))
    • Compilation speed significantly increased
    • Fixed running IPython %coconut command multiple times
    • Fixed --watch compiling files twice (thanks @Nexus6!)
    • Version restrictions on dependencies loosened
    • Enhanced reversed and enumerate built-ins (thanks @Nexus6!)
    • Fixed calling methods on integer literals (thanks @DomoSokrat!)
    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Sep 24, 2016)

    Colonel is the next major release of Coconut, and makes major feature additions and minor breaking changes over v1.1.1 [Brontosaurus]. See the updated documentation for more information on everything below.

    Breaking changes:

    • removed @recursive (now does auto tco)
    • function composition (..) precedence changed
    • removed --autopep8 flag

    New features:

    • automatic tail call optimization
    • statement (multiline) lambdas
    • command-line syntax highlighting
    • --jobs flag
    • assignment function notation
    • @recursive_iterator
    • star pattern matching
    • implicit pass for data and class
    • inline nonlocal and global statements
    • --keeplines flag
    Source code(tar.gz)
    Source code(zip)
  • v1.1.1(Jul 6, 2016)

    v1.1.1 [Brontosaurus] makes only minor feature additions over v1.1.0 [Brontosaurus], and should be fully backwards-compatible. The major changes were:

    • Adding a --watch flag (#99, #106, thanks @Boscillator!)
    • Improving Jupyter / IPython console autocompletion (#114)
    • Adding methodcaller implicit partial (#112)
    • Adding links to 3rd party Vim and Emacs highlighters (thanks, @manicmaniac and @NickSeagull!)
    • Adding pip install coconut[...] as a way to install optional dependencies
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Jun 24, 2016)

    Brontosaurus makes notable feature additions over v1.0.0 [Albatross], but should be fully backwards-compatible. The major changes were:

    • Adding addpattern and prepattern built-ins (#92, #103)
    • Changing recommended file extension from .coc to .coco (#88)
    • Making interpreter print the result of an expression (#100, thanks @Boscillator!)
    • Fixing IPython / Jupyter kernel support (#97)
    • Adding support for guards in pattern-matching function definition (#98)
    • Upgrading to pyparsing 2.1.5
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Jun 17, 2016)

    Albatross is the first production release (v1.0.0) of the Coconut programming language. No new features have been added since Pinnate (v0.4.1), although there have been major stability improvements. For documentation, see our new website at http://coconut-lang.org.

    Source code(tar.gz)
    Source code(zip)
  • v0.4.1(Apr 11, 2016)

    Pinnate (v0.4.1) is the first candidate release for v1.0.0. The language has become relatively stable and is unlikely to change much until a release is selected for v1.0.0.

    Massive changes have been made to Coconut since Odisha (v0.3.6). If you've been following Coconut development, you should read the new tutorial and go over the new documentation to familiarize yourself with all the changes.

    Pinnate is the type of leaf on the Coconut palm.

    Source code(tar.gz)
    Source code(zip)
  • v0.3.6(Jan 11, 2016)

    Major Changes:

    • New: --package or -p and --standalone or -a flags for forcing the type of compilation to perform
    • --print or -p is now --display or -d (-d is no longer an alias of --debug)
    • Fixes issues in data mutability and augmented assignment
    • Significantly increases compilation speed

    Odisha is a part of India famous for its coconuts.

    Source code(tar.gz)
    Source code(zip)
  • v0.3.5(Dec 14, 2015)

    Major Changes:

    • New: Built-in consume function for efficiently exhausting iterators
    • New: Only recompiles changed files (will recompile all files if --force is passed)
    • Improves (-) to support subtraction and negation
    • Improves Python-version-cross-compatibility for str, bytes, and open
    • Warns on mixing of tabs and spaces even if --strict isn't passed
    • Changes coconut.convenience.setup function

    Cocos Nucifera is the scientific name for the coconut tree.

    Source code(tar.gz)
    Source code(zip)
  • v0.3.4(Nov 17, 2015)

    Major Changes:

    • New: Built-in datamaker function for writing data.__new__ constructors
    • Removes itemgetter, attrgetter, and methodcaller from built-ins in favor of implicit partial application
    • Supports slice objects in iterator slicing
    • Fixes incompatibility with newest pyparsing

    Macapuno is a type of mutant coconut commonly used in desserts.

    Source code(tar.gz)
    Source code(zip)
  • v0.3.3(Nov 2, 2015)

    Major Changes:

    • New: In-place lazy chaining
    • New: Enhanced imaginary literals
    • Fixed error message line numbers
    • Fixed --runing a file with imports
    • Fixed interpreter scoping

    Lauric acid is the primary fatty acid found in coconuts.

    Source code(tar.gz)
    Source code(zip)
  • v0.3.2(Oct 25, 2015)

    Major Changes:

    • New: Lazy chaining
    • New: Head-last pattern-matching
    • New: Lazy list pattern-matching
    • Fixed empty and one-item lazy lists
    • Improved Python version cross-compatibility
    • Fixed interpreter errors

    Kopyor is the Indonesian name for a macapuno coconut.

    Source code(tar.gz)
    Source code(zip)
  • v0.3.1(Oct 14, 2015)

    Major Changes:

    • New: Lazy lists
    • New: Pattern-matching function definition
    • New: Enhanced except statements
    • New: __coconut_version__ built-in
    • def is now mandatory in mathematical function definition
    • Match failures now raise MatchError instead of ValueError
    • Added coconut.convenience.parse(mode="exec")

    Jawz Hindi is the Arabic word for Coconut, translated literally as Indian Nut.

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Sep 20, 2015)

    Major Changes:

    • New: Destructuring assignment
    • New: Implicit partial application
    • New: Additional pipeline operators
    • Changed non-decimal integer syntax from 101_2 to 2_101
    • Improved error messages
    • coconut.convenience.version("full") is now coconut.convenience.version("spec")

    Ilocos is an area in the Philippines that is a major producer of coconuts.

    Source code(tar.gz)
    Source code(zip)
  • v0.2.3(Aug 25, 2015)

    Major Changes:

    • New: Infix function definition
    • New: --target parameter
    • New: Support for Python 3.5 syntax
    • More Python-like interpreter

    Hawaii is one of the most iconic homes of the coconut tree.

    Source code(tar.gz)
    Source code(zip)
  • v0.2.2(Jul 6, 2015)

    Major Changes:

    • New: case blocks
    • New: Code passthrough
    • New: Checks in match statements
    • More Pythonic list and tuple matching
    • Fixed module docstrings
    • Reduced header size

    Guam was once home to many coconut plantations until they were destroyed by the coconut rhinoceros beetle.

    Source code(tar.gz)
    Source code(zip)
  • v0.2.1(Apr 30, 2015)

    Major Changes:

    • New: IPython Support
    • Improved Backtick Calling
    • Improved Convenience Functions
    • Improved Python 2/3 Universalizability
    • Improved Error Messages
    • Fixed Match Statement Errors
    • --exec is now --code

    Fiji is an island home to many coconut trees, including the eponymous Fiji Dwarf.

    Source code(tar.gz)
    Source code(zip)
Owner
Evan Hubinger
AI safety researcher at @machine-intelligence. Previously at @openai, @google, @Yelp, and @ripple.
Evan Hubinger
More routines for operating on iterables, beyond itertools

More Itertools Python's itertools library is a gem - you can compose elegant solutions for a variety of problems with the functions it provides. In mo

2.9k Jan 04, 2023
粤语编程语言.The Cantonese programming language.

粤语编程语言.The Cantonese programming language.

Stepfen Shawn 895 Dec 24, 2022
Cython implementation of Toolz: High performance functional utilities

CyToolz Cython implementation of the toolz package, which provides high performance utility functions for iterables, functions, and dictionaries. tool

894 Jan 02, 2023
Functional programming in Python: implementation of missing features to enjoy FP

Fn.py: enjoy FP in Python Despite the fact that Python is not pure-functional programming language, it's multi-paradigm PL and it gives you enough fre

Oleksii Kachaiev 3.3k Jan 04, 2023
A functional standard library for Python.

Toolz A set of utility functions for iterators, functions, and dictionaries. See the PyToolz documentation at https://toolz.readthedocs.io LICENSE New

4.1k Jan 03, 2023
Simple, elegant, Pythonic functional programming.

Coconut Coconut (coconut-lang.org) is a variant of Python that adds on top of Python syntax new features for simple, elegant, Pythonic functional prog

Evan Hubinger 3.6k Jan 03, 2023
A fancy and practical functional tools

Funcy A collection of fancy functional tools focused on practicality. Inspired by clojure, underscore and my own abstractions. Keep reading to get an

Alexander Schepanovski 2.9k Dec 29, 2022
Make your functions return something meaningful, typed, and safe!

Make your functions return something meaningful, typed, and safe! Features Brings functional programming to Python land Provides a bunch of primitives

dry-python 2.5k Jan 05, 2023