RAA - tcalc/0.11

tcalc / 0.11

Short description: calculator RPN another yet
Category: Application/Calculator
Status: alpha
Created: 2007-11-27 19:33:37 GMT
Last update: 2007-12-05 19:28:54 GMT
Owner: tlink (Projects of this owner)
Homepage: http://www.vim.org/scripts/script.php?script_id=2040
Download: not available
License: GPL
Dependency:
None
Description:

It turns out that ruby is pretty good at maths and deals well with complex or rational numbers etc. Anyway, in certain occasions a postfix syntax and a stack are better suited for calculations than ruby’s infix syntax. So, here comes …

tcalc:A small ruby-based[*] RPN-calculator, a simple ASCII function plotter, and stack-based playground :-).

Several "frontends" are supported:

  • VIM
  • Curses
  • Dumb command-line (with optional readline support)

The tcalc.rb script can also be used as a stand-alone calculator (with optional support for curses and readline). Run "tcalc —help" for information on the command-line options.

The script implements a small stack-based language. A simple-minded primes filter could look like:

    :primes ( top:Numeric ) args
        (( known_primes:Array current:Numeric top:Numeric )
            current top <=
                (
                    [ known_primes ] (( prime:Numeric ) current prime % 0 != ) all?
                        ( [ known_primes current ] )
                        ( [ known_primes ] )
                        ifelse
                    current 2 +
                    top
                    primes_helper
                )
                (
                    [ known_primes ]
                )
                ifelse
        ) -> primes_helper
        [ 2 ] 3 top primes_helper
    ;

The statically typed arguments are optional. If you have a forthy mind, you don’t need named arguments.

Within some limits it can also be used as some sort of function plotter:

    0 2 PI * 0.1 seq (( a: ) a sin a cos 0 ) mmap 10 10 plot
    =>
          1.00: ****   1356890                       ***
          0.78:    **80      134                   **
          0.56:    57 **        6                **
          0.33:   34    *        79            **
          0.11: 02+++++++*+++++++++0++++++++++*+++++++++
         -0.11:           **        23      ***       01
         -0.33:            ***       456   **        99
         -0.56:              **        78**        68
         -0.78:                **      **02      345
         -1.00:                  *******   356801
           .    +      +     +     +     +      +     ++
           .    0      1     2     3     4      5     66
Versions: [0.11 (2007-12-05)] [0.8 (2007-11-27)]

Edit this project (for project owner)

back to RAA top