From: Diego Virasoro Date: 2006-03-23T05:33:52+09:00 Subject: Re: questions/suggestions from a Ruby newbie > How about: > variable[3][2] > > ? :-) As long as both variable and variable[3] respond to "[]", you > should be OK. (They don't even have to be arrays.) Yes, thank you. I tried something like this before sending the post but it failed. But after reading this I realised it was an error in how I wrote it. It still isn't asgood as it could be, but it is a small thing. > Also, it's not too difficult to write a multi dimensional array class. > Basically you need to make [] and []= accept multiple arguments. Note > also, that there is a Matrix class (for n=2). Oh, I really like the Matrix class. I did not know about these libraries (yes, as I said I am very much a newbie, sorry). And I like the fact it can be a matrix of any object, just like Arrays. That would make it a good candidate for a table, as well as a numerical matrix (which is what I had in mind. Unfortunatly the Matrix class seems to be very lacking so far. In particular there is no (or I could not find) any assignment such as []= and similar problems. I know I can write this but I would imagine something this basic should be part of the class already. Is there any place one can contribute with the code and have it discussed for review and inclusion in the future... or just a place to propose future improvements? > I don't think this is doable with things as they are, since Ruby's > support for range indices differs from Fortran's (IIRC - I think > var[0:10:2] = 0 would set 0,2,4,6,8,10 ?). You are right, I see what you mean. They act very differently. > That's ugly IMHO and also just syntax. "<<" is well known in other > languages (namely C++) for stream appending which is basically what it > is. Also operator "+!" might introduce problems in the syntax. Yes, I must agree it's quite ugly... well, happy to have understood the difference anyway. > That starts to tie the language in knots. For one thing, if can take > a method with a block: > if x { }; y end > > I think things would start to get much too messy, especially with an > optional "do". Well, imho that what you wrote is primarely messy because of the style: like in every language I would imagine even Ruby can be difficult to read if one does not use a good style. Still what you say is very true: in this case however my gut feeling would suggest the problem is in making "do" optional. (as I said I think consistency if very important). > I think there's also a scoping issue involved: if and while do not > introduce a new scope while blocks do: True, I did not think of that. Although personally I must say I find that inconsistent and in fact a reason why using blocks would be better: nothing I cannot get used to, of course, but... > (I know Smalltalk and maybe other languages handle > conditionals as methods, but I don't think it would mesh well with > Ruby.) Is Smalltalk so? And could someone who knows both language explain the advantages of not using conditionals as methods? Ruby seems to be usually as consistent as possible for example making everything either a class or a method, so why not use conditionals as methods too? Just curiosity. > Give it a couple of months and you'll be using it for everything from > shuffling your music to documenting C code :) :) Diego Virasoro