[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

nested arrays

Darius Kvitnickas

2/22/2006 5:47:00 PM

Hi,

I'm new to this gem called ruby, but having difficulties generating nested
arrays. Why is: var = Array.new(p, Array.new(q, 0)) not the same as:
var = Array.new(p) {Array.new(q, 0)} ?? (I know the later one works, but it
took me ages for figuring this out :D)

Thnx for your answer.. Mathias


18 Answers

Robert Klemme

2/22/2006 5:55:00 PM

0

Mathias <nospam@xxx.com> wrote:
> Hi,
>
> I'm new to this gem called ruby, but having difficulties generating
> nested arrays. Why is: var = Array.new(p, Array.new(q, 0)) not the
> same as:
> var = Array.new(p) {Array.new(q, 0)} ?? (I know the later one works,
> but it took me ages for figuring this out :D)
>
> Thnx for your answer.. Mathias

Because in the first case you provide just a single object that is used for
initialization while the second case you provide a code block that is
executed once for each array element to initialize. Does that help?

Kind regards

robert

Darius Kvitnickas

2/22/2006 6:42:00 PM

0

Hi Robert,

>> nested arrays. Why is: var = Array.new(p, Array.new(q, 0)) not the
>> same as:
>> var = Array.new(p) {Array.new(q, 0)} ?? (I know the later one works,
>> but it took me ages for figuring this out :D)
>>
>> Thnx for your answer.. Mathias
>
> Because in the first case you provide just a single object that is used
> for initialization while the second case you provide a code block that is
> executed once for each array element to initialize. Does that help?

Yepp, and "language reference" says:
Array.new(size, obj) means [... is created with size copies of obj (that is,
size references to the same obj)..] I possible read the _same_ over and
over again ;).


thanks for fast reply, Mathias

Uncle Dave

5/7/2010 4:21:00 PM

0

On May 7, 5:18 pm, Blue <b...@there.com> wrote:
> White Spirit wrote:
> > On 07/05/2010 16:22, don diddi wrote:
>
> >> So Cam the Sham is so desperate for gov't that he is talking to those
> >> socialist fake lib dem
>
> >> Must be a big disappointment to abeliar for his hero to let him down so
> >> soon after the election
>
> > Knock knock.
>
> >   Who's there?
>
> > David.
>
> >   David who?
>
> > Gordon, open up the bloody door and get the fuck out of my house.
>
> G I won't go
> C go
> G I won't go
> C go
> G I won't go...

FUCK OFF UNCLE DAVE

My two cents

5/7/2010 4:22:00 PM

0

On 7 May, 17:18, Blue <b...@there.com> wrote:
> White Spirit wrote:
> > On 07/05/2010 16:22, don diddi wrote:
>
> >> So Cam the Sham is so desperate for gov't that he is talking to those
> >> socialist fake lib dem
>
> >> Must be a big disappointment to abeliar for his hero to let him down so
> >> soon after the election
>
> > Knock knock.
>
> >   Who's there?
>
> > David.
>
> >   David who?
>
> > Gordon, open up the bloody door and get the fuck out of my house.
>
> G I won't go
> C go
> G I won't go
> C go
> G I won't go...

If Cameron can secure the support of the LibDems Brown will go.
Cameron does not have the automatic right to become Prime Minister.
Parliament is hung.

White Spirit

5/7/2010 4:23:00 PM

0

On 07/05/2010 17:20, Uncle Dave wrote:

> FUCK OFF UNCLE DAVE

I second that motion.


Uncle Dave

5/7/2010 4:32:00 PM

0

On May 7, 5:22 pm, White Spirit <wspi...@homechoice.co.uk> wrote:
> On 07/05/2010 17:20, Uncle Dave wrote:
>
> > FUCK OFF UNCLE DAVE
>
> I second that motion.

So do I. I had planned to actually but it's getting interesting...

FOUD

White Spirit

5/7/2010 4:35:00 PM

0

On 07/05/2010 17:32, Uncle Dave wrote:

> On May 7, 5:22 pm, White Spirit<wspi...@homechoice.co.uk> wrote:

>> On 07/05/2010 17:20, Uncle Dave wrote:

>>> FUCK OFF UNCLE DAVE

>> I second that motion.

> So do I. I had planned to actually but it's getting interesting...

Well, now it's been seconded it has to be put to the chair I'm afraid.



Uncle Dave

5/7/2010 4:50:00 PM

0

