23 Number Snip

▼ |  | Framework: Racket GUI Application Framework

1 | Framework Libraries Overview
2 | Application
3 | Autosave
4 | Canvas
5 | Color Model
6 | Color Prefs
7 | Color
8 | Comment Box
9 | Decorated Editor Snip
10 | Editor Snip
11 | Editor
12 | Exit
13 | Finder
14 | Frame
15 | Group
16 | GUI Utilities
17 | Handler
18 | Icon
19 | Keymap
20 | Menu
21 | Mode
22 | Notify-boxes
23 | Number Snip
24 | Panel
25 | Pasteboard
26 | Path Utils
27 | Preferences
28 | Preferences, Textual
29 | Racket
30 | Srcloc Snips
31 | Text
32 | Splash
33 | Test
34 | Version
35 | Backwards Compatibility
36 | Signatures
37 | Unit
| Index

On this page:

number-snip: snip-class%
read
number-snip: number->string/ snip
number-snip: make-pretty-print-size
number-snip: make-repeating-decimal-snip
number-snip: make-fraction-snip
number-snip: is-number-snip?
number-snip: get-number
number-snip: remove-decimal-looking-number-snips-on-insertion-mixin

top contents ← prev up next →

### 23`` Number Snip🔗ℹ

class number-snip:snip-class% : class?
superclass: snip-class%

> > method (send a-number-snip:snip-class read f)
> > → (or/c (is-a?/c snip%) #f)
> > f : (is-a?/c editor-stream-in%)

> Overrides read in snip-class%.
> Constructs a number snip from its input.

> > procedure
> > (number-snip:number->string/snip |
> > |  | num |
> > | [ | #:exact-prefix exact-prefix |
> > |  | #:inexact-prefix inexact-prefix |
> > |  | #:fraction-view fraction-view]) |
> → (or/c number-snip:is-number-snip? string?)
> num : number?
> exact-prefix : (or/c 'always 'never 'when-necessary) = 'never
> | inexact-prefix |  | : |  | (or/c 'always 'never 'when-necessary)
> |  |  | = |  | 'never
> fraction-view : (or/c #f 'mixed 'improper 'decimal) = #f

For a number num, returns a number snip or a string according to the specified format arguments.

The exact-prefix argument specifies whether the representation should carry a #e prefix: Always, never, or when necessary to identify a representation that would otherwise be considered inexact.

Similarly for inexact-prefix. Note however that 'when-necessary is usually equivalent to 'never, as inexact numbers are always printed with a decimal dot, which is sufficient to identify a number representation as inexact.

The fraction-view field specifies how exact non-integer reals - fractions - should be rendered: As a mixed fraction, an improper fraction, or a decimal, possibly identifying periodic digits. For 'decimal, if it’s not possible to render the number as a decimal exactly, a fraction representation might be generated. This is currently the case for complex numbers.

If fraction-view is #f, this option comes from the 'framework:fraction-snip-style preference.

> > procedure
> > (number-snip:make-pretty-print-size |
> > | [ | #:exact-prefix exact-prefix |
> > |  | #:inexact-prefix inexact-prefix |
> > |  | #:fraction-view fraction-view]) |
> → (number? boolean? output-port? . -> . exact-nonnegative-integer?)
> exact-prefix : (or/c 'always 'never 'when-necessary) = 'never
> | inexact-prefix |  | : |  | (or/c 'always 'never 'when-necessary)
> |  |  | = |  | 'never
> fraction-view : (or/c #f 'mixed 'improper 'decimal) = #f

This returns a procedure usable in a pretty-print-size-hook implementation, to go with number-snip:number->string/snip. The arguments are as with number-snip:number->string/snip.

> > procedure
> > (number-snip:make-repeating-decimal-snip |  | num |
> > |  | show-prefix?) |
> → number-snip:is-number-snip?
> num : real?
> show-prefix? : boolean?

Makes a number snip that shows the decimal expansion for number. The boolean indicates if a #e prefix appears on the number.

See also number-snip:make-fraction-snip.

> > procedure
> > (number-snip:make-fraction-snip |  | num |
> > |  | show-prefix-in-decimal-view?) |
> → number-snip:is-number-snip?
> num : real?
> show-prefix-in-decimal-view? : boolean?

Makes a number snip that shows a fractional view of number. The boolean indicates if a #e prefix appears on the number, when shown in the decimal state.

See also number-snip:make-repeating-decimal-snip.

> procedure (number-snip:is-number-snip? v) → boolean?
> v : any/c

Determines if v is a number snip, i.e., created by number-snip:make-fraction-snip or number-snip:make-repeating-decimal-snip.

All values that answer #t to this predicate are also snip%s.

> procedure (number-snip:get-number ns) → real?
> ns : number-snip:is-number-snip?

Returns the number that this number snip displays.

> procedure (number-snip:remove-decimal-looking-number-snips-on-insertion-mixin text%)
> → (subclass?/c text%)
> text% : (subclass?/c text%)

Overrides the on-insert and after-insert to replace number-snip% objects that look like ASCII with their corresponding ASCII text.
top contents ← prev up next →