guile-srfi-123

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

commit c6edf59c603a7661431c61d20eb4b86151e61633
parent ec8eadb1282ee12e11161d45499b9c33f6182d02
Author: Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com>
Date:   Sun, 16 Aug 2015 14:47:28 +0200

Add SRFI-4 support.

Diffstat:
Msrfi-123.html | 4++--
Msrfi-123.md | 14+++++++-------
Msrfi/123.body.scm | 60++++++++++++++++++++++++++++++++++++++++++++++++------------
Msrfi/123.sld | 4++++
4 files changed, 61 insertions(+), 21 deletions(-)

diff --git a/srfi-123.html b/srfi-123.html @@ -84,8 +84,8 @@ class="antispam">nospam</span>srfi.schemers.org</a></code>. To subscribe to the <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>Valid types for <code>object</code> are: bytevectors, hashtables, pairs, strings, vectors, all record types, and SRFI-4 vectors if present. 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, vectors, and SRFI-4 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> <ul> <li><code>(set! object field value)</code> (syntax)</li> diff --git a/srfi-123.md b/srfi-123.md @@ -195,15 +195,15 @@ error. ;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 -non-standard types they support. +vectors, all record types, and SRFI-4 vectors if present. Only +hashtables are a sparse type. Implementations are encouraged to +expand this list of types with any further types they support. Valid types for `field` depend on the type of `object`. For -bytevectors, hashtables, strings, and vectors, refer to their -respective `*-ref` procedures. For pairs, refer to `list-ref`. For -records, symbols that correspond with the record type's field names -are allowed. +bytevectors, hashtables, strings, vectors, and SRFI-4 vectors, refer +to their respective `*-ref` procedures. For pairs, refer to +`list-ref`. For records, symbols that correspond with the record +type's field names are allowed. If SRFI-17 is supported, then the `ref` procedure has the following setter: `(lambda (object field value) (set! object field value))` diff --git a/srfi/123.body.scm b/srfi/123.body.scm @@ -35,6 +35,36 @@ alist) table)) +;;; SRFI-4 support + +(cond-expand + ((library (srfi 4)) + (define srfi-4-getters + (list (cons s8vector? s8vector-ref) + (cons u8vector? u8vector-ref) + (cons s16vector? s16vector-ref) + (cons u16vector? u16vector-ref) + (cons s32vector? s32vector-ref) + (cons u32vector? u32vector-ref) + (cons s64vector? s64vector-ref) + (cons u64vector? u64vector-ref))) + (define srfi-4-setters + (list (cons s8vector? s8vector-set!) + (cons u8vector? u8vector-set!) + (cons s16vector? s16vector-set!) + (cons u16vector? u16vector-set!) + (cons s32vector? s32vector-set!) + (cons u32vector? u32vector-set!) + (cons s64vector? s64vector-set!) + (cons u64vector? u64vector-set!))) + (define srfi-4-types + (list s8vector? u8vector? s16vector? u16vector? s32vector? u32vector? + s64vector? u64vector?))) + (else + (define srfi-4-getters '()) + (define srfi-4-setters '()) + (define srfi-4-types '()))) + ;;; Main (define ref @@ -80,26 +110,32 @@ (define getter-table (alist->hashtable - (list (cons bytevector? bytevector-u8-ref) - (cons hashtable? hashtable-ref) - (cons pair? list-ref) - (cons string? string-ref) - (cons vector? vector-ref)))) + (append + (list (cons bytevector? bytevector-u8-ref) + (cons hashtable? hashtable-ref) + (cons pair? list-ref) + (cons string? string-ref) + (cons vector? vector-ref)) + srfi-4-getters))) (define setter-table (alist->hashtable - (list (cons bytevector? bytevector-u8-set!) - (cons hashtable? hashtable-set!) - (cons pair? list-set!) - (cons string? string-set!) - (cons vector? vector-set!)))) + (append + (list (cons bytevector? bytevector-u8-set!) + (cons hashtable? hashtable-set!) + (cons pair? list-set!) + (cons string? string-set!) + (cons vector? vector-set!)) + srfi-4-setters))) (define sparse-types (list hashtable?)) (define type-list - (list boolean? bytevector? char? eof-object? hashtable? null? number? pair? - port? procedure? string? symbol? vector?)) + (append + (list boolean? bytevector? char? eof-object? hashtable? null? number? pair? + port? procedure? string? symbol? vector?) + srfi-4-types)) (define-syntax define-record-type (syntax-rules () diff --git a/srfi/123.sld b/srfi/123.sld @@ -8,4 +8,8 @@ (r6rs hashtables) (srfi 1) (rename (srfi 17) (set! %set!))) + (cond-expand + ((library (srfi 4)) + (import (srfi 4))) + (else)) (include "123.body.scm"))