131 lines
6.4 KiB
HTML
131 lines
6.4 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<!-- This manual documents Guile version 3.0.10.
|
|
|
|
Copyright (C) 1996-1997, 2000-2005, 2009-2023 Free Software Foundation,
|
|
Inc.
|
|
|
|
Copyright (C) 2021 Maxime Devos
|
|
|
|
Copyright (C) 2024 Tomas Volf
|
|
|
|
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
|
any later version published by the Free Software Foundation; with no
|
|
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
|
|
copy of the license is included in the section entitled "GNU Free
|
|
Documentation License." -->
|
|
<title>Strings (Guile Reference Manual)</title>
|
|
|
|
<meta name="description" content="Strings (Guile Reference Manual)">
|
|
<meta name="keywords" content="Strings (Guile Reference Manual)">
|
|
<meta name="resource-type" content="document">
|
|
<meta name="distribution" content="global">
|
|
<meta name="Generator" content=".texi2any-real">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
|
|
<link href="index.html" rel="start" title="Top">
|
|
<link href="Concept-Index.html" rel="index" title="Concept Index">
|
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
|
<link href="Data-Types.html" rel="up" title="Data Types">
|
|
<link href="Symbols.html" rel="next" title="Symbols">
|
|
<link href="Character-Sets.html" rel="prev" title="Character Sets">
|
|
<style type="text/css">
|
|
<!--
|
|
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
|
|
span:hover a.copiable-link {visibility: visible}
|
|
-->
|
|
</style>
|
|
<link rel="stylesheet" type="text/css" href="https://www.gnu.org/software/gnulib/manual.css">
|
|
|
|
|
|
</head>
|
|
|
|
<body lang="en">
|
|
<div class="subsection-level-extent" id="Strings">
|
|
<div class="nav-panel">
|
|
<p>
|
|
Next: <a href="Symbols.html" accesskey="n" rel="next">Symbols</a>, Previous: <a href="Character-Sets.html" accesskey="p" rel="prev">Character Sets</a>, Up: <a href="Data-Types.html" accesskey="u" rel="up">Data Types</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
<hr>
|
|
<h4 class="subsection" id="Strings-1"><span>6.6.5 Strings<a class="copiable-link" href="#Strings-1"> ¶</a></span></h4>
|
|
<a class="index-entry-id" id="index-Strings"></a>
|
|
|
|
<p>Strings are fixed-length sequences of characters. They can be created
|
|
by calling constructor procedures, but they can also literally get
|
|
entered at the <abbr class="acronym">REPL</abbr> or in Scheme source files.
|
|
</p>
|
|
|
|
<p>Strings always carry the information about how many characters they are
|
|
composed of with them, so there is no special end-of-string character,
|
|
like in C. That means that Scheme strings can contain any character,
|
|
even the ‘<samp class="samp">#\nul</samp>’ character ‘<samp class="samp">\0</samp>’.
|
|
</p>
|
|
<p>To use strings efficiently, you need to know a bit about how Guile
|
|
implements them. In Guile, a string consists of two parts, a head and
|
|
the actual memory where the characters are stored. When a string (or
|
|
a substring of it) is copied, only a new head gets created, the memory
|
|
is usually not copied. The two heads start out pointing to the same
|
|
memory.
|
|
</p>
|
|
<p>When one of these two strings is modified, as with <code class="code">string-set!</code>,
|
|
their common memory does get copied so that each string has its own
|
|
memory and modifying one does not accidentally modify the other as well.
|
|
Thus, Guile’s strings are ‘copy on write’; the actual copying of their
|
|
memory is delayed until one string is written to.
|
|
</p>
|
|
<p>This implementation makes functions like <code class="code">substring</code> very
|
|
efficient in the common case that no modifications are done to the
|
|
involved strings.
|
|
</p>
|
|
<p>If you do know that your strings are getting modified right away, you
|
|
can use <code class="code">substring/copy</code> instead of <code class="code">substring</code>. This
|
|
function performs the copy immediately at the time of creation. This
|
|
is more efficient, especially in a multi-threaded program. Also,
|
|
<code class="code">substring/copy</code> can avoid the problem that a short substring
|
|
holds on to the memory of a very large original string that could
|
|
otherwise be recycled.
|
|
</p>
|
|
<p>If you want to avoid the copy altogether, so that modifications of one
|
|
string show up in the other, you can use <code class="code">substring/shared</code>. The
|
|
strings created by this procedure are called <em class="dfn">mutation sharing
|
|
substrings</em> since the substring and the original string share
|
|
modifications to each other.
|
|
</p>
|
|
<p>If you want to prevent modifications, use <code class="code">substring/read-only</code>.
|
|
</p>
|
|
<p>Guile provides all procedures of SRFI-13 and a few more.
|
|
</p>
|
|
|
|
<ul class="mini-toc">
|
|
<li><a href="String-Syntax.html" accesskey="1">String Read Syntax</a></li>
|
|
<li><a href="String-Predicates.html" accesskey="2">String Predicates</a></li>
|
|
<li><a href="String-Constructors.html" accesskey="3">String Constructors</a></li>
|
|
<li><a href="List_002fString-Conversion.html" accesskey="4">List/String conversion</a></li>
|
|
<li><a href="String-Selection.html" accesskey="5">String Selection</a></li>
|
|
<li><a href="String-Modification.html" accesskey="6">String Modification</a></li>
|
|
<li><a href="String-Comparison.html" accesskey="7">String Comparison</a></li>
|
|
<li><a href="String-Searching.html" accesskey="8">String Searching</a></li>
|
|
<li><a href="Alphabetic-Case-Mapping.html" accesskey="9">Alphabetic Case Mapping</a></li>
|
|
<li><a href="Reversing-and-Appending-Strings.html">Reversing and Appending Strings</a></li>
|
|
<li><a href="Mapping-Folding-and-Unfolding.html">Mapping, Folding, and Unfolding</a></li>
|
|
<li><a href="Miscellaneous-String-Operations.html">Miscellaneous String Operations</a></li>
|
|
<li><a href="Representing-Strings-as-Bytes.html">Representing Strings as Bytes</a></li>
|
|
<li><a href="Conversion-to_002ffrom-C.html">Conversion to/from C</a></li>
|
|
<li><a href="String-Internals.html">String Internals</a></li>
|
|
</ul>
|
|
</div>
|
|
<hr>
|
|
<div class="nav-panel">
|
|
<p>
|
|
Next: <a href="Symbols.html">Symbols</a>, Previous: <a href="Character-Sets.html">Character Sets</a>, Up: <a href="Data-Types.html">Data Types</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|