Circular lists
Thomas Charles CONWAY
conway at students.cs.mu.oz.au
Thu Nov 27 11:21:01 AEDT 1997
Hi
With all this talk of circular lists, I thought people might be
interested/amused by the following.
Beware, it is a complete hack, but IMHO quite cute.
Enjoy,
Thomas
--
ZZ:wq!
^X^C
Thomas Conway conway at cs.mu.oz.au
AD DEUM ET VINUM Every sword has two edges.
:- module inflist.
:- interface.
:- import_module list.
:- inst circular_list = bound([ground|circular_list]).
:- pred circularize(list(T), list(T)).
:- mode circularize(di(non_empty_list), out(circular_list)) is det.
:- implementation.
:- pragma c_code(circularize(A::di(non_empty_list), B::out(circular_list)), "
B = A;
while (field(mktag(1), A, 1) != 0)
A = field(mktag(1), A, 1);
field(mktag(1), A, 1) = B;
").
More information about the users
mailing list