[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[JOIN] Range syntax & Solitare cypher

Markus

10/1/2004 8:09:00 PM

Here's a simple example of where ... is very nice to have. You want to
cut a deck and card x, so that x is on the top after the cut:

deck = deck.values(x..-1,0...x)

*grin* Try doing that as concisely without "..."

-- MarkusQ




6 Answers

gabriele renzi

10/1/2004 8:20:00 PM

0

Markus ha scritto:

> Here's a simple example of where ... is very nice to have. You want to
> cut a deck and card x, so that x is on the top after the cut:
>
> deck = deck.values(x..-1,0...x)
>
> *grin* Try doing that as concisely without "..."
>

with my syntax:
x..,0..x-1

one key less ;)
(though now I see a reason for excluding ranges)

Zach Dennis

10/1/2004 8:22:00 PM

0

Markus wrote:

>Here's a simple example of where ... is very nice to have. You want to
>cut a deck and card x, so that x is on the top after the cut:
>
>deck = deck.values(x..-1,0...x)
>
>*grin* Try doing that as concisely without "..."
>
>-- MarkusQ
>
>
deck = deck.values(x..-1,0..x-1)

Zach


Markus

10/1/2004 10:51:00 PM

0

Markus

10/1/2004 11:02:00 PM

0

Kristof Bastiaensen

10/2/2004 11:05:00 AM

0

On Sat, 02 Oct 2004 07:51:03 +0900, markus wrote:

> On Sat, 2 Oct 2004, Zach Dennis wrote:
>
>> Markus wrote:
>>
>> >Here's a simple example of where ... is very nice to have. You want to
>> >cut a deck and card x, so that x is on the top after the cut:
>> >
>> >deck = deck.values(x..-1,0...x)
>> >
>> >*grin* Try doing that as concisely without "..."
>> >
>> >-- MarkusQ
>> >
>> >
>> deck = deck.values(x..-1,0..x-1)
>>
>>
> Nope. Sorry. Try it with:
>
> deck = (1..52).to_a
> x = deck.index(1)
>
> (or just a deck from 1..10 if you prefer) and then try again.
>
> -- MarkusQ
>
> P.S. I repeat, a...b is NOT a synonym for a..b-1

Exactly.

(3..5-1).include? 4.4 #=> false
(3...5).include? 4.4 #=> true

KB


Markus

10/2/2004 3:12:00 PM

0

On Sat, 2004-10-02 at 04:05, Kristof Bastiaensen wrote:
> On Sat, 02 Oct 2004 07:51:03 +0900, markus wrote:
>
> > On Sat, 2 Oct 2004, Zach Dennis wrote:
> >
> >> Markus wrote:
> >>
> >> >Here's a simple example of where ... is very nice to have. You want to
> >> >cut a deck and card x, so that x is on the top after the cut:
> >> >
> >> >deck = deck.values_at(x..-1,0...x)
> >> >
> >> >*grin* Try doing that as concisely without "..."
> >> >
> >> >-- MarkusQ
> >> >
> >> >
> >> deck = deck.values_at(x..-1,0..x-1)
> >>
> >>
> > Nope. Sorry. Try it with:
> >
> > deck = (1..52).to_a
> > x = deck.index(1)
> >
> > (or just a deck from 1..10 if you prefer) and then try again.
> >
> > -- MarkusQ
> >
> > P.S. I repeat, a...b is NOT a synonym for a..b-1
>
> Exactly.
>
> (3..5-1).include? 4.4 #=> false
> (3...5).include? 4.4 #=> true

Agreed. But that's not the only difference. The idiom above
relies on another difference to function properly. I'm surprised no one
has jumped on it yet. (Especially after all the talk about "..." not
being useful. *evil grin* You'd think one of them could show me how
unneeded it is in this context).

-- MarkusQ