|
View:
New views
14 Messages
—
Rating Filter:
Alert me
|
|
|
Scala Puzzlers?Would there be any interest in creating a collection of Scala Puzzlers
- similar in concept to Josh and Neal's Java Puzzlers book? There already appear to be a scattering of examples in various blog posts (cf. http://www.google.com/search?hl=en&q=scala+puzzlers), but I feel it would be useful (and fun!) to sort, generalise and discuss them. As well as being a good reference for more advanced or esoteric topics, where quirks are not uncommon. Perhaps it could even become a useful source of comment and debate for language improvements..? Regards Andrew Phillips |
|
|
Re: Scala Puzzlers?+1
Bring em on!
On Thu, Sep 10, 2009 at 1:09 PM, Andrew Phillips <demobox1@...> wrote: Would there be any interest in creating a collection of Scala Puzzlers |
|
|
Re: Scala Puzzlers?On Thu, Sep 10, 2009 at 12:09:34PM +0000, Andrew Phillips wrote:
> Would there be any interest in creating a collection of Scala Puzzlers > - similar in concept to Josh and Neal's Java Puzzlers book? They don't make enough paper. I have been meaning to organize my own little collection. Here are a couple. 1) Why does this compile, and what does it print if you run it? object nutty { def main(args: Array[String]): Unit = { val x = "one" // \u000a + "two" /* println(x) val y = x // */ val y = x * 2 println(y) } } 2) Here is the second line from a repl session. What was the first? (Multiple possible answers, shortest wins.) scala> b b b b b b b b b b res0: b.type = b -- Paul Phillips | A national political campaign is better than the Moral Alien | best circus ever heard of, with a mass baptism and Empiricist | a couple of hangings thrown in. i pull his palp! | -- H. L. Mencken |
|
|
Re: Scala Puzzlers?> They don't make enough paper.
Most likely - not yet, certainly. Hence the idea of collecting them in a wiki-like environment until we have enough to pulp a few more trees. I guess you're not the only one with his own little collection of quirks and oddities, and if we can bring them all together who knows how many will turn up? The key thing would be of course be to try to make this "the" place to have your particular puzzler published - if we use scalapuzzlers.com (I could try to get a basic wiki set up there soon) at least we'd have a fairly memorable domain... ap PS: Still working on the second one. Feeling a bit guilty, I'm supposed to be working ;-)) |
|
|
Re: Scala Puzzlers?Just wait :-) With implicits and all the other Scala goodness, it has the potential for many more puzzlers than Java. |
|
|
Re: Scala Puzzlers?
scala> case object b { def apply(x: this.type) = x; val b = this } - Colin |
|
|
Re: Scala Puzzlers?The first one is pretty obvious, though it does annoy me.
Actually, the following code is pretty common Scala code, and yet it relies on a little known feature, and it is certainly a puzzler if people stop to think about it:
List(1,2) match {
case 1 :: 2 :: Nil => println("Yep")
case _ => println("Nope")
}
Why does "::" work in that context? How do you replicate such behavior with a class of your own? On Thu, Sep 10, 2009 at 10:15 AM, Paul Phillips <paulp@...> wrote:
-- Daniel C. Sobral Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value. |
|
|
Re: Scala Puzzlers?On Thu, Sep 10, 2009 at 4:03 PM, Daniel Sobral <dcsobral@...> wrote:
You'd then have to cross-reference several chapters on extractors, sounds fun! :) |
|
|
Re: Scala Puzzlers?
you can still strip some whitespace and "type safety":
just my 44 characters, adriaan
|
|
|
Re: Scala Puzzlers?Sounds wicked cool!!
On Thu, Sep 10, 2009 at 5:09 AM, Andrew Phillips <demobox1@...> wrote: Would there be any interest in creating a collection of Scala Puzzlers -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp |
|
|
Re: Scala Puzzlers?On Thu, Sep 10, 2009 at 10:08 AM, Kevin Wright <kev.lee.wright@...> wrote:
I wondered how this worked, too, so we describe it in "Programming Scala", http://programming-scala.labs.oreilly.com/ch06.html#CaseClasses. Search for "Syntactic Sugar for Binary Operations". -- Dean Wampler coauthor of "Programming Scala" (O'Reilly) - http://programmingscala.com twitter: @deanwampler, @chicagoscala Chicago-Area Scala Enthusiasts (CASE): - http://groups.google.com/group/chicagoscala |
|
|
Re: Scala Puzzlers?There, you just gave me a reason to upvote your book. :-)
On Thu, Sep 10, 2009 at 12:59 PM, Dean Wampler <deanwampler@...> wrote:
-- Daniel C. Sobral Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value. |
|
|
Re: Scala Puzzlers?scala> class Test scala>new Test().isInstanceOf[AnyVal]
res:9: Boolean = true. Why is it true? Can you think of other consequences resulting from the same root cause?
On Thu, Sep 10, 2009 at 9:09 AM, Andrew Phillips <demobox1@...> wrote: Would there be any interest in creating a collection of Scala Puzzlers -- Daniel C. Sobral Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value. |
|
|
Re: Scala Puzzlers?On Fri, Sep 11, 2009 at 3:43 PM, Daniel Sobral <dcsobral@...> wrote:
> scala> class Test > defined class Test > > scala>new Test().isInstanceOf[AnyVal] > res:9: Boolean = true. > > Why is it true? Can you think of other consequences resulting from the same > root cause? > That's going to be a short-lived puzzle. AnyVal will be disallowed as an argument for isInstanceOf tests from Scala 2.8. -- Martin |
| Free embeddable forum powered by Nabble | Forum Help |