[JOIN] Range syntax & Solitare cypher

M

Markus

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
 
G

gabriele renzi

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)
 
Z

Zach Dennis

Markus said:
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
 
M

markus

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
 
M

markus

Oops. Should be "values_at" in both cases. "values" is a site-local
synonym.

-- MarkusQ
 
K

Kristof Bastiaensen

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
 
M

Markus

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,416
Latest member
LionelQ387

Latest Threads

Top