pystacker


Namepystacker JSON
Version 1.5.4 PyPI version JSON
download
home_pagehttps://github.com/remokasu/stacker
SummaryStacker: RPN Calculator in Python
upload_time2023-12-25 15:29:32
maintainer
docs_urlNone
authorremokasu
requires_python
licenseMIT License Copyright (c) 2023 Remokasu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords reverse-polish-calculator rpn terminal-app
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [**日本語  (Japanese)**](https://github.com/remokasu/stacker/blob/main/README_JP.md)


# Stacker: An RPN Calculator and Extensible Programming Language

[![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
[![PyPI version](https://badge.fury.io/py/pystacker.svg)](https://badge.fury.io/py/pystacker)
![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)

Stacker is a powerful Reverse Polish Notation (RPN) calculator built with Python, featuring basic mathematical operations and extensibility through plugins.

## Installation

### Prerequisites:
Ensure Python 3 is installed.

### Installation Options:

- Via pip:
    ```bash
    pip install pystacker
    ```

- From source:
    ```bash
    git clone git@github.com:remokasu/stacker.git
    cd stacker
    python setup.py install
    ```

## Feedback and Contributions

Feedback and contributions are welcome. Please submit issues or suggestions on the [Issues page](https://github.com/remokasu/stacker/issues).

## Dependencies

Stacker uses external libraries like NumPy and Python Prompt Toolkit. Ensure these are installed:
```bash
pip install numpy prompt_toolkit
```

## Usage

Run Stacker:
```bash
stacker
```
Or:
```bash
python -m stacker
```

Stacker supports standard arithmetic operations (+, -, *, /) and advanced functions (sin, cos, tan, etc.). Users can input commands in RPN format and extend functionality using custom plugins.

### Input Examples

Stacker allows for straightforward RPN input. For example:

- Single-line input:
  ```bash
  stacker:0> 3 4 +
  [7]
  ```

- Multi-line input:
  ```bash
  stacker:0> 3
  [3]
  stacker:1> 4
  [3, 4]
  stacker:2> +
  [7]
  ```

- #### Variables:
  - syntax: 
    ``` bash
    value $name set
    ```
  - example:
    ```bash
    stacker:0> 3 $x set
    ```
    In this example, we assign `3` to `x`.
    If you input an undefined symbol, you need to prefix the symbol name with a dollar sign ($). <br>
    From now on, when using `x`, the character 'x' will be pushed onto the stack and evaluated to return `3` when popped. <br>
    You can push the value of a symbol by prefixing it with @. <br>
    For example, `@x` will push `3`.
    ``` bash
    stacker:0> 3 $x set
    stacker:1> x
    [x]
    stacker:2> @x
    [x, 3]
    stacker:1> +
    [6]
    ```

- #### Conditionals:
  - if
    - syntax:
      ```bash
      {true_block} {condition} if
      ```
    - example:
      ``` bash
      stacker:0> 0 $x set
      stacker:1> {3 4 +} {x 0 ==} if
      [7]
      ```
      This example pushes `7` onto the stack because `x` is equal to `0`.
  - ifelse
    - syntax:
      ```bash
      {true_block} {false_block} {condition} ifelse
      ```
    - example:
      ``` bash
      stacker:0> 0 $x set
      stacker:1> {3 4 +} {3 4 -} {x 0 ==} ifelse
      [7]
      ```
      This example pushes `7` onto the stack because `x` is equal to `0`.

- #### Loops:
  - do
    - syntax:
      ```bash
      start_value end_value $symbol {body} do
      ```
    - example:
      ```bash
      stacker:0> 0 10 $i {i echo} do
      0
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      ```
      This example prints the numbers from 0 to 10.
  - times
    - syntax:
      ```bash
      {body} n times
      ```
    - example:
      ```bash
      stacker:0> 1 {dup ++} 10 times
      [1 2 3 4 5 6 7 8 9 10 11]
      ```
      In this example, we push 1 onto the stack and then repeat {dup (duplicate the top element) and ++ (add 1 to the top element)} 10 times.

- #### Define a function:
  - syntax:
    ```bash
    (arg1 arg2 ... argN) {body} $name defun
    ```
  - example:
    ```bash
    stacker:0> (x y) {x y *} $multiply defun
    stacker:1> 10 20 multiply
    [200]
    ```
    This defines a function named `multiply` that takes two arguments `x` and `y` and multiplies them together.

- #### Define a macro:
  - syntax:
    ```bash
    {body} $name alias
    ```
  - example:
    ```bash
    stacker:0> {2 ^ 3 * 5 +} $calculatePowerAndAdd alias
    stacker:1> 5 calculatePowerAndAdd
    [80]
    ```
    This defines a macro with the body `{2 ^ 3 * 5 +}` and assigns it the name `calculatePowerAndAdd`. This macro squares the number on the stack, multiplies it by 3, and then adds 5.

- #### Include Scripts
  Stacker scripts can be included in other scripts using the `include` command. For example:

  ``` bash
  stacker:0>  "my_script.stk" include
  ```
  All functions, macros and variables defined in "my_script.stk" are added to the current stack.


### Running Scripts
Stacker scripts can be created in *stk files. To run a script, simply execute it with Stacker. For example:

- my_script.stk:
  ```bash
  0 $p set
  0 100000 $k {
      -1 k ^ 2 k * 1 + / p + p set
  } do
  4 p * p set
  p echo
  ```

  Running the script:  
  ```bash
  stacker my_script.stk
  ```


### Command Line Execution
You can directly execute a specified RPN expression from the command line.

```bash
stacker -e "3 4 + echo"
```


## Settings
- disable_plugin
  Disable a specified plugin:
  ```bash
  stacker:0> "hoge" disable_plugin
  ```
  This command deactivates the `hoge` operator added as a plugin.
  Note that it cannot be used on non-plugin oeratirs.

- disable_all_plugins
  Disable all plugins at once.
  ```bash
  stacker:0> disable_all_plugins
  ```

- enable_disp_stack
  Enables the setting to display the stack contents each time. By default, this setting is already active.
  ```bash
  stacker:0> enable_disp_stack
  ```

- disable_disp_stack
  Sets the display of stack contents to be disabled. When this setting is enabled, only the latest element of the stack is displayed.
  ```bash
  stacker:0> disable_disp_stack
  ```

- disable_disp_logo
  Disables the display of the logo at startup.
  ```bash
  stacker:0> disable_disp_logo
  ```

## Configuration File
You can automatically load settings at startup. The configuration file should be placed in ~/.stackerrc. For example, if you write the following contents in ~/.stackerrc, the disable_disp_logo and disable_disp_stack will be automatically activated at startup.
```bash
disable_disp_logo
disable_disp_stack
```

## Creating Plugins

Create custom plugins for Stacker using Python:

1. In the `plugins` directory, create a new Python file for your plugin (e.g., `my_plugin.py`). 
    ``` 
    stacker/
    │
    ├── stacker/
    │   ├── plugins/
    │   │   ├── my_plugin.py
    │   │   └── ...
    │   │
    │   ├── data/
    │   ├── stacker.py
    │   ├── test.py
    │   └── ...
    │
    └── ...
    ```

    Adding your plugin here and reinstalling Stacker will apply the plugin permanently.

2. Alternatively, create a `plugins` directory in the directory where Stacker is executed. This allows you to use plugins without reinstalling Stacker.
3. Define required functions or classes in your plugin file.
4. Add a `setup` function to register these with Stacker.


Example:
```python
from stacker.stacker import Stacker

def function(a, b):
    # Do something

def setup(stacker: Stacker):
    stacker.register_plugin("command", function)
```

## Disabling Plugins
Use operatorName disable_plugin to disable a specific plugin.<br>
Use disable_all_plugins to disable all plugins.<br>


## Documentation
For more detailed documentation, please refer to [`stacker/docs`](https://github.com/remokasu/stacker/blob/main/docs/README.md).


## Supported Operations
`+` `-` `*` `/` `//` `/` `%` `++` `--` `neg` `bin` `oct` `dec` `hex` `band` `bor` `bxor` `~` `>>` `<<` `==` `!=` `<=` `<` `>=` `>` `eq` `noq` `le` `lt` `ge` `gt` `echo` `print` `and` `or` `not` `&&` `||` `^` `log` `log2` `log10` `exp` `sin` `cos` `tan` `asin` `acos` `atan` `sinh` `cosh` `tanh` `asinh` `acosh` `atanh` `sqrt` `gcd` `lcm` `radians` `!` `ceil` `floor` `comb` `perm` `abs` `cbrt` `ncr` `npr` `roundn` `round` `rand` `randint` `uniform` `dice` `int` `float` `str` `bool` `seq` `range` `min` `sum` `max` `len` `drop` `dup` `swap` `pick` `rot` `rotl` `insert` `rev` `clear` `disp` `eval` `asc` `chr` `concat` `time` `if` `ifelse` `times` `do` `set` `defun` `alias` `include`



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/remokasu/stacker",
    "name": "pystacker",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "reverse-polish-calculator rpn terminal-app",
    "author": "remokasu",
    "author_email": "",
    "download_url": "",
    "platform": null,
    "description": "[**\u65e5\u672c\u8a9e  (Japanese)**](https://github.com/remokasu/stacker/blob/main/README_JP.md)\n\n\n# Stacker: An RPN Calculator and Extensible Programming Language\n\n[![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)\n[![PyPI version](https://badge.fury.io/py/pystacker.svg)](https://badge.fury.io/py/pystacker)\n![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)\n\nStacker is a powerful Reverse Polish Notation (RPN) calculator built with Python, featuring basic mathematical operations and extensibility through plugins.\n\n## Installation\n\n### Prerequisites:\nEnsure Python 3 is installed.\n\n### Installation Options:\n\n- Via pip:\n    ```bash\n    pip install pystacker\n    ```\n\n- From source:\n    ```bash\n    git clone git@github.com:remokasu/stacker.git\n    cd stacker\n    python setup.py install\n    ```\n\n## Feedback and Contributions\n\nFeedback and contributions are welcome. Please submit issues or suggestions on the [Issues page](https://github.com/remokasu/stacker/issues).\n\n## Dependencies\n\nStacker uses external libraries like NumPy and Python Prompt Toolkit. Ensure these are installed:\n```bash\npip install numpy prompt_toolkit\n```\n\n## Usage\n\nRun Stacker:\n```bash\nstacker\n```\nOr:\n```bash\npython -m stacker\n```\n\nStacker supports standard arithmetic operations (+, -, *, /) and advanced functions (sin, cos, tan, etc.). Users can input commands in RPN format and extend functionality using custom plugins.\n\n### Input Examples\n\nStacker allows for straightforward RPN input. For example:\n\n- Single-line input:\n  ```bash\n  stacker:0> 3 4 +\n  [7]\n  ```\n\n- Multi-line input:\n  ```bash\n  stacker:0> 3\n  [3]\n  stacker:1> 4\n  [3, 4]\n  stacker:2> +\n  [7]\n  ```\n\n- #### Variables:\n  - syntax: \n    ``` bash\n    value $name set\n    ```\n  - example:\n    ```bash\n    stacker:0> 3 $x set\n    ```\n    In this example, we assign `3` to `x`.\n    If you input an undefined symbol, you need to prefix the symbol name with a dollar sign ($). <br>\n    From now on, when using `x`, the character 'x' will be pushed onto the stack and evaluated to return `3` when popped. <br>\n    You can push the value of a symbol by prefixing it with @. <br>\n    For example, `@x` will push `3`.\n    ``` bash\n    stacker:0> 3 $x set\n    stacker:1> x\n    [x]\n    stacker:2> @x\n    [x, 3]\n    stacker:1> +\n    [6]\n    ```\n\n- #### Conditionals:\n  - if\n    - syntax:\n      ```bash\n      {true_block} {condition} if\n      ```\n    - example:\n      ``` bash\n      stacker:0> 0 $x set\n      stacker:1> {3 4 +} {x 0 ==} if\n      [7]\n      ```\n      This example pushes `7` onto the stack because `x` is equal to `0`.\n  - ifelse\n    - syntax:\n      ```bash\n      {true_block} {false_block} {condition} ifelse\n      ```\n    - example:\n      ``` bash\n      stacker:0> 0 $x set\n      stacker:1> {3 4 +} {3 4 -} {x 0 ==} ifelse\n      [7]\n      ```\n      This example pushes `7` onto the stack because `x` is equal to `0`.\n\n- #### Loops:\n  - do\n    - syntax:\n      ```bash\n      start_value end_value $symbol {body} do\n      ```\n    - example:\n      ```bash\n      stacker:0> 0 10 $i {i echo} do\n      0\n      1\n      2\n      3\n      4\n      5\n      6\n      7\n      8\n      9\n      10\n      ```\n      This example prints the numbers from 0 to 10.\n  - times\n    - syntax:\n      ```bash\n      {body} n times\n      ```\n    - example:\n      ```bash\n      stacker:0> 1 {dup ++} 10 times\n      [1 2 3 4 5 6 7 8 9 10 11]\n      ```\n      In this example, we push 1 onto the stack and then repeat {dup (duplicate the top element) and ++ (add 1 to the top element)} 10 times.\n\n- #### Define a function:\n  - syntax:\n    ```bash\n    (arg1 arg2 ... argN) {body} $name defun\n    ```\n  - example:\n    ```bash\n    stacker:0> (x y) {x y *} $multiply defun\n    stacker:1> 10 20 multiply\n    [200]\n    ```\n    This defines a function named `multiply` that takes two arguments `x` and `y` and multiplies them together.\n\n- #### Define a macro:\n  - syntax:\n    ```bash\n    {body} $name alias\n    ```\n  - example:\n    ```bash\n    stacker:0> {2 ^ 3 * 5 +} $calculatePowerAndAdd alias\n    stacker:1> 5 calculatePowerAndAdd\n    [80]\n    ```\n    This defines a macro with the body `{2 ^ 3 * 5 +}` and assigns it the name `calculatePowerAndAdd`. This macro squares the number on the stack, multiplies it by 3, and then adds 5.\n\n- #### Include Scripts\n  Stacker scripts can be included in other scripts using the `include` command. For example:\n\n  ``` bash\n  stacker:0>  \"my_script.stk\" include\n  ```\n  All functions, macros and variables defined in \"my_script.stk\" are added to the current stack.\n\n\n### Running Scripts\nStacker scripts can be created in *stk files. To run a script, simply execute it with Stacker. For example:\n\n- my_script.stk:\n  ```bash\n  0 $p set\n  0 100000 $k {\n      -1 k ^ 2 k * 1 + / p + p set\n  } do\n  4 p * p set\n  p echo\n  ```\n\n  Running the script:  \n  ```bash\n  stacker my_script.stk\n  ```\n\n\n### Command Line Execution\nYou can directly execute a specified RPN expression from the command line.\n\n```bash\nstacker -e \"3 4 + echo\"\n```\n\n\n## Settings\n- disable_plugin\n  Disable a specified plugin:\n  ```bash\n  stacker:0> \"hoge\" disable_plugin\n  ```\n  This command deactivates the `hoge` operator added as a plugin.\n  Note that it cannot be used on non-plugin oeratirs.\n\n- disable_all_plugins\n  Disable all plugins at once.\n  ```bash\n  stacker:0> disable_all_plugins\n  ```\n\n- enable_disp_stack\n  Enables the setting to display the stack contents each time. By default, this setting is already active.\n  ```bash\n  stacker:0> enable_disp_stack\n  ```\n\n- disable_disp_stack\n  Sets the display of stack contents to be disabled. When this setting is enabled, only the latest element of the stack is displayed.\n  ```bash\n  stacker:0> disable_disp_stack\n  ```\n\n- disable_disp_logo\n  Disables the display of the logo at startup.\n  ```bash\n  stacker:0> disable_disp_logo\n  ```\n\n## Configuration File\nYou can automatically load settings at startup. The configuration file should be placed in ~/.stackerrc. For example, if you write the following contents in ~/.stackerrc, the disable_disp_logo and disable_disp_stack will be automatically activated at startup.\n```bash\ndisable_disp_logo\ndisable_disp_stack\n```\n\n## Creating Plugins\n\nCreate custom plugins for Stacker using Python:\n\n1. In the `plugins` directory, create a new Python file for your plugin (e.g., `my_plugin.py`). \n    ``` \n    stacker/\n    \u2502\n    \u251c\u2500\u2500 stacker/\n    \u2502   \u251c\u2500\u2500 plugins/\n    \u2502   \u2502   \u251c\u2500\u2500 my_plugin.py\n    \u2502   \u2502   \u2514\u2500\u2500 ...\n    \u2502   \u2502\n    \u2502   \u251c\u2500\u2500 data/\n    \u2502   \u251c\u2500\u2500 stacker.py\n    \u2502   \u251c\u2500\u2500 test.py\n    \u2502   \u2514\u2500\u2500 ...\n    \u2502\n    \u2514\u2500\u2500 ...\n    ```\n\n    Adding your plugin here and reinstalling Stacker will apply the plugin permanently.\n\n2. Alternatively, create a `plugins` directory in the directory where Stacker is executed. This allows you to use plugins without reinstalling Stacker.\n3. Define required functions or classes in your plugin file.\n4. Add a `setup` function to register these with Stacker.\n\n\nExample:\n```python\nfrom stacker.stacker import Stacker\n\ndef function(a, b):\n    # Do something\n\ndef setup(stacker: Stacker):\n    stacker.register_plugin(\"command\", function)\n```\n\n## Disabling Plugins\nUse operatorName disable_plugin to disable a specific plugin.<br>\nUse disable_all_plugins to disable all plugins.<br>\n\n\n## Documentation\nFor more detailed documentation, please refer to [`stacker/docs`](https://github.com/remokasu/stacker/blob/main/docs/README.md).\n\n\n## Supported Operations\n`+` `-` `*` `/` `//` `/` `%` `++` `--` `neg` `bin` `oct` `dec` `hex` `band` `bor` `bxor` `~` `>>` `<<` `==` `!=` `<=` `<` `>=` `>` `eq` `noq` `le` `lt` `ge` `gt` `echo` `print` `and` `or` `not` `&&` `||` `^` `log` `log2` `log10` `exp` `sin` `cos` `tan` `asin` `acos` `atan` `sinh` `cosh` `tanh` `asinh` `acosh` `atanh` `sqrt` `gcd` `lcm` `radians` `!` `ceil` `floor` `comb` `perm` `abs` `cbrt` `ncr` `npr` `roundn` `round` `rand` `randint` `uniform` `dice` `int` `float` `str` `bool` `seq` `range` `min` `sum` `max` `len` `drop` `dup` `swap` `pick` `rot` `rotl` `insert` `rev` `clear` `disp` `eval` `asc` `chr` `concat` `time` `if` `ifelse` `times` `do` `set` `defun` `alias` `include`\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Remokasu  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Stacker: RPN Calculator in Python",
    "version": "1.5.4",
    "project_urls": {
        "Homepage": "https://github.com/remokasu/stacker"
    },
    "split_keywords": [
        "reverse-polish-calculator",
        "rpn",
        "terminal-app"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "99f498a22240f503a59fb0e83543d7c867988ec39f6f7074c8ff94aaee812e3f",
                "md5": "af606533f19ea95dd76d9044c8c38d79",
                "sha256": "5649396dd876941e64642015671a2770ebabd7d6635bd9109f5817a30b12ed67"
            },
            "downloads": -1,
            "filename": "pystacker-1.5.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "af606533f19ea95dd76d9044c8c38d79",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 50308,
            "upload_time": "2023-12-25T15:29:32",
            "upload_time_iso_8601": "2023-12-25T15:29:32.684719Z",
            "url": "https://files.pythonhosted.org/packages/99/f4/98a22240f503a59fb0e83543d7c867988ec39f6f7074c8ff94aaee812e3f/pystacker-1.5.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-25 15:29:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "remokasu",
    "github_project": "stacker",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "pystacker"
}
        
Elapsed time: 0.16463s