diff --git a/basis/prettyprint/backend/backend.factor b/basis/prettyprint/backend/backend.factor index 1cf3a9eb01..7145352acd 100644 --- a/basis/prettyprint/backend/backend.factor +++ b/basis/prettyprint/backend/backend.factor @@ -4,8 +4,8 @@ USING: accessors arrays assocs byte-arrays byte-vectors classes classes.algebra.private classes.intersection classes.maybe classes.tuple classes.tuple.private classes.union colors colors.constants combinators continuations effects generic -hash-sets hashtables io io.pathnames io.styles kernel make math -math.order math.parser namespaces prettyprint.config +hash-sets hashtables io io.pathnames io.styles kernel locals +make math math.order math.parser namespaces prettyprint.config prettyprint.custom prettyprint.sections prettyprint.stylesheet quotations sbufs sequences strings vectors words words.symbol ; FROM: sets => members ; @@ -63,11 +63,16 @@ M: method pprint* [ "method-generic" word-prop pprint-word ] bi 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* number-base get { - { 16 [ \ HEX: [ >hex text ] pprint-prefix ] } - { 8 [ \ OCT: [ >oct text ] pprint-prefix ] } - { 2 [ \ BIN: [ >bin text ] pprint-prefix ] } + { 16 [ "0x" [ >hex ] pprint-prefixed-number ] } + { 8 [ "0o" [ >oct ] pprint-prefixed-number ] } + { 2 [ "0b" [ >bin ] pprint-prefixed-number ] } [ drop number>string text ] } case ; @@ -76,7 +81,7 @@ M: float pprint* \ NAN: [ fp-nan-payload >hex text ] pprint-prefix ] [ number-base get { - { 16 [ \ HEX: [ >hex text ] pprint-prefix ] } + { 16 [ "0x" [ >hex ] pprint-prefixed-number ] } [ drop number>string text ] } case ] if ; diff --git a/basis/prettyprint/config/config-docs.factor b/basis/prettyprint/config/config-docs.factor index 7cd4b31c8b..a263ef3cc3 100644 --- a/basis/prettyprint/config/config-docs.factor +++ b/basis/prettyprint/config/config-docs.factor @@ -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." } ; 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? { $var-description "Toggles whether printed strings are truncated to the margin." } ;