Code Monkey home page Code Monkey logo

rpn_calc's Introduction

A (very) simplistic RPN calculator

Table of contents

Introduction

A few weeks ago, I stumbled upon a web page that was called something like "RPN calc in many languages". I can't find the link right now. I decided to practice with the OCaml language.

Although OCaml has a Stack module in the standard library, I decided to implement everything by myself, using a simple List as the stack.

Available operations and commands

As shown in the source code, there are a few operations and a couple of commands:

Operator
+ add
- subtract
* multiply
/ divide
% modulo
v square root
l log
Command
p print out the stack contents (left to right = bottom to top)
q quit, when in interactive mode

Building and running

OCaml

Interpreted

$ ocaml rpn_calc.ml
1 2 3 + +
6.
q
$

or

$ echo '1 2 3 + +' | ocaml rpn_calc.ml
6.
$

Compiled

First, comment out or delete the first line in the source that reads #load str.cma. Then, using ocamlbuild :

$ cd rpn_calc
$ ocamlbuild -use-ocamlfind rpn_calc.native
$ ./rpn_calc.native
1 2 3 + +
6.
1 2 p 3 p + p + q
1. 2.
1. 2. 3.
1. 5.
6.
$

rpn_calc's People

Contributors

juan70 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.