summaryrefslogtreecommitdiff
path: root/libguile/strports.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2012-03-07 13:34:06 +0100
committerAndy Wingo <wingo@pobox.com>2012-03-07 13:34:06 +0100
commita62b5c3d5431cf68d94af5397116ca38f7d15840 (patch)
tree42624e996ac2bf295d05a6636649fef518900c99 /libguile/strports.c
parent4df9e5eb0f2cbdcd36cb2a50214f79a16816accf (diff)
downloadguile-a62b5c3d5431cf68d94af5397116ca38f7d15840.tar.gz
call-with-{input,output}-string implemented in scheme
* module/ice-9/boot-9.scm (call-with-input-string) (call-with-output-string): Implement in Scheme. * libguile/strports.c (scm_call_with_output_string): (scm_call_with_input_string): Dispatch to Scheme.
Diffstat (limited to 'libguile/strports.c')
-rw-r--r--libguile/strports.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/libguile/strports.c b/libguile/strports.c
index c8cce354e..7b51a8c87 100644
--- a/libguile/strports.c
+++ b/libguile/strports.c
@@ -354,35 +354,27 @@ SCM_DEFINE (scm_object_to_string, "object->string", 1, 1, 0,
}
#undef FUNC_NAME
-SCM_DEFINE (scm_call_with_output_string, "call-with-output-string", 1, 0, 0,
- (SCM proc),
- "Calls the one-argument procedure @var{proc} with a newly created output\n"
- "port. When the function returns, the string composed of the characters\n"
- "written into the port is returned.")
-#define FUNC_NAME s_scm_call_with_output_string
+SCM
+scm_call_with_output_string (SCM proc)
{
- SCM p;
+ static SCM var = SCM_BOOL_F;
- p = scm_mkstrport (SCM_INUM0, SCM_BOOL_F,
- SCM_OPN | SCM_WRTNG,
- FUNC_NAME);
- scm_call_1 (proc, p);
+ if (scm_is_false (var))
+ var = scm_c_private_lookup ("guile", "call-with-output-string");
- return scm_get_output_string (p);
+ return scm_call_1 (scm_variable_ref (var), proc);
}
-#undef FUNC_NAME
-SCM_DEFINE (scm_call_with_input_string, "call-with-input-string", 2, 0, 0,
- (SCM string, SCM proc),
- "Calls the one-argument procedure @var{proc} with a newly\n"
- "created input port from which @var{string}'s contents may be\n"
- "read. The value yielded by the @var{proc} is returned.")
-#define FUNC_NAME s_scm_call_with_input_string
+SCM
+scm_call_with_input_string (SCM string, SCM proc)
{
- SCM p = scm_mkstrport(SCM_INUM0, string, SCM_OPN | SCM_RDNG, FUNC_NAME);
- return scm_call_1 (proc, p);
+ static SCM var = SCM_BOOL_F;
+
+ if (scm_is_false (var))
+ var = scm_c_private_lookup ("guile", "call-with-input-string");
+
+ return scm_call_2 (scm_variable_ref (var), string, proc);
}
-#undef FUNC_NAME
SCM_DEFINE (scm_open_input_string, "open-input-string", 1, 0, 0,
(SCM str),