Previous: , Up: lang   [Index]


1.20 Tuples on top of lists and vectors

The library (vicare language-extensions tuples) implements tuples on top of ordinary Scheme lists and vectors; the library makes use of the typed language. Tuple–types are label–types used to provide convenient read–only access to lists and vectors ((vicare-scheme)Sub-typing with labels).

The following syntactic bindings are exported by the library (vicare language-extensions tuples).

Syntax: define-list-tuple-type ?name ?clause
Syntax: define-vector-tuple-type ?name ?clause
Auxiliary Syntax: fields
Auxiliary Syntax: brace

Define a new tuple type on top of lists or vectors.

At present only the fields clause is supported; the syntactic bindings fields and brace are the ones exported by the library (vicare).

The clause fields must have the following format:

(fields ?field-spec0 ?field-spec ...)

where each ?field-spec must have one of the following formats:

?field-name
(brace ?field-name ?field-type)

where ?field-name is a syntactic identifier representing the field name and ?field-type is a syntax object representing the field’s type annotation. When no type annotation is specified: it defaults to <top>.

Usage examples with lists and untyped fields:

(define-list-tuple-type <stuff>
  (fields a b c))

(define T
  (new <stuff> 1 2 3))

(.a T)  ⇒ 1
(.b T)  ⇒ 2
(.c T)  ⇒ 3

usage examples with vectors and typed fields:

(define-vector-tuple-type <stuff>
  (fields {a <fixnum>}
          {b <flonum>}
          {c <string>}))

(define T
  (new <stuff> 1 2.3 "ciao"))

T                       ⇒ #(1 2.3 "ciao")
(.a T)                  ⇒ 1
(.b T)                  ⇒ 2.3
(.c T)                  ⇒ "ciao"
(.length (.c T))        ⇒ 4

Previous: , Up: lang   [Index]