Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun reader (stream)
- (let ((result (make-string 10)))
- (file-position stream 1024)
- (read-sequence result stream)
- result))
- (defun writer (stream)
- (let ((output "abcde12345"))
- (file-position stream 0)
- (write-sequence output stream)
- (values)))
- (defun init-file (stream)
- (file-position stream 0)
- (let ((buffer (make-string 80 :initial-element #\space)))
- (write-sequence buffer stream)
- (write-sequence buffer stream)))
- (defmacro with-my-file ((stream path) &body body)
- `(with-open-file (,stream ,path
- :element-type 'character
- :direction :io
- :if-does-not-exist :create
- :if-exists :append
- #+ccl :sharing #+ccl :external)
- (init-file stream)
- ,@body))
- (with-my-file (stream "/tmp/temp.data")
- (reader stream)
- (writer stream))
- (com.informatimago.common-lisp.interactive.browser:cat "/tmp/temp.data")
- (with-my-file (stream "/tmp/temp.data")
- (writer stream)
- (reader stream))
- (com.informatimago.common-lisp.interactive.browser:cat "/tmp/temp.data")
- (with-my-file (stream "/tmp/temp.data")
- (dolist (thread (list (bt:make-thread (lambda () (writer stream)) :name "writer")
- (bt:make-thread (lambda () (reader stream)) :name "reader")))
- (bt:join-thread thread)))
- (com.informatimago.common-lisp.interactive.browser:cat "/tmp/temp.data")
- #|
- > (load "~/f.lisp")
- abcde12345
- abcde12345
- abcde12345
- #P"/Users/pjb/f.lisp"
- >
- |#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement