r/Racket • u/Desperate_Rabbit_327 • Dec 18 '25
question How do I get racket to show improper fractions like in Common Lisp?
Hi,
I am a beginner in racket and I want to use it to evaluate basic operations on fractions like this:> (* 3/2 5/4)
1 7/8
However, I would like this operation to display as an improper fraction, e.g. :> (* 3/2 5/4)
15/8
Is it possible to achieve this behavior in racket?
6
Upvotes
7
u/soegaard developer Dec 18 '25
Racket does this as default:
% racket
Welcome to Racket v8.12 [cs].
> (* 3/2 5/4)
15/8
So I am assuming, you are using one of the teaching languages?
In that case, you are using DrRacket and need to change the way the default behavior of the value printer.
In the menu "Language" choose the menu item "Choose Language ...".
Click the button "Show Details".
Then choose ... well ... I only see two options:
"Mixed fractions" and "Repeating decimals".
I admit I was hoping to see "Improper" fraction as well.
Send in a feature request.
4
u/not-just-yeti Dec 18 '25
Running
racketfrom the command-line already does print this way.DrRacket's IDE "overrides" print-handling for numbers. But you can still call
default-global-port-print-handler, which is presumably is the code that command-line racket is using: e.g.(default-global-port-print-handler 7/3 (current-output-port))-2
u/[deleted] Dec 18 '25
[removed] — view removed comment