Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.42 KB | None | 0 0
  1. ;; This buffer is for text that is not saved, and for Lisp evaluation.
  2. ;; To create a file, visit it with C-x C-f and enter text in its buffer.
  3.  
  4. (defun tokenise (string)
  5.   (loop
  6.    for start = 0 then (1+ space)
  7.    for space = (position #\Space string :start start)
  8.    for token = (subseq string start space)
  9.    unless (equal token "") ; upewnij się że nie jest pusty
  10.    collect  (clean token)
  11.    until (not space)))
  12.  
  13. (defun clean (string)
  14.   (let ((result ""))
  15.      (loop
  16.       for character across string
  17.       do
  18.       (if
  19.       ;(alpha-char-p character)    ; works only for simple letters & ASCII mode, to define form scratch:
  20.       (not (member character '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\, #\. #\? #\; #\: #\" #\! #\- #\Return)))
  21.       (setf result (concatenate 'string
  22.                     result (string character)))))
  23.      result))
  24.  
  25. (defun file-to-tokens (file)
  26.   (with-open-file (stream file)
  27.           (loop
  28.            for line = (read-line stream nil)
  29.            while line
  30.            append (tokenise line))))
  31.  
  32. ;>(char "ściemniać" 0)
  33.  
  34. ;>(char "ściemniać" 1)
  35.  
  36. ;>(char "ściemniać" 2)
  37.  
  38. ;>(concatenate 'string (string (char "ściemniać" 0)) (string (char "ściemniać" 1)))
  39.  
  40. ;>(loop for x across "ściemniać" collect x)
  41.                     ;>(subseq "ściemniać" 0 2)
  42.  
  43. (defun string-to-tokens (string)
  44.   (loop
  45.    for start = 0 then (1+ space)
  46.    for space = (position #\Space string start start)
  47.    for token = (subseq string start space)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement