logo       

Re: assorted beginner questions: msg#00454

lang.scala

Subject: Re: assorted beginner questions

Hi Yang.
I'll try to answer what I can...

On 1/27/07, Yang <6gcgy2n02@xxxxxxxxxxxxxx> wrote:
i've accumulated a list of questions over the past few days of usin
scala. i always first try google then irc (i guess i scared everyone
away), but apologies if i've missed something obvious. they're mostly
superficial/easy to answer questions, hopefully... :) (perhaps less so
toward the end)
i get "value mkString is not a member of
scala.collection.mutable.Set[Obj]" but according to the API,
scala.Iterable defines mkString. how can i use this and other Iterable
methods (forall, etc.) on things like Sets?

scala> val aSet = Set("a", "b", "c", "a")
aSet: scala.collection.immutable.Set[java.lang.String] = Set(a, b, c)

scala> aSet.mkString("[", "|", "]")
line33: java.lang.String = [a|b|c]

for the following code:
def all(xs: Iterator[Boolean]) = xs forall (x => x) // forall (xs) (x => x)
all(for (val b <- List(true,false)) yield !b)
i get:
Main.scala:29: error: no type parameters for method map:
((scala.Boolean) => b)scala.List[b] exist so that it can be applied to
arguments ((scala.Boolean) => scala.Boolean)
--- because ---
result type scala.List[b] is incompatible with expected type
scala.Iterator [scala.Boolean]
all(for (val b <- List(true,false)) yield !b)

all((for (val b <- List(true,false)) yield !b).elements) //this works

This for comprehension yields a List[Boolean] because that is the
declared return type of the List.map method:
def map [b] (f: (a) => b) : scala.List[ b]

are there any form of nested comments in scala?

I think so:

object X {
/* outer
/* inner
*/
*/
}

Compiles normally (as opposed to similar construct in a .java source).

is there any special syntax for hashtable/map/set gets/updates?

No language syntax, but there is simple and terse library support:
http://www.scala-lang.org/downloads/library.html


what's the keyword to look for for info about varargs? what is this
called in scala? (def xxx(y: int*) = ...) can defs be overloaded?

They are called repeated parameters, butI don't know about overloading, sorry.

i read on the list archives that there are efforts to revamp the
eclipse plug-in. what's the timeline and expected features for this
(and/or any other ide's for scala)?

Good question :-)

what's the 'intended' way to use forall?

I believe I didn't understand the question, but see if this trivial
use of forall can help:
def allEven(ls:List[int]) = ls forall {i => i%2==0}

thanks for any answers!
yang

Sorry I couldn't help with many of the questions.

Cheers.
--
Rafael de F. Ferreira.
http://www.rafaelferreira.net/



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise