Next: , Previous: , Up: strings   [Index]


25.18 Miscellaneous functions

Function: %string-replace str1 start1 past1 str2 start2 past2
Macro: string-replace S1 S2

Replace the selected string in str1 with the selected string in str2. Return a newly allocated string.

Function: %string-reverse str start past
Function: %string-reverse! str start past
Macro: string-reverse S
Macro: string-reverse! S

Reverse the string. %string-reverse returns the result string and does not alter its str parameter. %string-reverse! is the in–place side–effecting variant.

Function: word-frequency getter-func

Count the number of occurrences of words in the sequence returned by successive invocations of getter-func, return a hashtable associating words to counts. getter-func must return a Scheme string at each invocation or #f when no more strings are available.

(import (vicare)
  (vicare containers strings)
  (vicare containers char-sets))

(let* ((line   "ciao ciao hello salut ciao salut")
       (words  (string-tokenize line char-set:ascii/letter))
       (getter (let ((words words))
                 (lambda ()
                   (if (null? words)
                       #f
                     (begin0
                         (car words)
                       (set! words (cdr words)))))))
       (result (word-frequency getter)))
  (hashtable-ref result "ciao"  0)      ⇒ 3
  (hashtable-ref result "hello" 0)      ⇒ 1
  (hashtable-ref result "salut" 0))     ⇒ 2