Hi,
Is there a way to make polyml display an integer in its hex format? For example,
0x12;
val it = 18 : int
I want to have 0x12 echoed back instead of 18.
Thanks. Lu
Lu Zhao wrote:
Is there a way to make polyml display an integer in its hex format? For example,
0x12;
val it = 18 : int
I want to have 0x12 echoed back instead of 18.
I do not know about echoing but you can print integers in hexadecimal format using
Int.fmt: StringCvt.radix -> int -> string
http://standardml.org/Basis/string-cvt.html#SIG:STRING_CVT.radix:TY
http://standardml.org/Basis/integer.html#SIG:INTEGER.fmt:VAL
e.g.
- Int.fmt StringCvt.HEX 18; val it = "12" : string
- Gergely
The problem is that I want to see some intermediate results that are mixed with other data types in tuples. I know I could write wrapper functions converting all intermediate integer results to string, but it's kind of tedious since I need to add that function to everywhere I want to see the hex format. A more desired solution is to turn on some flag, since I basically only need to see the hex format of integers.
Lu
Gergely Buday wrote:
Lu Zhao wrote:
Is there a way to make polyml display an integer in its hex format? For example,
0x12;
val it = 18 : int
I want to have 0x12 echoed back instead of 18.
I do not know about echoing but you can print integers in hexadecimal format using
Int.fmt: StringCvt.radix -> int -> string
http://standardml.org/Basis/string-cvt.html#SIG:STRING_CVT.radix:TY
http://standardml.org/Basis/integer.html#SIG:INTEGER.fmt:VAL
e.g.
- Int.fmt StringCvt.HEX 18;
val it = "12" : string
- Gergely
Lu, There's no switch as such that will do this but it's easy to install a pretty printer that will print ints in hex. Poly/ML 5.3 Release
local
fun prettyInt _ _ x = PolyML.PrettyString("0x" ^ Int.fmt StringCvt.HEX x) in val () = PolyML.addPrettyPrinter prettyInt end; # # # # > 18; val it = 0x12 : int
You could easily modify this to include your own ref that would allow you to switch the format as you want.
Regards, David
Lu Zhao wrote:
The problem is that I want to see some intermediate results that are mixed with other data types in tuples. I know I could write wrapper functions converting all intermediate integer results to string, but it's kind of tedious since I need to add that function to everywhere I want to see the hex format. A more desired solution is to turn on some flag, since I basically only need to see the hex format of integers.
Lu
Gergely Buday wrote:
Lu Zhao wrote:
Is there a way to make polyml display an integer in its hex format? For example,
0x12;
val it = 18 : int
I want to have 0x12 echoed back instead of 18.
I do not know about echoing but you can print integers in hexadecimal format using
Int.fmt: StringCvt.radix -> int -> string
http://standardml.org/Basis/string-cvt.html#SIG:STRING_CVT.radix:TY
http://standardml.org/Basis/integer.html#SIG:INTEGER.fmt:VAL
e.g.
- Int.fmt StringCvt.HEX 18;
val it = "12" : string
- Gergely
polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
~3;
val it = 0x~3 : int
~12;
val it = 0x~C : int
This is exactly what I expect to see for a negative numbers. Since I don't intend to make a negative number in 2's complement format.
Tjark Weber wrote:
On Tue, 2010-01-12 at 08:39 +0000, David Matthews wrote:
PolyML.PrettyString("0x" ^ Int.fmt StringCvt.HEX x)
Note that this is arguably flawed for negative x.
Regards, Tjark
polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
On Tue, 2010-01-12 at 13:32 -0700, Lu Zhao wrote:
~3;
val it = 0x~3 : int
~12;
val it = 0x~C : int
This is exactly what I expect to see for a negative numbers. Since I don't intend to make a negative number in 2's complement format.
I was merely referring to the position of "~". 0x~3 and 0x~C are rejected as malformed (when entered at the Poly/ML prompt). ~0x3 and ~0xC, on the other hand, work fine.
Apologies if this wasn't obvious.
Regards, Tjark
Tjark Weber wrote:
On Tue, 2010-01-12 at 13:32 -0700, Lu Zhao wrote:
~3;
val it = 0x~3 : int
~12;
val it = 0x~C : int
This is exactly what I expect to see for a negative numbers. Since I don't intend to make a negative number in 2's complement format.
I was merely referring to the position of "~". 0x~3 and 0x~C are rejected as malformed (when entered at the Poly/ML prompt). ~0x3 and ~0xC, on the other hand, work fine.
I see. I'm sorry that I misunderstood you. But it's easy to fix by putting an if statement in the pretty print function.
Thanks for pointing this out. Lu