From: Gennady Date: 2004-01-13T09:03:52+09:00 Subject: Re: Getting the tail of a list? Carsten Eckelmann wrote: > Hi everybody, > > I have spent the night reading about the wonders of Scheme at > http://www.teach-scheme.org and have stumbled over a small demo program. > > This function checks whether a guest is on the guest list or not: > > (define (guest name list) > (cond > ((empty? list) 'no) > ((equal? name (first list)) 'yes) > (else (guest name (rest list)) ))) > > I am in love with Ruby and I'm not about to switch to Scheme, so I > wanted to write this in ruby: > > def guest (name, list) > if list.empty? > :no > elseif name == list.first > :yes > else > guest(name, list.rest) No Array#rest as you noted bellow, you may use list[1..-1] here. > end > end However, why not just this: def guest(name,list) list.include?(name) ? :yes : :no end And what's wrong with boolean return values? > > Well looks nice but there's a little something missing: there's no such > method "rest" for an array! Whereas there are things like Array#first > and Array#last, this seems to have been forgotten. Of course I could > write it like this: > > def guest(name list) > if list.empty? > :no > elsif name == list.shift > :yes > else > guest(name,list) > end > end >