0

Is there any way to control the naming convention Dafny uses for the target code?

Is it possible to use a symbolic constant globally? Something like this:

? global const MaxValue = 10000; ?

method Method1 (a : int) returns (b : int)
  requires a < MaxValue

Is there any way to convert a numeric expression to string?

Attila Karoly
  • 951
  • 5
  • 13

1 Answers1

2

Yes and yes.

To control the names of various entities that Dafny uses in the target code, use the {:extern "ThisIsTheNameIWant"} attribute. This attribute is supported on most declarations. For example, you can put one on a class and another on a method inside the class. For more examples, see the Test/dafny0/Extern.dfy file in the Dafny test suite. If you want to look at what is generated, use the /spillTargetCode:1 flag from the command line.

For constants, use:

const MaxValue := 10000

(Note, until recently, you had to supply the type of constants explicitly, so you had to write

const MaxValue: int := 10000

If you're building the latest version of Dafny from sources, the type is inferred from the right-hand side expression.)

A nifty feature, borrowed from Ada language, is that you can insert an underscore between any two digits in numeric literals. If you work with large literals with a bunch a zeros in them, then this makes it easier for your eyes to see that you have written the correct number. For example:

const MaxValue := 10_000
const PhoneNumber := 512_555_1212
const SignedInt32Limit := 0x8000_0000

Rustan

Rustan Leino
  • 1,954
  • 11
  • 8
  • Rustan, thank you for your most helpful answer. I'd be very grateful if you could look into my recent post 'Dafny rejects a simple postcondition', too. – Attila Karoly Jul 26 '17 at 07:52