Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ratio #37

Merged
merged 1 commit into from
Mar 13, 2022
Merged

Add support for ratio #37

merged 1 commit into from
Mar 13, 2022

Conversation

r0man
Copy link
Contributor

@r0man r0man commented Mar 13, 2022

Hi @plexus,

This PR adds support for clojure.lang.Ratio fixing issue #24.

Since Elisp does not have a ratio type, a Clojure ratio is converted
to Elisp using this expression:

(/ numerator (float denominator)).

We are calling float on the denominator to perform floating point
arithmetic, instead of the default integer arithmetic.

I was thinking about introducing a new tagged type called :ratio, but
since clojure.lang.Ratio is a sub class of Number in Java as well, I
extended the lexer and parser that handles numbers.

public class Ratio extends Number {}

WDYT?

@plexus
Copy link
Collaborator

plexus commented Mar 13, 2022

Thanks a lot for contributing this! The approach seems reasonable. It's unfortunate that it's lossy, but in most situation getting an actual number back will be what people expect. I think preserving it as a tagged type can be a future enhancement, as an option.

@plexus plexus merged commit f32c041 into clojure-emacs:main Mar 13, 2022
@r0man r0man deleted the ratio branch March 13, 2022 17:42
@r0man
Copy link
Contributor Author

r0man commented Mar 13, 2022

Perfect, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants