The Artima Developer Community
Sponsored Link

Articles Forum
First Steps to Scala

32 replies on 3 pages. Most recent reply: May 6, 2010 4:54 PM by Venki Balakrishnan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 32 replies on 3 pages [ 1 2 3 | » ]
Admin Admin

Posts: 39
Nickname: admin
Registered: Jan, 2002

First Steps to Scala Posted: May 11, 2007 9:23 PM
Reply to this message Reply
Advertisement
In this article, you'll follow twelve steps that are designed to help you understand and gain some basic skills in the Scala programming language.

http://www.artima.com/scalazine/articles/steps.html

What do you think of Scala?


Stanislas Klimoff

Posts: 6
Nickname: graven
Registered: May, 2007

Re: First Steps to Scala Posted: May 12, 2007 3:05 AM
Reply to this message Reply
Personnaly, I like Scala, it looks like a very cute development effort. But I have to admit that hybrid languages aren't likely to have any future — they lack lazyness that is vital to the success of functional language.

Morel Xavier

Posts: 73
Nickname: masklinn
Registered: Sep, 2005

Re: First Steps to Scala Posted: May 12, 2007 12:12 PM
Reply to this message Reply
> Personnaly, I like Scala, it looks like a very cute
> development effort. But I have to admit that hybrid
> languages aren't likely to have any future — they lack
> lazyness that is vital to the success of functional
> language.

I fail to see how lazyness (as a core semantic of the language) is "vital" to functional language. Only one lazy functional language is even remotely widespread (Haskell, Miranda is also lazy but one can't say it's "widespread"), the vast majority of functional languages follow a strict evaluation model (pretty much every Lisp dialects, pretty much every ML dialects and derivatives including SML and OCaml, Erlang, ...) with the potential ability to include local lazyness (Scheme, D, Nemerle).

Not to mention that lazy evaluation still has huge execution-time and memory behaviour issues (which lead to the introduction of strict-evaluation operators and variants in Haskell for optimization purposes...)

Isaac Gouy

Posts: 527
Nickname: igouy
Registered: Jul, 2003

Re: First Steps to Scala Posted: May 13, 2007 6:05 PM
Reply to this message Reply
Morel Xavier wrote
> Only one lazy functional language is even remotely
> widespread (Haskell, Miranda is also lazy but one can't
> say it's "widespread") ...

Clean also.

http://clean.cs.ru.nl/About_Clean/Clean_Language_Features/clean_language_features.html

Tomi Maila

Posts: 1
Nickname: tmaila
Registered: May, 2007

Re: First Steps to Scala Posted: May 14, 2007 1:51 AM
Reply to this message Reply
Nice article guys! It's really nice to see Scala being introduced in this extent here at artima! Keep up with the good work.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: First Steps to Scala Posted: May 14, 2007 6:08 AM
Reply to this message Reply
This is really a great intro. I wish I had this when I was first trying to figure things out (not that I've figured it all out.)

Keep up the good work and thanks.

Daniel Jimenez

Posts: 40
Nickname: djimenez
Registered: Dec, 2004

Re: First Steps to Scala Posted: May 14, 2007 7:37 AM
Reply to this message Reply
Great introductory article.

A question about the map examples. What is it about method -> that is better than just defining the tuple? I mean, why is (1 -> "value") better than (1, "value")?

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: First Steps to Scala Posted: May 14, 2007 9:52 AM
Reply to this message Reply
> Great introductory article.
>
> A question about the map examples. What is it about method
> -> that is better than just defining the
> tuple? I mean, why is (1 -> "value") better
> than (1, "value")?

Good question. The only thing I can think of is that you could perhaps override the -> method, if that's allowed. Not sure that would be a good thing, though.

Mark Engelberg

Posts: 3
Nickname: puzzler
Registered: Jun, 2006

Re: First Steps to Scala Posted: May 14, 2007 8:48 PM
Reply to this message Reply
Good, lucid introduction overall. I still don't understand the order in which Scala calls the various overridden methods it inherits from its traits and superclass. I can't extrapolate from the exclamatorygreeter mixin example to understand how the chain would be resolved in general. Care to elucidate?

Andrew O'Malley

Posts: 1
Nickname: andrewom
Registered: May, 2007

Re: First Steps to Scala Posted: May 15, 2007 12:19 AM
Reply to this message Reply
One advantage of the -> method is that brackets are not required (unlike the example in the article). This makes the syntax a lot more readable: e.g.

val romanNumeral = Map(1 -> "I", 2 -> "II", 3 -> "III", 4 -> "IV", 5 -> "V")

versus

val romanNumeral = Map((1, "I"), (2, "II"), (3, "III"), (4, "IV"), (5, "V"))

Ravi Mohan

Posts: 11
Nickname: ravim
Registered: Jan, 2003

Re: First Steps to Scala Posted: May 15, 2007 6:49 AM
Reply to this message Reply
I find I need to say Console.println("Hello") vs println("hello") as described in the article.

scala> println("j")
<console>:4: error: not found: value println
val line3 = println("j")



What am I doing wrong?

Ravi Mohan

Posts: 11
Nickname: ravim
Registered: Jan, 2003

Re: First Steps to Scala Posted: May 15, 2007 7:13 AM
Reply to this message Reply
Urgh it seems I had the wrong version. Scala 2.5RC doe sindeed have the "println" construct.

It would be nice if the scala interpreter could output the version number.

something like ...

$python
Python 2.5.1c1 (release25-maint, Apr 12 2007, 21:00:25)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

Lex Spoon

Posts: 6
Nickname: lexspoon
Registered: Oct, 2006

Re: First Steps to Scala Posted: May 16, 2007 12:58 AM
Reply to this message Reply
All the Scala tools accept -version. Since you usually should not care about the version so much, I am going to leave out the Pythonic display of the version at every invocation.

$scala -version
Scala code runner version 2.5.0 -- (c) 2002-2007 LAMP/EPFL

Lex Spoon

Posts: 6
Nickname: lexspoon
Registered: Oct, 2006

Re: First Steps to Scala Posted: May 16, 2007 1:02 AM
Reply to this message Reply
Anyway, doesn't the -> version look nicer? Identifiers are not in short supply, so I don't see why there should be any effort to conserve them, unless....

Ahh, maybe it appears to Artima readers to be a special case in the syntax. It is not. -> is just an operator, which in Scala can be used as a method name.

Lex Spoon

Posts: 6
Nickname: lexspoon
Registered: Oct, 2006

Re: First Steps to Scala Posted: May 16, 2007 1:16 AM
Reply to this message Reply
The details are in the spec.

http://www.scala-lang.org/docu/files/ScalaReference.pdf

By the way, this spec is readable as specs go. There is a ton of detail, but it is meant to be readable, not to be leverage for lawyers.

Anyway, the rule is that inherited classes and mixed in traits get linearized. Message sends invoke the first class/trait in the linearization that has a matching method, and super calls work their way up through the linearization. The precise linearization algorithm is in the spec, but it is an intuitive one IMHO.

Note that with this rule, you can evaluate all of the methods by simply chaining "super" calls. If the first method invokes "super", and so do all the others except for the last, then you will end up invoking each method one time. This pattern is practically impossible with multiple inheritance, and is awkward with the original traits from U. Berne.

Flat View: This topic has 32 replies on 3 pages [ 1  2  3 | » ]
Topic: Developer Productivity in Flash Builder 4 Previous Topic   Next Topic Topic: Never Call Virtual Functions during Construction or Destruction

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use