Created
October 23, 2017 11:29
-
-
Save aragaer/4a4854028ad12e16c3af5ed371cacc07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))) | |
(when (probe-file quicklisp-init) | |
(load quicklisp-init))) | |
(with-open-file (*standard-output* "/dev/null" :direction :output | |
:if-exists :supersede) | |
(ql:quickload :trivial-gray-streams)) | |
(defvar *heads* (list)) | |
(defvar *tails* (list)) | |
(defvar *chunk-size* (* 4096 16)) | |
(shadowing-import (list 'trivial-gray-streams:fundamental-character-output-stream | |
'trivial-gray-streams:stream-write-char)) | |
(defclass my-output-stream (fundamental-character-output-stream) | |
((count :initform 0) | |
(buffer :initform (make-string *chunk-size*)))) | |
(defmethod stream-write-char ((stream my-output-stream) character) | |
(with-slots (count buffer) stream | |
(setf (char buffer count) character) | |
(incf count) | |
(when (= count *chunk-size*) | |
(format t "~a" buffer) | |
(setf count 0)))) | |
(defvar *my-out* (make-instance 'my-output-stream)) | |
(setq *tails* (loop for line = (read-line *standard-input* nil :eof) | |
until (eq line :eof) | |
for sp = (position #\Space line) | |
for head = (subseq line 0 sp) | |
for tail = (string-trim '(#\Space #\return) (subseq line sp)) | |
do (push head *heads*) | |
collect tail)) | |
(setq *heads* (nreverse *heads*)) | |
(loop for head in *heads* | |
do (loop for tail in *tails* | |
do (format *my-out* "~a~a~%" head tail))) | |
(with-slots (count buffer) *my-out* | |
(format t "~a" (subseq buffer 0 count))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment