From 5b0a9e5fe1032653c745e56a2f39561a1d7b7661 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 19 Jul 2014 10:06:37 -0700 Subject: * 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. --- ChangeLog | 9 +++++++++ stream.c | 20 ++++++++++++++++++++ stream.h | 2 ++ txr.1 | 39 ++++++++++++++++++++++++++++++++++----- 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index df64d668..006d02d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2014-07-19 Kaz Kylheku + + * 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 * eval.c (eval_init): Register get-lines as a synonym for lazy-stream-cons. 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 [ []]) (put-string []) + (put-line [ []]) (put-char []) (put-byte []) @@ -13042,15 +13042,44 @@ then *stdout* is used. The put-char function writes a character given by 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 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 argument to , if 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 []]) + (put-lines []]) + +.TP +Description: + +These functions assume to be a sequence of strings, or of +symbols, or a mixture thereof. These strings are sent to the stream. The + argument must be an output stream. If it is omitted, then *stdout* is +used. + +The put-strings function iterates over and writes each element +to the stream as if using the put-string function. + +The put-lines function iterates over and writes each element +to the stream as if using the put-line function. + +Both functions return t. + .SS Function flush-stream .TP -- cgit v1.2.3