2.2 mischief/phrase: Converting Values to Readable Phrases
(require mischief/phrase) | package: mischief |
procedure
(procedure-arity->phrase proc) → string?
proc : procedure? (procedure-arity->phrase arity) → string? arity : procedure-arity?
(procedure-arity->phrase arity required optional) → string? arity : procedure-arity? required : (listof keyword?) optional : (or/c (listof keyword?) #false)
Produces a readable phrase describing the positional and keyword arity of a
procedure.
Examples:
> (procedure-arity->phrase sort) "2 arguments and optional arguments of keywords #:cache-keys? and #:key"
> (procedure-arity->phrase (list 1 2 3 5 (arity-at-least 8))) "1 argument, 2 arguments, 3 arguments, 5 arguments, or 8 or more arguments"
> (procedure-arity->phrase 0 '[] #false) "0 arguments and any keyword arguments"
> (procedure-arity->phrase 1 '[#:always] '[#:always #:sometimes]) "1 argument; an argument of keyword #:always; and an optional argument of keyword #:sometimes"
> (procedure-arity->phrase 2 '[#:always #:usually] '[#:sometimes #:occasionally]) "2 arguments; arguments of keywords #:always and #:usually; and optional arguments of keywords #:occasionally and #:sometimes"
procedure
(list->phrase strs [ #:none none #:separator sep #:final final]) → string? strs : (listof string?) none : string? = "none" sep : string? = "," final : (or/c string? #false) = "and"
Produces a readable phrase describing a list of things.
Examples:
> (list->phrase empty) "none"
> (list->phrase empty #:none "nothing at all") "nothing at all"
> (list->phrase '["apples"]) "apples"
> (list->phrase '["apples" "bananas"]) "apples and bananas"
> (list->phrase '["apples" "bananas" "oranges"]) "apples, bananas, and oranges"
> (list->phrase '["apples and bananas" "carrots and celery" "meat and potatoes"] #:separator ";" #:final "or") "apples and bananas; carrots and celery; or meat and potatoes"
procedure
(count->phrase n singular [plural]) → string?
n : exact-nonnegative-integer? singular : string? plural : (or/c string? #false) = #false
Produces a readable phrase describing the quantity of something.
Examples:
> (count->phrase 0 "elephant") "0 elephants"
> (count->phrase 1 "elephant") "1 elephant"
> (count->phrase 2 "elephant") "2 elephants"
> (count->phrase 0 "goose" "geese") "0 geese"
> (count->phrase 1 "goose" "geese") "1 goose"
> (count->phrase 2 "goose" "geese") "2 geese"