From: Carsten Eckelmann Date: 2004-01-13T09:18:54+09:00 Subject: Re: Getting the tail of a list? Gennady wrote: > 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. OKAY! That's a bit shorter, thanks. > > However, why not just this: > > def guest(name,list) > list.include?(name) ? :yes : :no > end > > And what's wrong with boolean return values? Yes of course that's the way to do it in ruby. My example was a bit of an academic exercise used to demonstrate recursive processing of lists to beginning students. And there's nothing wrong with booleans, I just wanted to model the ruby code as close as possible to the scheme code. Cheers, Carsten.