guile-srfi-123

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit fecbccd73db52b9b15ddf3fb29d2b42457995b5d
parent fc57f5e766d5f7eb0600547dd7a0e3c6df7dd0ed
Author: Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com>
Date:   Sat, 15 Aug 2015 14:34:27 +0200

Fix ref specification.

Diffstat:
MREADME.md | 25++++++++++++++++++-------
MSRFI.html | 9++++++++-
2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md @@ -149,16 +149,27 @@ Specification - `(ref object field)` (procedure) - `(ref object field default)` -Returns the value for `field` in `object`. If `object` is of a -"sparse" type, meaning its fields can be "empty" or "unassigned" -(e.g. a hashtable), and the requested field is empty, then the value -of `default` is returned if given, and otherwise an error raised. If -`object` is not of a sparse type, then `default` is ignored and an -error raised if object doesn't have a value for `field`. (This error -will typically come from the underlying accessor procedure.) +Returns the value for `field` in `object`. An error is raised if +`object` has no field identified by `field`. (This error will often +come from the underlying accessor procedure.) (ref #(0 1 2) 3) ;error: vector-ref: Index out of bounds. +If `object` is of a "sparse" type, meaning its fields can be "empty" +or "unassigned" (e.g. a hashtable), and the requested field is empty, +then the value of `default` is returned if given, and otherwise an +error raised. + + (ref hashtable unassigned-key 'default) ;=> default + (ref hashtable unassigned-key) ;error + +If `object` is not of a sparse type, then passing `default` is an +error. + + (ref '(0 1 2) 3 'default) ;error: list-ref: Too many arguments. + ;Unless the implementation's list-ref + ;does something else. + Valid types for `object` are: bytevectors, hashtables, pairs, strings, vectors, and all record types. Only hashtables are a sparse type. Implementations are encouraged to expand this list of types with any diff --git a/SRFI.html b/SRFI.html @@ -66,8 +66,15 @@ <li><code>(ref object field)</code> (procedure)</li> <li><code>(ref object field default)</code></li> </ul> -<p>Returns the value for <code>field</code> in <code>object</code>. If <code>object</code> is of a &quot;sparse&quot; type, meaning its fields can be &quot;empty&quot; or &quot;unassigned&quot; (e.g. a hashtable), and the requested field is empty, then the value of <code>default</code> is returned if given, and otherwise an error raised. If <code>object</code> is not of a sparse type, then <code>default</code> is ignored and an error raised if object doesn't have a value for <code>field</code>. (This error will typically come from the underlying accessor procedure.)</p> +<p>Returns the value for <code>field</code> in <code>object</code>. An error is raised if <code>object</code> has no field identified by <code>field</code>. (This error will often come from the underlying accessor procedure.)</p> <pre><code>(ref #(0 1 2) 3) ;error: vector-ref: Index out of bounds.</code></pre> +<p>If <code>object</code> is of a &quot;sparse&quot; type, meaning its fields can be &quot;empty&quot; or &quot;unassigned&quot; (e.g. a hashtable), and the requested field is empty, then the value of <code>default</code> is returned if given, and otherwise an error raised.</p> +<pre><code>(ref hashtable unassigned-key &#39;default) ;=&gt; default +(ref hashtable unassigned-key) ;error</code></pre> +<p>If <code>object</code> is not of a sparse type, then passing <code>default</code> is an error.</p> +<pre><code>(ref &#39;(0 1 2) 3 &#39;default) ;error: list-ref: Too many arguments. + ;Unless the implementation&#39;s list-ref + ;does something else.</code></pre> <p>Valid types for <code>object</code> are: bytevectors, hashtables, pairs, strings, vectors, and all record types. Only hashtables are a sparse type. Implementations are encouraged to expand this list of types with any non-standard types they support.</p> <p>Valid types for <code>field</code> depend on the type of <code>object</code>. For bytevectors, hashtables, strings, and vectors, refer to their respective <code>*-ref</code> procedures. For pairs, refer to <code>list-ref</code>. For records, symbols that correspond with the record type's field names are allowed.</p> <p>If SRFI-17 is supported, then the <code>ref</code> procedure has the following setter: <code>(lambda (object field value) (set! object field value))</code></p>