2019-01-06

(sph record)

*deprecated* vectors as records.

part of sph-lib

library description

see vector-accessor from (sph vector) instead and create records like #(symbol:type-name value ...).

access vector elements with field names.

this library is supposed to be simpler in definition and usage than previously existing record libraries (rnrs, srfi) and

more powerful by being based on vectors (records) and hashtables (layouts) and their less restricted interoperability.

any vector can be accessed as a record and records can be accessed as vectors.

if type information is desired then for example a symbol type name can be used as the first element of the vector.

vector records have the typical literal vector representation for read/write.

usage:

(define-record my-record a b c)

(define-record my-other-record (a accessor-name setter-name) b (c my-other-c))

(define x (record my-record 1 2))

(my-record-a x) -> 1

(my-record-c x) -> #f

(my-record-c-set! x 3)

syntax

  record-update-b :: record-layout a field-names ...

    create a new vector with field name and value taken from given identifier and variable value.

    example: (record-update layout instance name name-2)

    same as (record-update layout instance (q name) name (q name-2) name ...)

import name

(sph record)

exports

procedure: alist->record a record-layout ->
alist record-layout -> record
extract record data from alist using record-layout and result in one record. currently, string keys are also recognized
syntax: define-record
syntax: define-record-accessors record-layout (identifier field-name) ...
syntax: define-record-setters record-layout (identifier field-name) ...
procedure: make-record record-layout ->
record-layout -> record
procedure: make-record-layout field-spec ->
(symbol ...) -> record-layout
results in a new record-layout with the given field names
procedure: record record-layout values ... ->
record-layout (any ...) -> record
create a new record by specifying the layout and the values in the same order as they are specified in layout field-spec. not all values have to be given, unspecified fields are set to <unspecified>
procedure: record-accessor record-layout field-name ->
record-layout symbol -> procedure {record -> field-value}
returns an accessor procedure for the given record-layout and field-name.
procedure: record-accessors record-layout ->
hashtable:record-layout -> (proc ...)
returns all accessors for the given record-layout in a list
procedure: record-append ->
(vector-append vec ...) -> vector
Return a newly allocated vector that contains all elements in order from the subsequent locations in VEC ...
procedure: record-field-names record-layout ->
hashtable:record-layout -> vector:#(symbol ...)
result in the field-names of record in the same order as they were specified.
procedure: record-field-names-unordered hashtable ->
procedure: record-layout->predicate a [type-prefix] ->
record-layout [symbol:type-name] -> procedure:{vector -> boolean}
if type-prefix is given, the first field of the record is required to contain the type-prefix
procedure: record-layout-extend! layout-1 layout-2 ->
procedure: record-layout-length hashtable ->
procedure: record-layout-merge! a b ... ->
hashtable hashtable ... -> unspecified
copy the values of hash b to hash a. existing key values are overwritten
procedure: record-layout? obj ->
procedure: record-length a ->
procedure: record-list-filter-value record-list value match-accessor retrieve-accessor ->
list procedure:accessor procedure:accessor -> false/(any ...)
filter record list entries by values retrieved by match-accessor that match the given value, and return a list of values retrieved by retrieve-accessor
procedure: record-ref record record-layout field-name ->
record record-layout symbol -> any
get the value for field-name of the given record. record-ref is considerably slower than using an accessor procedure
procedure: record-setter record-layout field-name ->
record-layout symbol -> procedure {record value -> unspecified}
returns a setter procedure for the given layout and field-name
procedure: record-setters record-layout ->
record-layout (symbol ...) -> proc ...
returns all setters for the given layout in a list
procedure: record-take record-layout a ->
this adjusts the length of the given vector to match the length of the layout. extra fields in are left out if the layout is smaller
procedure: record-update record-layout a field-name/value ... ->
vector [integer any] ... -> vector
create a copy of the given record with values in fields set to new values. field name and value are given alternatingly. example: (record-update myrecord (quote a) #\c (quote b) #\d)
syntax: record-update-b record-layout a field-name ...
syntax: record-update-q record-layout a field-name/value ...
procedure: record? a ->
procedure: vector->record record-layout a ->
this adjusts the length of the given vector to match the length of the layout. extra fields in are left out if the layout is smaller