cbirds


Namecbirds JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryCombinatory Birds
upload_time2023-06-09 00:28:40
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords cbirds combinator birds combinator birds logic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cbirds

![](https://github.com/jotaalvim/cbirds/blob/main/cbirds_logo.png?raw=true)

---
## Combinator Birds

> This is a port of the haskell package [Data.Aviary.Birds](https://hackage.haskell.org/package/data-aviary-0.4.0/docs/Data-Aviary-Birds.html). Please check this out if you want to see more details about the birds.

``cbirds`` is a module intended for demonstration purposes rather than functional or practical use. The objective is to
support the **combinator birds** in a pointfree style programming.

The only way to make sense of function combinators in python would be in a pointfree context. 
Lucky for us, there is a [pointfree](https://pypi.org/project/pointfree/)
module that allows us, e.g., to compose functions smoothly and enable partial application of functions and methods. 

Pointfree style has a few downsides. I'm afraid this is an unsuccessful attempt to join python pointfree and the 
use combinator birds. It is just a matter of time before it becomes an unreadable mess.

## Examples

Let's define a function keephalf, keephalf is a function that return the first half of a list. 
```
>>> keephalf([1,2,3,4,5,6,7,8,9,10])
[1, 2, 3, 4, 5]
```

I'll start by defining our own (@pointfree) version of length, integer division and and take, 
these functions are going to useful in the making of keephalf.

```python
@pointfree
def pflen(l): return len(l) 
@pointfree
def div(a,x): return a // x
@pointfree
def take(n,l): return l[0:n]
```

Although the code below does not look like python I can guarantee you that it is!
In the examples bellow the * symbol means function composition (from the ``pointfree`` module). For the ones wanting to
reach the highest level of bird use, there's a combinator that composes functions: the **bluebird** but for reasons of
readability we'll use * ,for now. 

The most intuitive birds to use in the making of keephalf is the **phoenix**.
The phoenix passes a single value through two different functions, 
and pass the results to a two-parameter function. We'll also use the **idiot** bird, that is the identity function.

```python
#phoenix x y z w = x (y w) (z w)
#idiot x = x

keephalf = phoenix (take, cardinal (div,2) * pflen, idiot)
```

Let's try different birds now, let's use the **starling** and the **cardinal** .
The starling passes a value straight and also through a function to another function of arity 2, and the
cardinal that swaps the argument order.

```python
#starling = x y z = x z (y z)
#cardinal x y z = x (z y)

keephalf2 = starling (cardinal (take), cardinal (div,2) * pflen)
```

We can also use the **warbler** and the **cardinal__**. The warbler is a elementary duplicator, the cardinal__
pass first argument straight, and second argument through a function,
to a two-parameter function

```python
#cardinal_ x y z w = x (y w) z
#warbler x y = x y y
keephalf3 = warbler (cardinal_ (take , cardinal(div, 2) * pflen))
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "cbirds",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "cbirds,combinator,birds,combinator birds,logic",
    "author": "",
    "author_email": "Jo\u00e3o Alvim <joaoafonsoalvim@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/bb/0c/d9091590e29cde059974356021a88c97801aa1eca8bc5705a882032c3ccb/cbirds-0.1.0.tar.gz",
    "platform": null,
    "description": "# cbirds\n\n![](https://github.com/jotaalvim/cbirds/blob/main/cbirds_logo.png?raw=true)\n\n---\n## Combinator Birds\n\n> This is a port of the haskell package [Data.Aviary.Birds](https://hackage.haskell.org/package/data-aviary-0.4.0/docs/Data-Aviary-Birds.html). Please check this out if you want to see more details about the birds.\n\n``cbirds`` is a module intended for demonstration purposes rather than functional or practical use. The objective is to\nsupport the **combinator birds** in a pointfree style programming.\n\nThe only way to make sense of function combinators in python would be in a pointfree context. \nLucky for us, there is a [pointfree](https://pypi.org/project/pointfree/)\nmodule that allows us, e.g., to compose functions smoothly and enable partial application of functions and methods. \n\nPointfree style has a few downsides. I'm afraid this is an unsuccessful attempt to join python pointfree and the \nuse combinator birds. It is just a matter of time before it becomes an unreadable mess.\n\n## Examples\n\nLet's define a function keephalf, keephalf is a function that return the first half of a list. \n```\n>>> keephalf([1,2,3,4,5,6,7,8,9,10])\n[1, 2, 3, 4, 5]\n```\n\nI'll start by defining our own (@pointfree) version of length, integer division and and take, \nthese functions are going to useful in the making of keephalf.\n\n```python\n@pointfree\ndef pflen(l): return len(l) \n@pointfree\ndef div(a,x): return a // x\n@pointfree\ndef take(n,l): return l[0:n]\n```\n\nAlthough the code below does not look like python I can guarantee you that it is!\nIn the examples bellow the * symbol means function composition (from the ``pointfree`` module). For the ones wanting to\nreach the highest level of bird use, there's a combinator that composes functions: the **bluebird** but for reasons of\nreadability we'll use * ,for now. \n\nThe most intuitive birds to use in the making of keephalf is the **phoenix**.\nThe phoenix passes a single value through two different functions, \nand pass the results to a two-parameter function. We'll also use the **idiot** bird, that is the identity function.\n\n```python\n#phoenix x y z w = x (y w) (z w)\n#idiot x = x\n\nkeephalf = phoenix (take, cardinal (div,2) * pflen, idiot)\n```\n\nLet's try different birds now, let's use the **starling** and the **cardinal** .\nThe starling passes a value straight and also through a function to another function of arity 2, and the\ncardinal that swaps the argument order.\n\n```python\n#starling = x y z = x z (y z)\n#cardinal x y z = x (z y)\n\nkeephalf2 = starling (cardinal (take), cardinal (div,2) * pflen)\n```\n\nWe can also use the **warbler** and the **cardinal__**. The warbler is a elementary duplicator, the cardinal__\npass first argument straight, and second argument through a function,\nto a two-parameter function\n\n```python\n#cardinal_ x y z w = x (y w) z\n#warbler x y = x y y\nkeephalf3 = warbler (cardinal_ (take , cardinal(div, 2) * pflen))\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Combinatory Birds",
    "version": "0.1.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/jotaalvim/cbirds/issues",
        "repository": "https://github.com/jotaalvim/cbirds"
    },
    "split_keywords": [
        "cbirds",
        "combinator",
        "birds",
        "combinator birds",
        "logic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "099d2749d96d63120defe7ba68ced75aa04ff649c5ad2ef075f08dade7ef3cc8",
                "md5": "0cec8e574598aef7eaa6f906a7b9471f",
                "sha256": "a18fe873573a2bbd9146c6ef15710de79ba39236bfd9940daeb3592ac3442a87"
            },
            "downloads": -1,
            "filename": "cbirds-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0cec8e574598aef7eaa6f906a7b9471f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5671,
            "upload_time": "2023-06-09T00:28:34",
            "upload_time_iso_8601": "2023-06-09T00:28:34.565102Z",
            "url": "https://files.pythonhosted.org/packages/09/9d/2749d96d63120defe7ba68ced75aa04ff649c5ad2ef075f08dade7ef3cc8/cbirds-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bb0cd9091590e29cde059974356021a88c97801aa1eca8bc5705a882032c3ccb",
                "md5": "4b08a6b36df354d960f348099636aecf",
                "sha256": "4f01c8a6c87fe1cc8cb1a40259c862040b6aeb8ab804ff8ba8b245e76c723962"
            },
            "downloads": -1,
            "filename": "cbirds-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4b08a6b36df354d960f348099636aecf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5441,
            "upload_time": "2023-06-09T00:28:40",
            "upload_time_iso_8601": "2023-06-09T00:28:40.812870Z",
            "url": "https://files.pythonhosted.org/packages/bb/0c/d9091590e29cde059974356021a88c97801aa1eca8bc5705a882032c3ccb/cbirds-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-09 00:28:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jotaalvim",
    "github_project": "cbirds",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cbirds"
}
        
Elapsed time: 1.91768s