On Thu, 18 Jan 2001, hipster wrote:

> On Thu, 18 Jan 2001  00:13:23 +0900, Hugh Sasse Staff Elec Eng wrote:
> > What is the idiomatic Ruby way to go through all the elements of an array,
> > except the last one, gettting the index?
> 
> exactly where Haskell list-lingo (head, tail, init, last) comes in
> handy. On Array

Yes, these are useful -- I think Lisp and Prolog have some of these
as well.  It would be nice to have these built in to Array -- probably
done in C for performance.
> 
> ,----
> | def init
> | 	self[0..-2]
> | end
> `----
> 
> and you can say
> 
> ,----
> | my_array.init.each_index{ |i|
> | 	...
> | }
> `----
> 
> and of course you could directly write
> 
> ,----
> | my_array[0..-2].each_index{ |i|
> | 	...
> | }
> `----

I think I will use this one. Thank you.  And thank you to the others as
well.
> 
> which seems less intuitive. (But is a direct answer to your Q)
> 
> See http://www.xs4all.nl/~hipster/lib/ruby/haskell for more Haskell
> list-ops (it's incomplete though, if I only had the time ;). Notice
> how e.g. foldl1, scanl1, split_at, take_while and drop_while build

I have not used Haskell at all, so I'm not familiar with most of these.

> nicely from earlier defined primitives as take, drop, tail and init.
> 
> 	Michel
> 

	Thank you,
	Hugh