Repeatedly appending to a list is a common, if inefficient pattern
in functional programs. Usually the trick we use is to build up the
list in reverse, and then to reverse it as the last action of a
function.Dlists are a representation of lists as functions that provide for
constant time append to either the front or end of a dlist that may
be used instead.dlist? : any -> boolean
returns #t if its argument is a dlist, #f otherwise.
dlist-append : dlist dlist -> dlist
returns a new dlist consisting of all the elements of the first
dlist, followed by all the items of the second dlist.
(dlist-cons element dlist)
dlist-cons : any dlist -> dlist
returns a new dlist created by prepending the element to the head
of the dlist argument.
(dlist-snoc dlist element)
dlist-snoc : dlist any -> dlist
returns a new dlist created by appending the element to the tail of
the dlist argument.
dlist->list : dlist -> listof(any)
returns a list consisting of all the elements of the dlist.
list->dlist : listof(any) -> dlist
returns a dlist consisting of all the elements of the list.
dlist : any ... -> dlist
returns a dlist containing all its arguments.