Plaster
New
List
Login
common-lisp
default
vms
2019.04.12 23:12:02
(defparameter input nil) (defparameter inputstring (make-array 0 :adjustable t :fill-pointer t :element-type 'character)) (defun reader () (if (char= #\Space (peek-char)) (progn (read-char) (push (intern inputstring) input) ) (format inputstring "~a" (read-char)) ) ) (loop while (not (char= #\Newline (peek-char))) do (reader))
Raw
Annotate
Repaste
Annotations
text
default
anonymous
2019.04.12 23:31:55
(loop while (not (char= #\Newline (peek-char))) do (reader)) Hell world How do you do? nil cl-user> inputstring "HellworldHowdoyoudo?" cl-user> input (|HellworldHowdoyou| |HellworldHowdo| |HellworldHow| |Hellworld| |Hell|)
Raw
Repaste
Edit
text
default
anonymous
2019.04.12 23:32:18
(loop while (not (char= #\Newline (peek-char))) do (reader)) Hell world How do you do? nil cl-user> inputstring "HellworldHowdoyoudo?" cl-user> input (|HellworldHowdoyou| |HellworldHowdo| |HellworldHow| |Hellworld| |Hell|)
Raw
Repaste
Edit
text
default
anonymous
2019.04.12 23:46:51
(defun skip-spaces (stream) (loop :while (eql #\space (peek-char t stream nil nil)) :do (read-char stream))) (defun read-token-list (stream) (let ((buffer (make-array 80 :adjustable t :fill-pointer 0 :element-type 'character))) (loop :for (word eof) := (loop :initially (setf (fill-pointer buffer) 0) (skip-spaces stream) :for ch := (read-char stream nil nil) :until (position ch #(#\space #\newline nil)) :do (vector-push-extend ch buffer (array-total-size buffer)) :finally (return (list (copy-seq buffer) (position ch #(#\newline nil))))) :when (plusp (length word)) :collect word :until eof))) (with-input-from-string (input "hello world how do you do? Fine, thanks! ") (list (read-token-list input) (read-token-list input) (read-token-list input))) --> (("hello" "world") ("how" "do" "you" "do?") ("Fine," "thanks!"))
Raw
Repaste
Edit