Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Clojure from simplifying ratios

Tags:

clojure

Is there any way to prevent clojure from making for example a 2/5 from 6/15? I need for a function to have the original denominators of ratios, hence the question.


1 Answers

There is no way to prevent clojure from making 2/5 from 6/15. This is most readily apparent from the equality of clojure.lang.Ratio defined here. Preserving the original unreduced version would break equality.

This sounds like a datatype problem. You are putting information into a type that doesn't preserve the amount of data that you need. Fundamentally you are putting two numbers into a ratio datatype which is a single scalar value. You'll (most probably) need to thread more information through or delay the conversion into a ratio.

like image 178
dpsutton Avatar answered Jun 14 '26 08:06

dpsutton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!