Next: Balancing, Previous: Predicates, Up: rope API [Contents][Index]
Convert a given binary tree of strings into a rope.
(cons->rope '(("Ye" . "of") . ("little" . "faith")))
⇒ #<<rope> … >
Example 2.2: Converting a cons binary tree of strings into a rope.
The binary-tree consists of cons pairs whose cells are either strings or ropes. For example this also works:
(define r (cons->rope '(("Alan " . "Mathison ") . "Turing")))
(define r' (cons->rope (cons r (cons ", I repeat: " r))))
(rope->string r')
⇒ "Alan Mathison Turing, I repeat: Alan Mathison Turing"
Example 2.3: Converting a cons binary tree of ropes and strings into a rope.
Convert the rope to a binary tree of cons pairs and strings.
Note that this is not exactly inverse with cons->rope:
specifically if the original binary tree contained cons cells of ropes
as in Example 2.3, the fact will not survive this conversion:
(define r (cons->rope '(("1" . "2") . "3")))
(define r' (cons->rope (cons r r)))
(rope->cons r')
⇒ ((("1" . "2") . "3") ("1" . "2") . "3")
Example 2.4: Converting a rope into a cons binary tree of strings.
Return a randomly structured rope representing string. This function is useful for fuzzy testing.
(rope->cons (string->random-rope "hello"))
⇒ (("h" "e" . "l") "l" . "o")
Example 2.5: Generating a random rope from a given string.
The string represented by the rope, see Example 2.3 for an example. This function will have to allocate the entire string and as such it is mostly meant to be used for debugging purposes.
Next: Balancing, Previous: Predicates, Up: rope API [Contents][Index]