Everything2
Near Matches
Ignore Exact
Full Text
Everything2

Teach Yourself Scheme: 7.4 String ports

created by washort

(idea) by washort (6.8 y) (print)   ?   (I like it!) Tue Apr 18 2000 at 23:10:49

Prev Up Next

It is often convenient to associate ports with strings. Thus, the procedure open-input-string associates a port with a given string. Reader procedures on this port will read off the string:

(define i (open-input-string "hello world"))

(read-char i)
=> #\h

(read i)
=> ello

(read i)
=> world

The procedure open-output-string creates an output port that will eventually be used to create a string:

(define o (open-output-string))

(write 'hello o)
(write-char #\, o)
(display " " o)
(display "world" o)

You can now use the procedure get-output-string to get the accumulated string in the string port o:

(get-output-string o)
=> "hello, world"

String ports need not be explicitly closed.

Prev Up Next


printable version
chaos

Teach Yourself Scheme: 7.5 Loading files Teach Yourself Scheme air separator Teach Yourself Scheme: 7.3 File ports
Mene, mene, tekel, upharsin
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Nodes to live by:
September 11, 2001 - III
Rules of program optimization
Irish Wake
Louisiana Purchase
Critias
CCBBA Karate Curriculum
sorghum
Thomas Jefferson's First Inaugural Address
How to meet the most girls
hypoglycemia
Gloria Anzaldúa Memorial Quest
Making an F-16 from a cereal box, some Scotch tape, and a penny
Cy Twombly
New Writeups
XWiz
Trism(review)
artman2003
Briefcase Full of Souls - Part I(fiction)
Dreamvirus
Alan Ladd(person)
waverider37
Harold Holt(person)
The Debutante
Until death do us part(fiction)
Ysardo
a brother to a sister(personal)
antigravpussy
your warm whispers(personal)
Clarke
Multiculturalism(idea)
aneurin
Earl of Landaff(person)
Heitah
Pseudocide(idea)
XWiz
Google Knol(lede)
Mythi
July 24, 2008(personal)
locke baron
The fall of Earth(fiction)
BookReader
Fear the Cold(dream)
Pavlovna
Kathleen MacInnes(person)
E2 is a by-product of the existence of The Everything Development Company