prettyprint: use radix prefixes for number-base
parent
4b6559849f
commit
6d1a28aca6
|
@ -4,8 +4,8 @@ USING: accessors arrays assocs byte-arrays byte-vectors classes
|
||||||
classes.algebra.private classes.intersection classes.maybe
|
classes.algebra.private classes.intersection classes.maybe
|
||||||
classes.tuple classes.tuple.private classes.union colors
|
classes.tuple classes.tuple.private classes.union colors
|
||||||
colors.constants combinators continuations effects generic
|
colors.constants combinators continuations effects generic
|
||||||
hash-sets hashtables io io.pathnames io.styles kernel make math
|
hash-sets hashtables io io.pathnames io.styles kernel locals
|
||||||
math.order math.parser namespaces prettyprint.config
|
make math math.order math.parser namespaces prettyprint.config
|
||||||
prettyprint.custom prettyprint.sections prettyprint.stylesheet
|
prettyprint.custom prettyprint.sections prettyprint.stylesheet
|
||||||
quotations sbufs sequences strings vectors words words.symbol ;
|
quotations sbufs sequences strings vectors words words.symbol ;
|
||||||
FROM: sets => members ;
|
FROM: sets => members ;
|
||||||
|
@ -63,11 +63,16 @@ M: method pprint*
|
||||||
[ "method-generic" word-prop pprint-word ] bi
|
[ "method-generic" word-prop pprint-word ] bi
|
||||||
block> ;
|
block> ;
|
||||||
|
|
||||||
|
:: pprint-prefixed-number ( n pre quot: ( n -- n' ) -- )
|
||||||
|
n neg?
|
||||||
|
[ n neg quot call pre prepend "-" prepend text ]
|
||||||
|
[ n quot call pre prepend text ] if ; inline
|
||||||
|
|
||||||
M: real pprint*
|
M: real pprint*
|
||||||
number-base get {
|
number-base get {
|
||||||
{ 16 [ \ HEX: [ >hex text ] pprint-prefix ] }
|
{ 16 [ "0x" [ >hex ] pprint-prefixed-number ] }
|
||||||
{ 8 [ \ OCT: [ >oct text ] pprint-prefix ] }
|
{ 8 [ "0o" [ >oct ] pprint-prefixed-number ] }
|
||||||
{ 2 [ \ BIN: [ >bin text ] pprint-prefix ] }
|
{ 2 [ "0b" [ >bin ] pprint-prefixed-number ] }
|
||||||
[ drop number>string text ]
|
[ drop number>string text ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
|
@ -76,7 +81,7 @@ M: float pprint*
|
||||||
\ NAN: [ fp-nan-payload >hex text ] pprint-prefix
|
\ NAN: [ fp-nan-payload >hex text ] pprint-prefix
|
||||||
] [
|
] [
|
||||||
number-base get {
|
number-base get {
|
||||||
{ 16 [ \ HEX: [ >hex text ] pprint-prefix ] }
|
{ 16 [ "0x" [ >hex ] pprint-prefixed-number ] }
|
||||||
[ drop number>string text ]
|
[ drop number>string text ]
|
||||||
} case
|
} case
|
||||||
] if ;
|
] if ;
|
||||||
|
|
|
@ -20,7 +20,7 @@ HELP: line-limit
|
||||||
{ $var-description "The maximum number of lines output by the prettyprinter before output is truncated with \"...\". The default is " { $link f } ", denoting unlimited line count." } ;
|
{ $var-description "The maximum number of lines output by the prettyprinter before output is truncated with \"...\". The default is " { $link f } ", denoting unlimited line count." } ;
|
||||||
|
|
||||||
HELP: number-base
|
HELP: number-base
|
||||||
{ $var-description "The number base in which the prettyprinter will output numeric literals. A value of " { $snippet "2" } " will print integers and ratios in binary with " { $link POSTPONE: BIN: } ", and " { $snippet "8" } " will print them in octal with " { $link POSTPONE: OCT: } ". A value of " { $snippet "16" } " will print all integers, ratios, and floating-point values in hexadecimal with " { $link POSTPONE: HEX: } ". Other values of " { $snippet "number-base" } " will print numbers in decimal, which is the default." } ;
|
{ $var-description "The number base in which the prettyprinter will output numeric literals. A value of " { $snippet "2" } " will print integers and ratios in binary with " { $snippet "0b" } ". A value of " { $snippet "8" } " will print them in octal with " { $snippet "0o" } ". A value of " { $snippet "16" } " will print all integers, ratios, and floating-point values in hexadecimal with " { $snippet "0x" } ". Other values of " { $snippet "number-base" } " will print numbers in decimal, which is the default." } ;
|
||||||
|
|
||||||
HELP: string-limit?
|
HELP: string-limit?
|
||||||
{ $var-description "Toggles whether printed strings are truncated to the margin." } ;
|
{ $var-description "Toggles whether printed strings are truncated to the margin." } ;
|
||||||
|
|
Loading…
Reference in New Issue