At 12:03 12/06/2004 +0900, you wrote: >"Alexander Kellett" <ruby-lists / lypanov.net> wrote in message news:20040611112816.GA2067 / loki... >| first / rest is symmetric... >| head / tail unix commands don't default to 1 "line" >| car + cdr have crappy names. >| i'm sure there is something better for this :) > >Could be take / drop (with optional argument, number of items): > >[1,2,3,4].take --> 1 >[1,2,3,4].take(1) --> 1 # or can be [1] >[1,2,3,4].take(2) --> [1,2] >[1,2,3,4].drop --> [2,3,4] >[1,2,3,4].drop(2) --> [3,4] >[1,2,3,4].take(-3) --> [2,3,4] >[1,2,3,4].drop(-1) --> [1,2,3] > >And in some language there was a pair 'first / butfirst'. >Georgy Pruss That is what I ended up in some language I designed. I was not perfectly happy with the result, but that was the best I found. Was more like but_first() however (well... it actually was butFirst(), Smalltalk camelCase). It worked on strings, lists and arrays and was the main style for iterating: while item = a_list.first() a_list = a_list.but_first() xxx end I for sure prefer Ruby's for item in a_list do xxx end or even more Rubyish (or Smalltalkish) I guess: a_list.each do |item| xxx end It was efficient because I had implemented copy-on-write optimization and but_first() was just a pointer increment. Yours, JeanHuguesRobert >E#Mail: 'naabbcaDaddaLryDwksvKmyw'.tr('a-zA-Z','0-9a-z.@') ------------------------------------------------------------------------- Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17