Skip to content

Commit 28e4204

Browse files
committed
Merge pull request #622 from BarAgent/dep-0007
DEP-0007 Type-Safe Limited Collections
2 parents 0132fff + 92d2d5d commit 28e4204

33 files changed

+1391
-595
lines changed

documentation/library-reference/source/dylan/index.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,69 @@ a Table-extensions module, which you can read about in
371371
It returns a hash ID (an integer) and the result of merging the
372372
initial state with the associated hash state for the object,
373373
computed in some implementation-dependent manner.
374+
375+
Limited Collections
376+
-------------------
377+
378+
To improve type safety of limited collections, Open Dylan implements an
379+
extension to the :drm:`make` and :drm:`limited` functions. Normally, when
380+
calling :drm:`make` on a collection that supports the ``fill:`` init-keyword,
381+
that keyword defaults to ``#f``. This value can be inappropriate for a limited
382+
collection. The :drm:`limited` function in Open Dylan accepts a
383+
``default-fill:`` keyword argument which replaces the default of ``#f`` with a
384+
user-specified value; this value is used by :drm:`make` and :drm:`size-setter`
385+
when initializing or adding elements to those collections.
386+
387+
Open Dylan also implements the :func:`element-type` and
388+
:func:`element-type-fill` functions to further improve type safety.
389+
390+
.. function:: limited
391+
392+
Open Dylan implements the following altered signatures.
393+
394+
:signature: limited singleton(<array>) #key *of* *size* *dimensions* *default-fill* => *type*
395+
:signature: limited singleton(<vector>) #key *of* *size* *default-fill* => *type*
396+
:signature: limited singleton(<simple-vector>) #key *of* *size* *default-fill* => *type*
397+
:signature: limited singleton(<stretchy-vector>) #key *of* *default-fill* => *type*
398+
:signature: limited singleton(<deque>) #key *of* *default-fill* => *type*
399+
:signature: limited singleton(<string>) #key *of* *size* *default-fill* => *type*
400+
401+
:param #key default-fill:
402+
The default value of the ``fill:`` keyword argument to the :drm:`make`
403+
function, replacing ``#f``. Optional. If not supplied, the default
404+
value for the ``default-fill:`` argument and thus for the ``fill:``
405+
argument to :drm:`make` is ``#f`` (or ``' '`` for strings).
406+
407+
:example:
408+
409+
.. code-block:: dylan
410+
411+
define constant <answers-vector>
412+
= limited(<vector>, of: <object>, default-fill: 42);
413+
let some-answers = make(<answers-vector>, size: 3);
414+
// #[ 42, 42, 42 ]
415+
416+
.. generic-function:: element-type
417+
:open:
418+
419+
Returns the element type of a collection.
420+
421+
:signature: element-type *collection* => *type*
422+
423+
:param collection: An instance of :drm:`<collection>`.
424+
:value type: The permitted element type of the collection.
425+
426+
.. generic-function:: element-type-fill
427+
:open:
428+
429+
Returns a valid object that may be used for new elements of a collection.
430+
431+
:signature: element-type-fill *collection* => *object*
432+
433+
:param collection: An instance of :drm:`<collection>` that supports the
434+
``fill:`` init-keyword.
435+
:value object: An object.
436+
437+
:discussion: For limited collections, this object will be the defaulted or
438+
supplied ``default-fill:`` argument to the :func:`limited`
439+
function.

documentation/release-notes/source/2014.1.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,26 @@ Common Dylan
8484
* The function ``integer-to-string`` is now faster.
8585

8686

87+
Dylan
88+
=====
89+
90+
Open Dylan now implements
91+
`DEP-0007 (Type-Safe Limited Collections) <http://opendylan.org/proposals/dep-0007.html>`_.
92+
This adds a ``default-fill:`` argument to ``limited``, a corresponding
93+
``element-type-fill`` generic function, and an ``element-type`` generic
94+
function applicable to all collections. With this, limited collections will now
95+
be easier and safer to use—with one caveat:
96+
97+
As described in the DEP-0007 document, Open Dylan had previously ensured that
98+
some numeric limited collection types would automatically be filled with ``0``
99+
when instantiated *with* a non-zero size but *without* a ``fill:`` init-keyword.
100+
This is no longer the case. Code that relied on this behavior must be updated
101+
to provide valid ``fill:`` or ``default-fill:`` values.
102+
103+
``element`` will no longer signal a type error when it returns its ``default:``
104+
value and that value does not match the element type of a limited collection.
105+
106+
87107
dylan-direct-c-ffi
88108
==================
89109

sources/common-dylan/byte-vector.dylan

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ License: See License.txt in this distribution for details.
1010
///// BYTE-VECTOR
1111
/////
1212

13-
define constant <byte-vector> = limited(<vector>, of: <byte>);
13+
define constant <byte-vector> = limited(<vector>, of: <byte>, default-fill: as(<byte>, 0));
1414

1515
/// Fast byte vector copying
1616

sources/common-dylan/format.dylan

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Warranty: Distributed WITHOUT WARRANTY OF ANY KIND
1010
/// String buffers
1111

1212
//---*** Oh for a stretchy string...
13-
define constant <string-buffer> = limited(<stretchy-vector>, of: <byte-character>);
13+
define constant <string-buffer> = limited(<stretchy-vector>, of: <byte-character>,
14+
default-fill: as(<byte-character>, ' '));
1415

1516
//---*** Is there a more efficient way to do this?
1617
define function print-string

0 commit comments

Comments
 (0)