From: Bill Kelly Date: 2001-04-23T06:24:53+09:00 Subject: [ruby-talk:14034] Re: Comments in code (was Re: From Guido, with love...) From: "Dennis Decker Jensen" > Regarding implementation language: I think I would need a lot more > "helpful comments" if I were to code in Forth or Assembler... :-) What!?? Surely nothing could be as immediately and transparently obvious as: DUP >R 2* 1+ FOR R@ I - ABS DUP * R@ 2* 1+ FOR R@ I - ABS DUP * OVER + R@ 1- DUP * R@ DUP * WITHIN IF ASCII * ELSE BL THEN EMIT NEXT CR DROP NEXT R> DROP ;-) Okay, here's my attempt at hopefully a maximally-readable ruby implementation. (But I'm a ruby novice so any improvements would be most welcome!) class Circle def Circle.draw(radius) (-radius..radius).each do |y| (-radius..radius).each do |x| if pointOnCircle? x, y, radius then print '*' else print ' ' end end print "\n" end end def Circle.pointOnCircle?(x, y, radius) Integer(dist x, y) == radius end def Circle.dist(x, y) Math.sqrt(x**2 + y**2) end end P.S. I just had a thought as to how to comment the Forth version at the level of intent: DUP >R 2* 1+ FOR R@ I - ABS DUP * R@ 2* 1+ FOR R@ I - ABS DUP * OVER + R@ 1- DUP * R@ DUP * WITHIN IF ASCII * ELSE BL THEN EMIT NEXT CR DROP NEXT R> DROP ;-) Bill