It is an error to invoke unread-char twice consecutively on the same stream without an intervening call to read-char (or some other input operation which implicitly reads characters) on that stream.
I used it to basically peek multiple characters ahead, like peek-char, but for multiple characters. This may be why MathP doesn't work in CLISP. That allows me to have arbitrary operators. For example, I could have the following as distinct operators:
- * for multiplication
- ** (perhaps for exponentiation)
- .* (perhaps for element-wise multiplication, like in MATLAB)
- *. (dot product?)
- *.* (perhaps for element-wise exponentiation)
I thought I was being clever, but such a use contravenes the standard pretty clearly. So I'm interested in alternatives. Does anyone know if it's possible to do multiple unread-chars with other stream implementations? Also, can you read lisp from them with standard reading functions?
You can unread-string in this way:ReplyDelete
Make a concatenated stream from a string stream and *standard-input* and set the *standard-input* to it.
Then in a pertinent moment check by CONCATENATED-STREAM-STREAMS if your string stream has been depleted and reset *standard-input* not to have a concatenated stream of concatenated stream of ... in the *standard-input* variable with time.
Thanks Goheeca, I'd overlooked concatenated streams. That's a little corner of the CLHS I hadn't absorbed... It looks perfect for this type of problem.ReplyDelete