Previous chapter: #11: Last-Setter (Addition)

Dylan Design Notes: #12: Size-Setter for Stretchy Sequences (Addition)

Dylan Design Notes

#12: Size-Setter for Stretchy Sequences (Addition)

Version 1, March 1993

This design note adds the generic function size-setter to the language specification, allowing the size of a stretchy sequence to be changed in a single operation.


Add a new generic function, with predefined methods for <stretchyvector> and <deque>, as follows:

size-setter sequence n   => n                [Generic Function]
Sets the size of sequence to be n. sequence is destructively modified.

If n is less than or equal to the original size of sequence, then the first n elements of sequence are retained at the same positions. If n is greater than the original size of sequence, then the previous elements of sequence are retained at the same positions, and enough new elements are added to reach the new size. The value of each new element is the same as would have been used if sequence had been created with make, specifying size: n but not fill:.

It is not specified how size-setter adds new elements to a sequence. In particular, size-setter is not required to call add! or any other predefined Dylan function.

? (define my-deque (make <deque> size: 5 fill: 10))
;unspecified
? my-deque
{deque 10 10 10 10 10}
? (set! (size my-deque) 10)
10
? my-deque
{deque 10 10 10 10 10 #f #f #f #f #f}
? (set! (size my-deque) 3)
3
? my-deque
{deque 10 10 10}
? (set! (size my-deque) 5)
5
? my-deque
{deque 10 10 10 #f #f}

Next chapter: #13: Type Restrictions Survive Assignment (Change)