@@ -371,3 +371,69 @@ a Table-extensions module, which you can read about in
371
371
It returns a hash ID (an integer) and the result of merging the
372
372
initial state with the associated hash state for the object,
373
373
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.
0 commit comments