|
Re: assorted beginner questions: msg#00459lang.scala
Yang, Your questions make very good additions to the Scala FAQ. Thanks for asking them. On 1/28/07, Yang <
6gcgy2n02@xxxxxxxxxxxxxx> wrote: i've accumulated a list of questions over the past few days of using Which version did you use? mkString is in Iterable only since 2.3.2. for the following code: Lists are not iterators. You either need to turn the result of `for' into an iterator using `elements', or define `all' on Iterables. are there any form of nested comments in scala? Yes. /* ... */ comments nest. does scala have keyword arguments a la lisp/python? No. You can use anonymous classes and inheritance to work around this. David gave an example. is there any special syntax for hashtable/map/set gets/updates? General syntactic sugaring applies. You can write: m(key) = value or m += (key -> value) The two are equivalent. The first is translated to m.update(key, value). The second reduces to the same _expression_. can i define functions that aren't part of an 'object' or 'class'? Yes, as long as you execute them as a script in the interpreter shell. 'static methods'? These go into an object. Example: object HashSet { def empty[T]: Set[T] } class HashSet[T] { ... } HashSet.empty would be static in Java. In Scala, the object and the class HashSet are combined in one classfile. The object effectively contains the static parts. is there a web interface to sbaz somewhere? I think Ross Judson did a GUI interface. I am not sure whether it works over the web. what's the keyword to look for for info about varargs? what is this It's called a repeated parameter. is there a more succinct way to reduce a list, e.g. something that For methods like && you need to give a lambda abstraction, i.e. mylist reduceLeft ((x, y) => x && y) in pattern matching, can i bind to the composite structure as well as Yes, it's almost the same in Scala: blah match { case ls @ (x :: xs) => ... case List() => ... } when can/can't i omit () (for zero-param calls/defs) () in a call can be omitted for defs with () parameters. It does not work the other way round. I.e. if the def is parameterless, the call may not have a () argument. or the 'new' If the class is a case class. for the former, is it ever No and no. why is, e.g., foldLeft defined so oddly? 'explicitly curried', it seems: That's indeed the encouraged style. One reason for this is that then you need not give types for the parameters x and y (they are inferred from the previous argument). while on that page, what's the difference between {} and () in this They are exactly the same at the moment. Both mean the unit value. We are thinking of deprecating () because it looks too much like an empty parameter list (which is not the same as the unit value). what's the 'intended' way to use forall? ideally, the syntax would be: Try: case {name, Prop(typ, value)} => checkType(value, typ) }) If your closure contains a pattern, it needs to be preceded by case.
There are some frameworks for this in development. Philip Haller has a library of pickling combinators in style of what Andrew Kennedy did for Haskell. what are the some of the principal reasons for scala's (generally) Last I saw, Scala was equal to Java in the shootout. I think the shootout produces a lot of noise anyway. are there any efforts under way to provide static I would like to encourage any such effort! I think this would be really useful tools, which could be more more convenient to use, given Scala's more advanced syntactic and typing capabilities. Cheers -- Martin |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: implicit defs (Poor Man's Type Classes): 00459, Imam Tashdid ul Alam |
|---|---|
| Next by Date: | Re: implicit defs (Poor Man's Type Classes): 00459, Warren Henning |
| Previous by Thread: | Re: assorted beginner questionsi: 00459, Rafael de F. Ferreira |
| Next by Thread: | Re: assorted beginner questions: 00459, Imam Tashdid ul Alam |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |