scalapuzzlers / scalapuzzlers.github.com

Github Pages behind scalapuzzlers.com
www.scalapuzzlers.com
161 stars 53 forks source link

Failwhale (puzzlr-012) #18

Closed lazyval closed 12 years ago

lazyval commented 12 years ago

I've added puzzler related to lazy value computation in case we get an exception during the first time we call this val. Hope you'll like it. Not sure I've written explanation in a clean English, since it is not my first and native language, correct me, please, if you've noted something bad (or even awful) with spelling.

demobox commented 12 years ago

Sorry for the review delay (also for https://github.com/scalapuzzlers/scalapuzzlers.github.com/pull/17)! Been a crazy couple of weeks ;-)

I'll try to get round to this in the coming days...

demobox commented 12 years ago

Nice! I would only suggest a couple of small things:

Prints nothing Prints <lazy> since the value will not be evaluated Prints an empty line Prints 1

lazyval commented 12 years ago

@demobox

demobox commented 12 years ago

Good with me....@nermin ?

demobox commented 12 years ago

@nermin suggests the following answers (in any order):

based on the fact that these are more likely to be encountered in the REPL than "print nothing" or "prints an empty line". What do you think?

lazyval commented 12 years ago

Sorry about such long delay, I've been really busy for the past few days.

@demobox I like your answers, except the first one. Divide by zero will be thrown in any case (but then will be caught by catch block) , that's how the code is written. I think that you possibly mean unhandled exception, so we need to specify that little detail in order to not confuse the reader.

@nermin I've assumed that the one will likely will solve puzzler doing some crunching in REPL, that is why I've proposed <<lazy>> as one of the possible answers.

nermin commented 12 years ago

@om-nom-nom I understand now the rationale behind , and I like that as a possible answer. Hence, i would include it. Regarding the divide-by-zero exception, I was thinking it would be thrown as a result of a second println(y), within the catch block (since y is a val, increment x might not affect it).

Thoughts?

demobox commented 12 years ago

@nermin "I understand now the rationale behind , and"...did Markdown swallow something between "behind" and "," there..? ;-)

nermin commented 12 years ago

Ah, yes, I wanted to say rationale behind <lazy>

lazyval commented 12 years ago

@nermin How about this?

nermin commented 12 years ago

@om-nom-nom Those seem to me as best 4 options for this puzzler.

demobox commented 12 years ago

See http://scalapuzzlers.com/#pzzlr-012 ;-)

lazyval commented 12 years ago

@demobox whoa, thanks a lot