RSS Feed

Lisp Project of the Day

cl-stream

You can support this project by donating at:

Donate using PatreonDonate using Liberapay

Or see the list of project sponsors.

cl-streamio

Documentation🥺
Docstrings😀
Tests 🥺
Examples🥺
RepositoryActivity🤨
CI 🥺

This system defines a new streams API for CL. It is still WIP, but something already works. For example, there is how we can make a stream to read numbers from a vector:

POFTHEDAY> (defparameter *s*
             (cl-stream:sequence-input-stream #(1 2 3)))

;; Standard read function does not work:
POFTHEDAY> (read *s*)
; Debugger entered on #<SB-PCL::NO-APPLICABLE-METHOD-ERROR {1002EAA433}>

;; But cl-stream provides it's own methods:
POFTHEDAY> (cl-stream:read *s*)
1
NIL

POFTHEDAY> (cl-stream:read *s*)
2
NIL

POFTHEDAY> (cl-stream:read *s*)
3
NIL

POFTHEDAY> (cl-stream:read *s*)
NIL
:EOF

The same calls work for strings:

POFTHEDAY> (defparameter *s*
             (cl-stream:sequence-input-stream "Lisp"))

POFTHEDAY> (cl-stream:read *s*)
#\L
NIL

POFTHEDAY> (cl-stream:read *s*)
#\i
NIL

POFTHEDAY> (cl-stream:read *s*)
#\s
NIL

POFTHEDAY> (cl-stream:read *s*)
#\p
NIL

POFTHEDAY> (cl-stream:read *s*)
NIL
:EOF

I also tried to use class for output to the sequence but seems it is incomplete. Some methods are missing:

POFTHEDAY> (defparameter *s*
             (make-instance 'cl-stream:sequence-output-stream
                            :element-type 'integer))
*S*

POFTHEDAY> (cl-stream:sequence-output-stream-sequence *s*)
; Debugger entered on #<SB-PCL::NO-APPLICABLE-METHOD-ERROR {100802EEC3}>
[1] POFTHEDAY> 
; Evaluation aborted on #<SB-PCL::NO-APPLICABLE-METHOD-ERROR {100802EEC3}>

There is also an interesting but not implemented idea to support blocking/non-blocking stream API calls.

This library was changed a year ago, and probably the author lost interest in improving it. What do you think, does Common Lisp needs an alternative streams API?


Brought to you by 40Ants under Creative Commons License