On Fri, Sep 21, 2001 at 06:17:08AM -0700, Dave Cross wrote:
> From: Jonathan McKeown <[EMAIL PROTECTED]>
> Date: 9/21/01 1:27:03 PM
> > I'm still intrigued to know what your middle stage was 
> > (wrong answer for rightish reason).
> To clarify, the sequence I had in mind went something like this:
> 1/ <runs code> Hmmm... why is $x set to 1. Oh, I know. That's
> a comma operator, it returns the left-hand operand in scalar
> context. It must do. That's the only possible explanation.

OK. I didn't quite go through this step, because I was thinking, ',' returns
the rhs. That bit I got, so I said (before running it) it returns "2", I'm
appallingly bad with operator precedence of anything outside of + - * /, and
I probably only remember that because I had it drilled into me at a very
early stage... :-)

> 2/ <reads docs> Hmmm... but the docs say it returns the _right-hand_
> operator. So that must mean that $i is set to 2. I must have
> run the code wrong or something. <reruns code>... bugger... still
> 1.

I ran the code at this point and realised that it must have been the
assignment binding more tightly than the ','.

> 3/ <lightbulb!> <reads precendence table in docs> Aha!

:-) I should have read the docs, but didn't.

> There is, of course, as Robin pointed out, also the possibility
> that at about stage 2 much time is wasted assuming that 2 is
> the number of elements in the list instead of the last element.

I realised this wasn't the case, because that would require parentheses.

Oh well, how well would I have done in the interview? :-)

MBM

-- 
Matthew Byng-Maddick         <[EMAIL PROTECTED]>           http://colondot.net/

Reply via email to