Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you're taking suggestions, I have a frequent need to do basic arithmetic on fractions and not many "app" calculators do that well or at all.


On the desktop, if you keep a Scheme interpreter installed, you can use it as a quick arbitrary-precision calculator, including support for fractions.

Guile is the most easily available one on a Linux system, though some others will give better REPL out of the box.

    $ guile
    GNU Guile 3.0.8
    Copyright (C) 1995-2021 Free Software Foundation, Inc.

    Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
    This program is free software, and you are welcome to redistribute it
    under certain conditions; type `,show c' for details.

    Enter `,help' for help.
    scheme@(guile-user)> (+ 1/2 1/8 1/8)     
    $1 = 3/4
    scheme@(guile-user)> (* $1 1/2)
    $2 = 3/8
    scheme@(guile-user)> (define rate 42)
    scheme@(guile-user)> (* rate $2)
    $3 = 63/4
    scheme@(guile-user)> (define (foo x) (- x 1/32))              
    scheme@(guile-user)> (foo $3)
    $4 = 503/32
    scheme@(guile-user)> (exact->inexact $4)
    $5 = 15.71875
    scheme@(guile-user)> 
You can also run a Scheme REPL within Emacs, with `M-x run-scheme RET`. Optionally with Quack. https://www.neilvandyke.org/quack/


Heh, I hated writing arithmetic in lisp even when I used it fulltime with paredit.

Fortunately, many languages have a rational type, even Python, which might be more ergonomic even if ratio literals aren't supported:

    $ python
    from fractions import Fraction as f
    f(1, 2) + f(1, 8) + f(1, 8) 
    # 3/4


You didn't like the parentheses and prefix operator syntax?

Syntax-wise, you could use Racket (or another Scheme, with a little more difficulty) to make a very thin layer over normal Scheme, and package it into a program called `calc`, like this:

    user@computer:~$ calc

    > 1/2 + 1/8 + 1/8
    $1 = 3/4
    >
Or do you want a bigger library of off-the-shelf numeric tools, like Python, Julia, or R?


I'm just showing that a more accessible language like Python has a repl with a ratio type.


This is very different, but check out my https://git.sr.ht/~akkartik/notebook.love


I don't have an immediate use for it, but I quite like it!


Me neither and me too! Thanks :)


Buy a handheld calculator. Many scientifics since the mid 80s handle compound fractions via the "a b/c" key.


I have a couple, they work fine, but there don't seem to be that many options for apps/web.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: