From: Michael Neumann Date: 2003-11-20T05:14:35+09:00 Subject: Re: x.f! RCR On Thu, Nov 20, 2003 at 02:43:20AM +0900, Dan Doel wrote: > Michael Neumann wrote: > > >Your suggestion is that delete_if does not delete anything (it creates a > >new > >array), where delete_if! would. Principle of Least Surprise? Not for me! > > > > > > That depends on your background, I suppose. If I'm not mistaken, ! and > ? probably come from Scheme, I've to admit, I never really used Scheme or Lisp. > where ! is usually used to denote that it causes a side effect on the > arguments. Since Scheme advocates > functional programming, > > (delete_if predicate list) > > would return a new list with the proper elements deleted, while > > (delete_if! predicate list) > > would delete the elements in place (probably returning the list as well). > > If you're writing in a functional manner, it's not at all surprising to > expect a delete... or remove... function to > not modify the initial list (in fact it's almost a requirement if you > want to prove certain correctness > requirements for a program). In that case, the fact that there is no > #delete_if that doesn't modify the base > list would be an inconvenience. Not that Ruby's lists are exactly > suited for functional programming, but > food for thought. Thanks for the insights into Scheme. Scheme is probably much more consistent than Ruby. Ruby instead favours 'matz' POLS over consistence (but it's not that inconsistent at all :-). Regards, Michael