Advertisement
Guest User

Untitled

a guest
May 3rd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. (defun reader (stream)
  2. (let ((result (make-string 10)))
  3. (file-position stream 1024)
  4. (read-sequence result stream)
  5. result))
  6.  
  7. (defun writer (stream)
  8. (let ((output "abcde12345"))
  9. (file-position stream 0)
  10. (write-sequence output stream)
  11. (values)))
  12.  
  13. (defun init-file (stream)
  14. (file-position stream 0)
  15. (let ((buffer (make-string 80 :initial-element #\space)))
  16. (write-sequence buffer stream)
  17. (write-sequence buffer stream)))
  18.  
  19. (defmacro with-my-file ((stream path) &body body)
  20. `(with-open-file (,stream ,path
  21. :element-type 'character
  22. :direction :io
  23. :if-does-not-exist :create
  24. :if-exists :append
  25. #+ccl :sharing #+ccl :external)
  26. (init-file stream)
  27. ,@body))
  28.  
  29.  
  30. (with-my-file (stream "/tmp/temp.data")
  31. (reader stream)
  32. (writer stream))
  33.  
  34. (com.informatimago.common-lisp.interactive.browser:cat "/tmp/temp.data")
  35.  
  36. (with-my-file (stream "/tmp/temp.data")
  37. (writer stream)
  38. (reader stream))
  39.  
  40. (com.informatimago.common-lisp.interactive.browser:cat "/tmp/temp.data")
  41.  
  42. (with-my-file (stream "/tmp/temp.data")
  43. (dolist (thread (list (bt:make-thread (lambda () (writer stream)) :name "writer")
  44. (bt:make-thread (lambda () (reader stream)) :name "reader")))
  45. (bt:join-thread thread)))
  46.  
  47. (com.informatimago.common-lisp.interactive.browser:cat "/tmp/temp.data")
  48.  
  49. #|
  50. > (load "~/f.lisp")
  51. abcde12345
  52. abcde12345
  53. abcde12345
  54. #P"/Users/pjb/f.lisp"
  55. >
  56. |#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement