Movatterモバイル変換


[0]ホーム

URL:


[LISPWORKS][Common Lisp HyperSpec (TM)][Previous][Up][Next]


MacroWITH-OUTPUT-TO-STRING

Syntax:

with-output-to-string(var&optional string-form&key element-type)declaration*form*

=>result*

Arguments and Values:

var---avariablename.

string-form---aform ornil; ifnon-nil, evaluated to producestring.

string---astring that has afill pointer.

element-type---atype specifier; evaluated. The default ischaracter.

declaration---adeclareexpression; not evaluated.

forms---animplicit progn.

results---If astring-form is not supplied ornil, astring; otherwise, thevalues returned by theforms.

Description:

with-output-to-string creates a characteroutputstream, performs a series of operations that may send results to thisstream, and then closes thestream.

Theelement-type names thetype of the elements of thestream; astream is constructed of the most specializedtype that can accommodate elements of the giventype.

The body is executed as animplicit progn withvar bound to anoutputstring stream. All output to thatstring stream is saved in astring.

Ifstring is supplied,element-type is ignored, and the output is incrementally appended tostring as if by use ofvector-push-extend.

Theoutputstream is automatically closed on exit fromwith-output-from-string, no matter whether the exit is normal or abnormal. Theoutputstring stream to which thevariablevar isbound hasdynamic extent; itsextent ends when theform is exited.

If nostring is provided, thenwith-output-from-string produces astream that accepts characters and returns astring of the indicatedelement-type. Ifstring is provided,with-output-to-string returns the results of evaluating the lastform.

The consequences are undefined if an attempt is made toassign thevariablevar.

Examples:

 (setq fstr (make-array '(0) :element-type 'base-char                             :fill-pointer 0 :adjustable t)) =>  "" (with-output-to-string (s fstr)    (format s "here's some output")    (input-stream-p s)) =>false fstr =>  "here's some output"

Side Effects:

Thestring is modified.

Affected By: None.

Exceptional Situations:

The consequences are undefined if destructive modifications are performed directly on thestring during thedynamic extent of the call.

See Also:

make-string-output-stream,vector-push-extend,Section 3.6 (Traversal Rules and Side Effects)

Notes: None.


The followingX3J13 cleanup issues,not part of the specification, apply to this section:


[Starting Points][Contents][Index][Symbols][Glossary][Issues]
Copyright 1996-2005, LispWorks Ltd. All rights reserved.


[8]ページ先頭

©2009-2025 Movatter.jp