User talk:Maerics

Your new Ruby implementation
Hello. I just noticed your new Ruby implementation. Interesting. I'm new to Ruby (I learned it the same day I did that). So let me get this straight: 1) Array.new returns the array value, but you can attach an Array message to a block? 2) Why did you get rid of the retry and the r variable or whatever it is called? It allows the program to work like the above and not quit when an overflow is expected. For example, if you enter a number like 9.99 E 99, it would overflow. But it would then go on to the next input number. Unless I'm missing something. Once again, I'm new to Ruby (have a couple of years' experience in other languages like C), so if there's something I'm missing, let me know. - PGSONIC 00:40, 27 June 2007 (UTC)
 * Hi there! I'm new to Wikipedia so I hope this is the right way to respond... anyway, I've been hacking Ruby professionally since 2000 (and lots of other languages before and since), so I've soaked up a number of tricks.  To answer your questions:  1) Yes, the Array constructor can take a block which gets evaluated upon each elements initialization, optionally with the index as the block parameter, so   will print the numbers 0-9 as side-effect and populate each element with the integer corresponding to its index (since that is the last thing evaluated in the block and therefore the implicit return value).  2) The retry statement and r variable were unnecessary since Ruby handles numerical under/overflow by returning 0.0 or Infinity respectively (both Floats), never by raising an exception, so really, the begin/rescue block is not necessary at all; moreover the other language implementations appear to consider any value greater than 400 as overlow, so I'll modify the new implementation to be consistent with them.  Let me know what you think. Maerics 04:16, 27 June 2007 (UTC)
 * Thanks for the info. You can make your replies easier to find by adding the right number of colons before each paragraph. But what I meant by 1) is that you can chain a block like Array.new(4){gets.to_i}.reverese ? That looks a bit weird to me (could Array.new(10, {gets.to_i}).reverse work?). - PGSONIC 12:27, 27 June 2007 (UTC)
 * Ah, I see. Ruby has this notion of a "given block", which is different than a formal argument but can be converted to one by using special syntax.  So the form " " is handled in the Array constructor implementation by doing something like " " where "yield" invokes the given block with its argument.  If you want to pass the block as a formal argument you have to create a "Proc" object and then convert it to a "given block" by using the "&" operator, so the following should work like you want: " ".  The keyword "lambda" is syntactic sugar for "Proc.new"; I think it's unfortunate that Procs don't just spring into existence when you create a block, but so be it. Maerics 03:55, 28 June 2007 (UTC)