From: Ralph Mason Date: 2004-01-13T14:38:26+09:00 Subject: Re: Linked vs Array-based Lists (Was: Getting the tail of a list?) Jim Weirich wrote: > Good answer, but a minor quibble is addressed below ... > > jason r tibbetts wrote: > >> Nobody's really addressed this question posed by the OP. There are >> several facets to the answer. The short answer is that procedural and >> object-oriented languages [...] > > Its not so much the difference between procedural and OO languages, > but between link-list and array-based lists. > > A lot of times, with our glut of data structures in modern languages, > we forget the elegance of the simple linked list data structure. Ward > Cunningham uses linked lists to great effect in his FIT library and > achieves elegance in code that would have been clumsy if he had stayed > with the library supplied container classes. The source for the FIT > library is recommended reading for programmers. > It's always horses for courses though. If the OP just wants to show the class a simular construct in ruby creating a linked list class strays from the problem. It's also a grand example of premature optimisation inthis case - the root of many programing evils. How about simply this (to show the conversion of the scheme, and also show how you can replace and extend ruby) class Array def guest (name, list) return false if list.empty? return true if name == list.shift guest name,list end def include?(name) guest name,clone end end Ralph