Skip to content

Port arithmetic operators for jank#828

Open
shantanu-sardesai wants to merge 5 commits intojank-lang:mainfrom
shantanu-sardesai:issues/359-auto-promotion
Open

Port arithmetic operators for jank#828
shantanu-sardesai wants to merge 5 commits intojank-lang:mainfrom
shantanu-sardesai:issues/359-auto-promotion

Conversation

@shantanu-sardesai
Copy link
Copy Markdown
Contributor

Adding support for jank's arithmetic promotion operators.

Comment thread test/clojure/core_test/plus_squote.cljc Outdated

(is (thrown? #?(:cljs :default :clj Exception :cljr Exception) (+' 1 nil)))
(is (thrown? #?(:cljs :default :clj Exception :cljr Exception) (+' nil 1)))
#?(:jank []
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocked by the jank-lang/jank#558.

@jeaye

I was thinking, maybe it would be better to have a specific issue ticket in jank (Maybe a child of this ticket) dedicated to updating all the Clojure test suite test cases for jank with support for catching specific exception types once the blocking feature is merged and in the meanwhile we merge these blocked PRs (this one, #790, and more incomming). That way we have a reminder to update these test cases and benefit from the plethora of other test cases.

What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just see that as part of jank-lang/jank#415. It's not done until jank is running all of the tests we have in this repo.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fine, so we can merge these PRs and just revisit these tests once jank can catch exceptions by type. Till then I can just keep a list of tests (in the comments of the ticket) that need to be updated.

@shantanu-sardesai shantanu-sardesai changed the title Port +' Port arithmetic operators for jank Nov 25, 2025
@shantanu-sardesai shantanu-sardesai changed the title Port arithmetic operators for jank Port arithmetic operators for jank Nov 25, 2025
@shantanu-sardesai shantanu-sardesai force-pushed the issues/359-auto-promotion branch 2 times, most recently from 8c13328 to 3a6d889 Compare November 25, 2025 14:29
@shantanu-sardesai shantanu-sardesai force-pushed the issues/359-auto-promotion branch from e40cecc to 47d24c5 Compare November 25, 2025 14:47
Comment thread test/clojure/core_test/star_squote.cljc
Comment thread test/clojure/core_test/number_range.cljc Outdated
@shantanu-sardesai shantanu-sardesai force-pushed the issues/359-auto-promotion branch from 4477c90 to f7c8103 Compare November 26, 2025 15:21
:jank (cpp/jank.runtime.is_big_integer n)
:default
(and (integer? n)
(not (int? n)))))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to switch to this predicate, I think we could do a better job than this. Personally I think the default should be something like

(= (type 0N) (type n))

Copy link
Copy Markdown
Contributor Author

@shantanu-sardesai shantanu-sardesai Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure why this is better? As long as we make sure the check in the compiler for jank.runtime.is_big_integer doesn't have a bug.

Copy link
Copy Markdown
Contributor Author

@shantanu-sardesai shantanu-sardesai Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Are you referring to the :default case? On my mobile it looked like you were talking about the :jank case. I agree that the check for the default case is... a bit convoluted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, sounds good.

Copy link
Copy Markdown
Collaborator

@dgr dgr Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote the original default case for big-int?. I'm looking through the current version of it now and it seems like in some dialects it's becoming a synonym for integer?. I'm not sure that's what we want as it changes the semantics of it. IMO, there are a couple different cases that we need to think through. If a dialect doesn't act like Clojure JVM, there are a couple of choices. The dialect could hard fail on big integers, similar to what ClojureScript does on rationals. This would imply throwing an exception when reading a big integer (e.g., fail on "0N"). Or it could silently incorporate them for those in a given range. Thus, reading "0N" would succeed, but you'd have another kind of number, not a true big integer (again, similar to what JavaScript does). The question is what are the semantics of big-int? in the case of an implementation that just silently converts big integers to another type? In other words, is big-int? semantically equivalent to "Is this a big integer distinct from fixed-precision integers where int? returns true?" or is it semantically equivalent to "Is the type of this object the same type that is the result of (read-string "0N")?" Those are not quite the same thing. It feels like the bit-int? predicate semantics have gotten a little mushy. Specifically, the current code just accepts anything "big integerish" (and even "integerish") in a dialect that doesn't have big integers, and I'm not sure that's what we want. I'd have to go look at all the tests that use the bit-int? predicated to think this through more carefully, but just wanted to highlight the issue.

Copy link
Copy Markdown
Collaborator

@E-A-Griffin E-A-Griffin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the :default cases here to Exception since most platforms are going to throw an Exception? If you need to add an empty :jank case in the meantime we can always come back to it

@jeaye
Copy link
Copy Markdown
Member

jeaye commented Dec 18, 2025

Can we change the :default cases here to Exception since most platforms are going to throw an Exception? If you need to add an empty :jank case in the meantime we can always come back to it

Agreed, this makes sense.

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.

4 participants