Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/masipcat/invars
Single assignment variables in Python
https://github.com/masipcat/invars
functional-programming python single-assignment
Last synced: 10 days ago
JSON representation
Single assignment variables in Python
- Host: GitHub
- URL: https://github.com/masipcat/invars
- Owner: masipcat
- License: gpl-3.0
- Created: 2018-12-07T19:00:27.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-07T23:59:37.000Z (almost 6 years ago)
- Last Synced: 2024-10-14T06:27:21.445Z (about 1 month ago)
- Topics: functional-programming, python, single-assignment
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# invars
This package brings *invariable variables* or **single assignment variables** to Python (like in [Erlang](http://erlang.org/doc/reference_manual/expressions.html#variables) and other functional programming languages).
**Examples**
```python
one = 1
two = 2
...
two += one # invalid!
``````python
total = 0
for i in range(4):
total += i # invalid!
```## Installation
```console
$ pip install invars
```## Usage
```
$ invars my_script.py
```## Why?
> In functional programming, assignment is discouraged in favor of single assignment. [...] Imperative assignment can introduce side effects while destroying and making the old value unavailable while substituting it with a new one
[Wikipedia](https://en.wikipedia.org/wiki/Assignment_%28computer_science%29#Single_assignment)
> Single assignment variables simplifies a lot of things because it takes out the "time" variable from your programs.
[Stack Overflow](https://stackoverflow.com/questions/11255632/the-purpose-of-single-assignment)
## TODO
- [ ] Integrate with `flakes8`