+ if (!SCM_UNBNDP (printer))
+ SCM_VALIDATE_PROC (2, printer);
+
+ str = scm_allocate_string (0);
+ port = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_WRTNG, FUNC_NAME);
+
+ if (SCM_UNBNDP (printer))
+ scm_write (obj, port);
+ else
+ scm_call_2 (printer, obj, port);
+
+ return scm_strport_to_string (port);
+}
+#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