1
0
Fork 0
cl-sites/guile.html_node/Procedure-Properties.html
2024-12-17 12:49:28 +01:00

173 lines
12 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>Procedure Properties (Guile Reference Manual)</title>
<meta name="description" content="Procedure Properties (Guile Reference Manual)">
<meta name="keywords" content="Procedure Properties (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="Procedures.html" rel="up" title="Procedures">
<link href="Procedures-with-Setters.html" rel="next" title="Procedures with Setters">
<link href="Higher_002dOrder-Functions.html" rel="prev" title="Higher-Order Functions">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</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="Procedure-Properties">
<div class="nav-panel">
<p>
Next: <a href="Procedures-with-Setters.html" accesskey="n" rel="next">Procedures with Setters</a>, Previous: <a href="Higher_002dOrder-Functions.html" accesskey="p" rel="prev">Higher-Order Functions</a>, Up: <a href="Procedures.html" accesskey="u" rel="up">Procedures</a> &nbsp; [<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="Procedure-Properties-and-Meta_002dinformation"><span>6.7.7 Procedure Properties and Meta-information<a class="copiable-link" href="#Procedure-Properties-and-Meta_002dinformation"> &para;</a></span></h4>
<p>In addition to the information that is strictly necessary to run,
procedures may have other associated information. For example, the
name of a procedure is information not for the procedure, but about
the procedure. This meta-information can be accessed via the procedure
properties interface.
</p>
<a class="index-entry-id" id="index-procedure_003f-2"></a>
<dl class="first-deffn">
<dt class="deffn" id="index-procedure_003f"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">procedure?</strong> <var class="def-var-arguments">obj</var><a class="copiable-link" href="#index-procedure_003f"> &para;</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-scm_005fprocedure_005fp"><span class="category-def">C Function: </span><span><strong class="def-name">scm_procedure_p</strong> <var class="def-var-arguments">(obj)</var><a class="copiable-link" href="#index-scm_005fprocedure_005fp"> &para;</a></span></dt>
<dd><p>Return <code class="code">#t</code> if <var class="var">obj</var> is a procedure.
</p></dd></dl>
<dl class="first-deffn">
<dt class="deffn" id="index-thunk_003f"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">thunk?</strong> <var class="def-var-arguments">obj</var><a class="copiable-link" href="#index-thunk_003f"> &para;</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-scm_005fthunk_005fp"><span class="category-def">C Function: </span><span><strong class="def-name">scm_thunk_p</strong> <var class="def-var-arguments">(obj)</var><a class="copiable-link" href="#index-scm_005fthunk_005fp"> &para;</a></span></dt>
<dd><p>Return <code class="code">#t</code> if <var class="var">obj</var> is a procedure that can be called with
zero arguments. See <a class="xref" href="Compiled-Procedures.html">Compiled Procedures</a>, to get more information
on what arguments a procedure will accept.
</p></dd></dl>
<a class="index-entry-id" id="index-procedure-properties"></a>
<p>Procedure properties are general properties associated with
procedures. These can be the name of a procedure or other relevant
information, such as debug hints.
</p>
<p>The most general way to associate a property of a procedure is
programmatically:
</p>
<dl class="first-deffn">
<dt class="deffn" id="index-procedure_002dproperty"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">procedure-property</strong> <var class="def-var-arguments">proc key</var><a class="copiable-link" href="#index-procedure_002dproperty"> &para;</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-scm_005fprocedure_005fproperty"><span class="category-def">C Function: </span><span><strong class="def-name">scm_procedure_property</strong> <var class="def-var-arguments">(proc, key)</var><a class="copiable-link" href="#index-scm_005fprocedure_005fproperty"> &para;</a></span></dt>
<dd><p>Return the property of <var class="var">proc</var> with name <var class="var">key</var>, or <code class="code">#f</code> if
not found.
</p></dd></dl>
<dl class="first-deffn">
<dt class="deffn" id="index-set_002dprocedure_002dproperty_0021"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">set-procedure-property!</strong> <var class="def-var-arguments">proc key value</var><a class="copiable-link" href="#index-set_002dprocedure_002dproperty_0021"> &para;</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-scm_005fset_005fprocedure_005fproperty_005fx"><span class="category-def">C Function: </span><span><strong class="def-name">scm_set_procedure_property_x</strong> <var class="def-var-arguments">(proc, key, value)</var><a class="copiable-link" href="#index-scm_005fset_005fprocedure_005fproperty_005fx"> &para;</a></span></dt>
<dd><p>Set <var class="var">proc</var>&rsquo;s property named <var class="var">key</var> to <var class="var">value</var>.
</p></dd></dl>
<p>However, there is a more efficient interface that allows constant
properties to be embedded into compiled binaries in a way that does
not incur any overhead until someone asks for the property: initial
non-tail elements of the body of a lambda expression that are literal
vectors of pairs are interpreted as declaring procedure properties.
This is easiest to see with an example:
</p>
<div class="example">
<pre class="example-preformatted">(define proc
(lambda args
#((a . &quot;hey&quot;) (b . &quot;ho&quot;)) ;; procedure properties!
42))
(procedure-property proc 'a) ; &rArr; &quot;hey&quot;
(procedure-property proc 'b) ; &rArr; &quot;ho&quot;
</pre></div>
<p>There is a shorthand for declaring the <code class="code">documentation</code> property,
which is a literal string instead of a literal vector:
</p>
<div class="example">
<pre class="example-preformatted">(define proc
(lambda args
&quot;This is a docstring.&quot;
42))
(procedure-property proc 'documentation)
;; &rArr; &quot;This is a docstring.&quot;
</pre></div>
<p>Calling <code class="code">procedure-property</code> with a key of <code class="code">documentation</code>
is exactly the same as calling <code class="code">procedure-documentation</code>.
Similarly, <code class="code">procedure-name</code> is the same as the <code class="code">name</code>
procedure property, and <code class="code">procedure-source</code> is for the
<code class="code">source</code> property.
</p>
<dl class="first-deffn">
<dt class="deffn" id="index-procedure_002dname"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">procedure-name</strong> <var class="def-var-arguments">proc</var><a class="copiable-link" href="#index-procedure_002dname"> &para;</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-scm_005fprocedure_005fname"><span class="category-def">C Function: </span><span><strong class="def-name">scm_procedure_name</strong> <var class="def-var-arguments">(proc)</var><a class="copiable-link" href="#index-scm_005fprocedure_005fname"> &para;</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-procedure_002dsource"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">procedure-source</strong> <var class="def-var-arguments">proc</var><a class="copiable-link" href="#index-procedure_002dsource"> &para;</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-scm_005fprocedure_005fsource"><span class="category-def">C Function: </span><span><strong class="def-name">scm_procedure_source</strong> <var class="def-var-arguments">(proc)</var><a class="copiable-link" href="#index-scm_005fprocedure_005fsource"> &para;</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-procedure_002ddocumentation"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">procedure-documentation</strong> <var class="def-var-arguments">proc</var><a class="copiable-link" href="#index-procedure_002ddocumentation"> &para;</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-scm_005fprocedure_005fdocumentation"><span class="category-def">C Function: </span><span><strong class="def-name">scm_procedure_documentation</strong> <var class="def-var-arguments">(proc)</var><a class="copiable-link" href="#index-scm_005fprocedure_005fdocumentation"> &para;</a></span></dt>
<dd><p>Return the value of the <code class="code">name</code>, <code class="code">source</code>, or
<code class="code">documentation</code> property for <var class="var">proc</var>, or <code class="code">#f</code> if no
property is set.
</p></dd></dl>
<p>One can also work on the entire set of procedure properties.
</p>
<dl class="first-deffn">
<dt class="deffn" id="index-procedure_002dproperties"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">procedure-properties</strong> <var class="def-var-arguments">proc</var><a class="copiable-link" href="#index-procedure_002dproperties"> &para;</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-scm_005fprocedure_005fproperties"><span class="category-def">C Function: </span><span><strong class="def-name">scm_procedure_properties</strong> <var class="def-var-arguments">(proc)</var><a class="copiable-link" href="#index-scm_005fprocedure_005fproperties"> &para;</a></span></dt>
<dd><p>Return the properties associated with <var class="var">proc</var>, as an association
list.
</p></dd></dl>
<dl class="first-deffn">
<dt class="deffn" id="index-set_002dprocedure_002dproperties_0021"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">set-procedure-properties!</strong> <var class="def-var-arguments">proc alist</var><a class="copiable-link" href="#index-set_002dprocedure_002dproperties_0021"> &para;</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-scm_005fset_005fprocedure_005fproperties_005fx"><span class="category-def">C Function: </span><span><strong class="def-name">scm_set_procedure_properties_x</strong> <var class="def-var-arguments">(proc, alist)</var><a class="copiable-link" href="#index-scm_005fset_005fprocedure_005fproperties_005fx"> &para;</a></span></dt>
<dd><p>Set <var class="var">proc</var>&rsquo;s property list to <var class="var">alist</var>.
</p></dd></dl>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Procedures-with-Setters.html">Procedures with Setters</a>, Previous: <a href="Higher_002dOrder-Functions.html">Higher-Order Functions</a>, Up: <a href="Procedures.html">Procedures</a> &nbsp; [<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>