word_count   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/examples/contrib/word_count.xtm

Implementation

(bind-func word_count
  "turn a c string into a word count dict of <String*,i64>, splitting on split_on"
  (lambda (str split_on)
    (let ((split_on_cstr (cstring split_on))
          (tokenptr (strtok (cstring str) split_on_cstr))
          (dict (list (Pair (String "first_key") 0)))
          (cnt 0))
      (while (not (null? tokenptr))
        (if (= (% cnt 10000) 0)
            (printf "cnt: %lld tokenptr: %p\n" cnt tokenptr))
        (set! cnt (+ cnt 1))
        (dict_update dict (String tokenptr) (lambda (x) (+ x 1)))
        (set! tokenptr (strtok null split_on_cstr)))
      (println "processed" cnt "tokens")
      dict)))


Back to Index

Similar Entries

  • aiProcess_SplitByBoneCount    scheme
  • cell_count_neighbors    xtlang
  • file_word_count    xtlang
  • get_frame_count    xtlang
  • impc:ti:word-downcase    scheme
  • impc:ti:word-upcase    scheme
  • pm_count_devices    xtlang