The bindings in this section are not imported with continued-fractions.
This parameter controls the way string conversions happen in either direction. It contains information about which symbols to use for which numbers, what symbol to use as a radix point, and which symbol to use as a negative sign. The magnitude of the base is determined from the number of characters in the string specified by #:term. The first character of the terms is considered to be zero, the second character is considered to be one, and so on. The parameter is intended to be constructed through make-representation. make-representation checks that every part of the string is unique and checks that the radix and negate characters differ from each other and the string. The radix can be #f, in which case it is never displayed.
Controls the number of fractional digits produced.
Emits terms based on the representation argument. Because the integer part of a continued fraction doesn’t respect the base in base-emit, the integer part is emitted as a base-converted list.
cf : (or/c continued-fraction? (listof exact-integer?))
Converts a continued fraction, or a representation of one as a list of exact integers, into a string based on the parameter representation.
> (define p (make-representation #:radix #\_ #:negate #\$ #:terms "abcdefghij"))
> (parameterize ((representation p)) (continued-fraction->string (rational->cf 11/3)))
> (parameterize ((representation (make-representation #:terms "01")) (digits 20)) (continued-fraction->string (tangent-cf 157/50)))
> (parameterize ((digits 20)) (continued-fraction->string (phi-cf)))
> (define ~phi (for/list ((t (base-emit (phi-cf) 10)) (i (in-range 40))) t)) > (continued-fraction->string ~phi)
> (parameterize ((digits 20)) ; note this won't work because it interprets ; the terms in the continued fraction as a ; simple continued fraction, but this isn't ; a simple continued fraction, it's decimal (continued-fraction->string (base-emit (phi-cf) 10)))
Converts an exact number to a string based on representation. Trailing zeroes and leading zeroes are not printed. If the argument is not an exact number, the expression evaluates to #f.
Interprets a string as a number based on representation. The parameter digits is not respected when reading strings, only when writing them. If the argument is not a string, the expression evaluates to #f.
Converts a string with the current value of representation to a number, then to a string based on the rep* argument. The interpretation of the string doesn’t respect the digits parameter, but the subsequent output of the string with the new representation does.
> (define alphabet* (make-representation #:radix #\, #:terms " abcdefghijklmnopqrstuvwxyz!")) > (->number "123.456")
> (string->string "123.456" alphabet*)
> (string->string "123.456789011121314" (representation))
> (parameterize ((digits 15)) (string->string "123.456789011121314" (representation)))
> (parameterize ((representation alphabet*) (digits 0)) (->string 9395845/17210367))
> (parameterize ((representation alphabet*) (digits 20)) (->string 263083660/481890303))
" ,oh my oh my oh my oh"
> (parameterize ((representation alphabet*) (digits 34)) (->string 1169629299742001994435343/232218265089212416))