Octal literals?

Is there a gentle way to make octal literals in Scala? Does it carry over into Scala 3.

The last .java source file to convert for the project is very simple, but is full of them. (It’s JNA calls to some standard unix libraries - lots of octal constants.)

Thanks,

David

Hmm. I’m not aware of anything built-in; in Scala 3, it seems like it could be handled with the experimental new generic number literals feature, although it might require too much boilerplate to be worth it. Don’t see a straightforward way for Scala 2, offhand.

Thanks! That’s another thing to look forward to in scala 3.

A string interpolator can do this. Spire has a number of such interpolators: GitHub - typelevel/spire: Powerful new number types and numeric abstractions for Scala. I don’t know offhand if octal is one of them, but if not, you might be able to look and see how they did it.

A plain string interpolator would be easy to write, but then the conversion would happen at runtime. A macro-based interpolator could do the conversion at compile-time; that’s how Spire does it.

Spire has not been ported to Scala 3, sadly.

4 Likes

An effort to port Spire to Scala 3 is underway here: https://github.com/typelevel/spire/issues/936

I imagine volunteer participation/assistance would be appreciated.

1 Like