[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:03853] Re: Array.uniq! returning nil

From: matz@... (Yukihiro Matsumoto)
Date: 2000-07-06 02:48:34 UTC
List: ruby-talk #3853
Hi,

In message "[ruby-talk:03845] Re: Array.uniq! returning nil"
    on 00/07/05, Aleksi Niemel<aleksi.niemela@cinnober.com> writes:

|But wait a second? Don't we feed if/unless with predicates like true, false,
|nil? Then we must have a mistake here. *reading docs* No there's no mistake,
|uniq! can be used as a "predicate" because it returns nil or the (now
|modified) array which evaluates to non-nil, thus true.
|
|So array.uniq! *is already* a "predicate" with a side effect.

"Conditions" may have side effect.  Have you ever seen a code like
following?

   while line = gets()
     ...
   end

"line = gets()" is a condition for while statement, and this is an
assignment, which is surely with a side effect.  But I don't call
these conditions with side effect as predicates.

|Now, to remove '"' from my last sentence we could define predicate to match 
|  /[\w_!]+\?/
|
|Then we can mark our predicate capable to cause a side effect. When you see
|array.uniq!? you know it modifies in place and acts as a predicate.

Besides the "predicate" definition problem above,  `foo!?' is ugly.
Well, at least for my taste.

							matz.

In This Thread

Prev Next