On May 7, 5:34 pm, White Spirit <wspi...@homechoice.co.uk> wrote:
> On 07/05/2010 17:32, Uncle Dave wrote:
>
> > On May 7, 5:22 pm, White Spirit<wspi...@homechoice.co.uk>  wrote:
> >> On 07/05/2010 17:20, Uncle Dave wrote:
> >>> FUCK OFF UNCLE DAVE
> >> I second that motion.
> > So do I.  I had planned to actually but it's getting interesting...
>
> Well, now it's been seconded it has to be put to the chair I'm afraid.

Why are you afraid of chairs? Is it a deep-seated fear?

I'm feeling quite perky today as I got the first step to what I wanted
with a hung parliament. Given that Labour are waiting in the wings
should the Conservatives courtship fail, I think Cleggy can be quite
firm about demanding at the very least a referendum on PR and not the
sort of wishy washy silliness proposed by Dave's PR machine to catch a
few extra votes. Pundits and public alike are talking about a Labour-
Lib Dem alliance as almost criminal, but this is politics, and the Lib
Dems might not get this chance again. They would be quite within
their rights to go to Labour if the Tory thing fails, though I think
Brown going would be a pre-requisite for that. Their very future as a
credible force in UK politics depends on taking this chance, otherwise
they will go on getting a sizeable proportion of the vote but few
seats compared to the other two and may even gradually wither away if
the others continue to steal their policies. So, sod it, go for it I
say and worry about the consequences afterwards.

FOUD

White Spirit

5/7/2010 4:59:00 PM

0

On 07/05/2010 17:49, Uncle Dave wrote:

> Why are you afraid of chairs? Is it a deep-seated fear?

I think it arose when I was cushioned too much during my formative
years, which made standing up for myself rather difficult.

> I'm feeling quite perky today as I got the first step to what I wanted
> with a hung parliament. Given that Labour are waiting in the wings
> should the Conservatives courtship fail, I think Cleggy can be quite
> firm about demanding at the very least a referendum on PR and not the
> sort of wishy washy silliness proposed by Dave's PR machine to catch a
> few extra votes. Pundits and public alike are talking about a Labour-
> Lib Dem alliance as almost criminal, but this is politics, and the Lib
> Dems might not get this chance again. They would be quite within
> their rights to go to Labour if the Tory thing fails, though I think
> Brown going would be a pre-requisite for that. Their very future as a
> credible force in UK politics depends on taking this chance, otherwise
> they will go on getting a sizeable proportion of the vote but few
> seats compared to the other two and may even gradually wither away if
> the others continue to steal their policies. So, sod it, go for it I
> say and worry about the consequences afterwards.

I'm more concerned about the economy, and I believe that the Tories are
the best party to being recovery.

Uncle Dave

5/7/2010 5:04:00 PM

0

On May 7, 5:59 pm, White Spirit <wspi...@homechoice.co.uk> wrote:
> On 07/05/2010 17:49, Uncle Dave wrote:
>
> > Why are you afraid of chairs?  Is it a deep-seated fear?
>
> I think it arose when I was cushioned too much during my formative
> years, which made standing up for myself rather difficult.
>
> > I'm feeling quite perky today as I got the first step to what I wanted
> > with a hung parliament.  Given that Labour are waiting in the wings
> > should the Conservatives courtship fail, I think Cleggy can be quite
> > firm about demanding at the very least a referendum on PR and not the
> > sort of wishy washy silliness proposed by Dave's PR machine to catch a
> > few extra votes.  Pundits and public alike are talking about a Labour-
> > Lib Dem alliance as almost criminal, but this is politics, and the Lib
> > Dems might not get this chance again.  They would be quite within
> > their rights to go to Labour if the Tory thing fails, though I think
> > Brown going would be a pre-requisite for that.  Their very future as a
> > credible force in UK politics depends on taking this chance, otherwise
> > they will go on getting a sizeable proportion of the vote but few
> > seats compared to the other two and may even gradually wither away if
> > the others continue to steal their policies.  So, sod it, go for it I
> > say and worry about the consequences afterwards.
>
> I'm more concerned about the economy, and I believe that the Tories are
> the best party to being recovery.

From your postings, I'd guess you're no spring chicken and so you will
know that the economy eventually revives. It's the nature of
recessions to be deeper than the last because of such things as
improved communications speeding eveything up - nobody gets to throw
the switch in time nowadays. We will come through. It will take
time, at least this one is less down to the politicians so much as
market forces so hopefully they will work together on that rather than
bickering about how killed who's father.

FOUD