|
assorted beginner questions: msg#00433lang.scala
i've accumulated a list of questions over the past few days of using 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? 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) are there multi-line string literals in scala? are there any form of nested comments in scala? does scala have keyword arguments a la lisp/python? is there any special syntax for hashtable/map/set gets/updates? can i define functions that aren't part of an 'object' or 'class'? 'static methods'? is there a web interface to sbaz somewhere? 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? is there a more succinct way to reduce a list, e.g. something that simply names an operator, like (mylist reduceLeft &&)? in pattern matching, can i bind to the composite structure as well as its elements? in haskell you can do this as: case blah of ls@(x:xs) -> ... -- i can refer to the cons (ls) or its car (x) and cdr (xs) [] -> ... 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)? the emacs mode doesn't seem to correctly color tuples in pattern matching (at least in for-comprehensions). just fyi. when can/can't i omit () (for zero-param calls/defs) or the 'new' keyword preceding constructor calls? for the former, is it ever ambiguous whether we're passing around a function or the function's result? for the latter, is there a semantic difference? why is, e.g., foldLeft defined so oddly? 'explicitly curried', it seems: def foldLeft[b](z: b)(op: (b, a) => b): b = ... this is also seen on http://www.scala-lang.org/intro/targettyping.html. is this seems to encourage the user to use this strange syntactic style: (xs foldLeft z) { (x,y) => x+y } while on that page, what's the difference between {} and () in this context? it seems whileLoop treats both as parameterless closures ('blocks' as the manual calls them). what's the 'intended' way to use forall? ideally, the syntax would be: assert(forall ({name, Prop(typ, value) <- props.elements) { checkType(value, typ) }) the closest thing that i believe is realizable is: assert(forall (props.elements) { {name, Prop(typ, value)} => checkType(value, typ) }) but that gives me "error: malformed formal parameter list." i currently do: assert((for (val {name, Prop(typ, value)} <- props.elements) yield checkType(value, typ)) forall (x => x)) is there any way to automatically inherit certain behaviors, a la 'derives' in haskell? any tools/approaches using metaprogramming, reflection, or something else? in particular, i'd like to (de)serialize my objects, a la python's pickle or haskell's read/show, without writing any serialization code (or at most once). what are the some of the principal reasons for scala's (generally) lesser performance compared with java, at least according to the language shootout? not trolling; i'd just like to understand the strengths and weaknesses of languages that i use. are there any efforts under way to provide static checking/modification tools for scala? (checkers in the vein of pmd/findbugs, or annotated like esc/dbc, and modifiers like refactorers or transformers like jackpot) thanks for any answers! yang |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Another nit: 00433, Tony Morris |
|---|---|
| Next by Date: | Re: Another nit: 00433, Vijay Saraswat |
| Previous by Thread: | Empty Iteratorsi: 00433, Miles Sabin |
| Next by Thread: | Re: assorted beginner questions: 00433, David Pollak |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |