Since I only got back from vacation, I’m replying to this thread
late. To avoid clutter, I’m replying to 5 messages all in this
one email. Skip what you want:
a.each {|x| p x } # ← this line
How do you read the “this line” line?
I read it like it were Ruby code:
for x in a; p x; end
If I had to read it out loud over the phone, I might read:
for each x in a, p x.
When I read your code, before I got to the ‘How do you read the
“this line” line?’ I definitely (in my head) read the code as:
on each x from a, p x.
However, that’s because when I see .each, I skip over to the
block and look at it. If the block weren’t a one-liner, I
would read it as:
on each element from a,
using |...|
do {...}
Sorry, typo:
for each x in a do p(x)
that has the same meaning but might be confused with the actual use of
the for statement.
Remove the “each” and “do” and add some semicolons and an “end” and
it is an actual use of the “for” statement.
I would call Albert’s version a “verbose, human-readable version”
of the use of the “for” statement.
yes, it was a merely syntactic (phonetic?) question; what
does the line sound like.
What is the sound of one line of code clapping?
I am reminded of the question, “If Helen Keller
fell over in the forest, would she make a sound?”
Damn, you beat me to it.
For my part, a.each {|x| p x} sounds something like:
Given a, for each x in it, do p(x)
“Do p() using x to each element in a.”
This is what happens when you’re Japanese and learn to read
from right-to-left. My guess is this is how a native Japanese
reader would read the line of Ruby code and IMHO it’s quite
intuitive.
···
On 2002.07.26, Michael Campbell michael_s_campbell@yahoo.com wrote:
On 2002.07.26, Tom Sawyer transami@transami.net wrote:
On Thu, 2002-07-25 at 17:41, Albert Wagner wrote:
On 2002.07.26, Michael Campbell michael_s_campbell@yahoo.com wrote:
On 2002.07.31, Hal E. Fulton hal9000@hypermetrics.com wrote:
On 2002.07.26, yct yuchingtien@yahoo.com wrote:
a for each of your x do this…
“All your ‘x’ are belong to ‘a’.”
Sorry, couldn’t resist.
– Dossy
–
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)