summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-07-19 10:06:37 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-07-19 10:06:37 -0700
commit5b0a9e5fe1032653c745e56a2f39561a1d7b7661 (patch)
treef3482e19ef5016097978388268d0f5f846dade95
parent74880de58e4f3ae6e0a84187f92e6853c37aa64e (diff)
downloadtxr-5b0a9e5fe1032653c745e56a2f39561a1d7b7661.tar.gz
txr-5b0a9e5fe1032653c745e56a2f39561a1d7b7661.tar.bz2
txr-5b0a9e5fe1032653c745e56a2f39561a1d7b7661.zip
* stream.c (put_strings, put_lines): New functions.
(stream_init): Registered new functions as intrinsics. * stream.h (put_strings, put_lines): Declared. * txr.1: Documented.
-rw-r--r--ChangeLog9
-rw-r--r--stream.c20
-rw-r--r--stream.h2
-rw-r--r--txr.139
4 files changed, 65 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index df64d668..006d02d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2014-07-19 Kaz Kylheku <kaz@kylheku.com>
+ * stream.c (put_strings, put_lines): New functions.
+ (stream_init): Registered new functions as intrinsics.
+
+ * stream.h (put_strings, put_lines): Declared.
+
+ * txr.1: Documented.
+
+2014-07-19 Kaz Kylheku <kaz@kylheku.com>
+
* eval.c (eval_init): Register get-lines as a synonym for lazy-stream-cons.
* stream.c (get_string): New function.
diff --git a/stream.c b/stream.c
index ae05ae80..cc83ea09 100644
--- a/stream.c
+++ b/stream.c
@@ -1967,6 +1967,24 @@ val put_line(val string, val stream)
return (put_string(default_arg(string, null_string), stream), put_char(chr('\n'), stream));
}
+val put_strings(val strings, val stream)
+{
+ strings = nullify(strings);
+
+ for (; strings; strings = cdr(strings))
+ put_string(car(strings), stream);
+ return t;
+}
+
+val put_lines(val lines, val stream)
+{
+ lines = nullify(lines);
+
+ for (; lines; lines = cdr(lines))
+ put_line(car(lines), stream);
+ return t;
+}
+
val flush_stream(val stream)
{
type_check (stream, COBJ);
@@ -2858,6 +2876,8 @@ void stream_init(void)
reg_fun(intern(lit("put-line"), user_package), func_n2o(put_line, 0));
reg_fun(intern(lit("put-char"), user_package), func_n2o(put_char, 1));
reg_fun(intern(lit("put-byte"), user_package), func_n2o(put_byte, 1));
+ reg_fun(intern(lit("put-lines"), user_package), func_n2o(put_lines, 1));
+ reg_fun(intern(lit("put-strings"), user_package), func_n2o(put_strings, 1));
reg_fun(intern(lit("unget-char"), user_package), func_n2o(unget_char, 1));
reg_fun(intern(lit("unget-byte"), user_package), func_n2o(unget_byte, 1));
reg_fun(intern(lit("flush-stream"), user_package), func_n1(flush_stream));
diff --git a/stream.h b/stream.h
index dee60cb8..4b7b2fe5 100644
--- a/stream.h
+++ b/stream.h
@@ -92,6 +92,8 @@ val put_string(val string, val stream);
val put_line(val string, val stream);
val put_char(val ch, val stream);
val put_byte(val byte, val stream);
+val put_strings(val strings, val stream);
+val put_lines(val lines, val stream);
val flush_stream(val stream);
val seek_stream(val stream, val offset, val whence);
val get_string(val stream, val nchars);
diff --git a/txr.1 b/txr.1
index de7fa00a..abce3d55 100644
--- a/txr.1
+++ b/txr.1
@@ -13027,8 +13027,8 @@ indeterminate.
.TP
Syntax:
- (put-line [<string> [<stream>]])
(put-string <string> [<stream>])
+ (put-line [<string> [<stream>]])
(put-char <char> [<stream>])
(put-byte <byte> [<stream>])
@@ -13042,15 +13042,44 @@ then *stdout* is used.
The put-char function writes a character given by <char> to a stream. If the
stream is based on bytes, then the character is encoded into UTF-8 and multiple
bytes are written. Streams which support put-char also support put-line, and
-put-string. The put-string function writes the characters of a string out to
-the stream as if by multiple calls to put-char. The put-line function is like
-put-string, but also writes an additional newline character. The string
-is optional in put-line, and defaults to the empty string.
+put-string.
+
+The put-string function writes the characters of a string out to
+the stream as if by multiple calls to put-char. The <string> argument
+may be a symbol, in which case its name is used as the string.
+
+The put-line function is like put-string, but also writes an additional newline
+character. The string is optional in put-line, and defaults to the empty
+string.
The put-byte function writes a raw byte given by the <byte> argument
to <stream>, if <stream> supports a byte write operation. The byte
value is specified as an integer value in the range 0 to 255.
+.SS Functions put-strings and put-lines
+
+.TP
+Syntax:
+
+ (put-strings <sequence> [<stream>]])
+ (put-lines <sequence> [<stream>]])
+
+.TP
+Description:
+
+These functions assume <sequence> to be a sequence of strings, or of
+symbols, or a mixture thereof. These strings are sent to the stream. The
+<stream> argument must be an output stream. If it is omitted, then *stdout* is
+used.
+
+The put-strings function iterates over <sequence> and writes each element
+to the stream as if using the put-string function.
+
+The put-lines function iterates over <sequence> and writes each element
+to the stream as if using the put-line function.
+
+Both functions return t.
+
.SS Function flush-stream
.TP