[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6150] Re: detect:ifNone: in Ruby

From: "Guy N. Hurst" <gnhurst@...>
Date: 2000-11-08 02:31:31 UTC
List: ruby-talk #6150
Yukihiro Matsumoto wrote:
> 
> Hi,
> 
> In message "[ruby-talk:6111] Re: detect:ifNone: in Ruby"
>     on 00/11/07, Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> writes:
> 
> |> How about default, defaults or defaulting (I like the last).
> |
> |I'd call it "nilGives" or "nil_gives", etc.  I think default leaves too
> |much open -- it depends on how your objects are made as to what their
> |defualt value is.
> 
> I agree with that `default' is too broad.  And both `nilGives' (case
> mixture; third person) and 'nil_gives (third person) are not Rubyish
> neither.
> 


Since this seems to be acting as a proxy, maybe a good name
would be:

proxy_nil

And back to Hugh's 'cut' concept, maybe that can be named:

trap_nil  or  nil_break

myarray.sort!.nil_break.uniq!.nil_break.print

(Alternatively, use proxy_nil{someObject} where someObject has
method_missing defined accordingly ;-)


Finally, I'd like to mention something that I have sometimes wished
for - referring to previously mentioned variables or cached results.
This is probably the ultimate in lazy programming, I don't know,
but how many times have you wished you could stop repeating
yourself in the following cases?

if a == "up" || a== "down" || a == "around" then .....

Why not:    if a == "up" ^or^ "down" ^or^ "around" .......

if month > 2 && month < 7 || month == 11 then .....

Why not: if month > 2 ^and^ < 7 ^or^ == 11 then .....

(abstract concept, not actually suggesting using ^ symbol)


And how often have you made a calculation and needed to refer to again
soon, only to realize you have to save it in a temporary variable
to manually cache it?

1. if (co*m/ple+x%exp-ress/ion) then (co*m/ple+x%exp-ress/ion) else yield end

   temporary variable
   x = (co*m/ple+x%exp-ress/ion);  if x then x else yield end

   can become something like
   if (co*m/ple+x%exp-ress/ion).cache_to(:x) then x else yield end

   existing alternative functional approach?
   if ( x = (co*m/ple+x%exp-ress/ion) ) then x else yield end

   existing proc approach?
   if (x = proc{(co*m/ple+x%exp-ress/ion)}).call then x.call else yield end


2. x = a.detect { |i| i == 7 } .nil? 99 : a.detect{ |i| i == 7 }

   temporary variable
   x = a.detect { |i| i == 7 }; if x.nil? then 99 else x end

   can become something like
   x = a.detect { |i| i == 7 }.cache_to(:tmp).nil? ? 99 : tmp

   existing alternative functional approach?
   x = ( tmp = a.detect { |i| i == 7 } ).nil? ? 99 : tmp

   proxy_nil could be used...
   x = a.detect { |i| i == 7 } .proxy_nil(99)
 


Guy N. Hurst


-- 
HurstLinks Web Development    http://www.hurstlinks.com/
Norfolk, VA - (757)623-9688
PHP/MySQL - Ruby/Perl - HTML/Javascript

In This Thread

Prev Next