Custom Search
|
Date: December 31, 2006
From: David Pollak <dpp@xxxxxxxxxx>
In-reply-to:
<20061231160422.GD22555@xxxxxxxxxxxxxxxx>
References:
<20061104155919.GM32434@xxxxxxxxxxxxxxxx> <001001c7002e$049b4a10$9801a8c0@Dave> <000c01c70041$11054220$0100000a@Dave510m> <20061104185424.GN32434@xxxxxxxxxxxxxxxx> <e6c6cc500611071858w5a76feebt393c28ed1e27058d@xxxxxxxxxxxxxx> <20061108045711.GD856@xxxxxxxxxxxxxxxx> <8071592.post@xxxxxxxxxxxxxxx> <5ba551214e573327ebc72e87ad1779a2@xxxxxxxxxx> <45964CE9.4060109@xxxxxxx> <45976DC8.1030103@xxxxxxxxxxxxxx> <20061231160422.GD22555@xxxxxxxxxxxxxxxx>
val myWindow = new Window {
title = "My Title"
content = VBox(
val myLabel = new Label {
text = "A"
},
new Button {
text = "Click Me"
onClick = { event =>
myLabel.text = "B"
}
}
)
It's kind of like for (int x = 0; x < 10; x++)...I'm also a huge fan of Ruby's hash constructor {:foo => "bar", :baz => "dog"} Having a similar (new-free) way of creating Maps would be cool. Especially if the map constructor would default to an immutable map. If you wanted another map class, you would specify it like {:HashMap "foo" -> "bar", "baz" -> "dog"}
On the list front, the existing List creator works really well for me.Finally, it would be most excellent to have traits for immutable sets and hashes such that the traits were implemented (sorry, Java-speak) on both mutable and immutable sets (as well as lists) and hashes.
On a separate note, I looked at the implementation of immutable ListMap and it looks like lookup time is O(n) rather than O(~1) for HashMap. Is this correct? If so, is there any way to make the immutable ListMaps more efficient for lookup?
On a separate, separate note, is there any information carried around with functions/methods that indicate if the have side effects such that the value of functions/methods that have no side effects can be cached and possibly marking a function/method that takes a function as a parameter as requiring a side-effect-free function. I'm kinda thinking about the 'const' declaration in C++.
On a separate, separate, separate note (okay, this is becoming a wish- list), I really, really like Ruby's "if at the end of the line" construct:
return foo if bar return baz if dogAny chance of a similar construct in Scala or does it just start messing up what is very clean syntax?
Sorry about my rambling.Happy New Year to all that observe the Julian Calendar and have a very, very excellent next 365 days to everyone else!
Thanks, David On Dec 31, 2006, at 8:04 AM, Jamie Webb wrote:
On Sun, Dec 31, 2006 at 07:59:04AM +0000, Andy Dwelly wrote:Panel p = new Panel(new FlowLayout()); JButton b = new JButton("Press me!"); b.setEventListener(somethingOrOther); p.add(b); JSomething foo = new JSomething(blah, blah); foo.setAttribute(); foo.setOtherAttribute(); foo.soGladIDontDoThisKindOfThingAnymore(); p.add(foo); of course solving this needs more than just literals for maps.Yes, it's possible to come up with much more elegant ways to write stuff like that in Scala. IMO the biggest limitation is that there's no nice way to refer to declaratively constructed objects that are deeply nested. Consider: var myLabel = null val myWindow = new Window { title = "My Title" content = VBox( new Label { text = "A" myLabel = this }, new Button { text = "Click Me" onClick = { event => myLabel.text = "B" } } ) } It's all pretty neat and should be a good way to do things in Scala, apart from the horrible hack I used to get hold of a reference to the Label object. Of course I could have just constructed the label on that first line instead, but then I'd be heading back in the direction of the unstructured Java code. /J
-- David Pollak http://blog.lostlake.org
Date: December 31, 2006
From: Jamie Webb <j@xxxxxxxxxxxxxxx>
In-reply-to:
<45976DC8.1030103@xxxxxxxxxxxxxx>
References:
<20061104155919.GM32434@xxxxxxxxxxxxxxxx> <001001c7002e$049b4a10$9801a8c0@Dave> <000c01c70041$11054220$0100000a@Dave510m> <20061104185424.GN32434@xxxxxxxxxxxxxxxx> <e6c6cc500611071858w5a76feebt393c28ed1e27058d@xxxxxxxxxxxxxx> <20061108045711.GD856@xxxxxxxxxxxxxxxx> <8071592.post@xxxxxxxxxxxxxxx> <5ba551214e573327ebc72e87ad1779a2@xxxxxxxxxx> <45964CE9.4060109@xxxxxxx> <45976DC8.1030103@xxxxxxxxxxxxxx>
On Sun, Dec 31, 2006 at 07:59:04AM +0000, Andy Dwelly wrote:
> Panel p = new Panel(new FlowLayout());
> JButton b = new JButton("Press me!");
> b.setEventListener(somethingOrOther);
> p.add(b);
> JSomething foo = new JSomething(blah, blah);
> foo.setAttribute();
> foo.setOtherAttribute();
> foo.soGladIDontDoThisKindOfThingAnymore();
> p.add(foo);
>
> of course solving this needs more than just literals for maps.
Yes, it's possible to come up with much more elegant ways to write
stuff like that in Scala. IMO the biggest limitation is that there's
no nice way to refer to declaratively constructed objects that are
deeply nested. Consider:
var myLabel = null
val myWindow = new Window {
title = "My Title"
content = VBox(
new Label {
text = "A"
myLabel = this
},
new Button {
text = "Click Me"
onClick = { event =>
myLabel.text = "B"
}
}
)
}
It's all pretty neat and should be a good way to do things in Scala,
apart from the horrible hack I used to get hold of a reference to the
Label object. Of course I could have just constructed the label on
that first line instead, but then I'd be heading back in the direction
of the unstructured Java code.
/J
Date: December 31, 2006
From: Andy Dwelly <andy.dwelly@xxxxxxxxxxxxxx>
In-reply-to:
<45964CE9.4060109@xxxxxxx>
References:
<001301c7001f$e255abc0$9801a8c0@Dave> <20061104155919.GM32434@xxxxxxxxxxxxxxxx> <001001c7002e$049b4a10$9801a8c0@Dave> <000c01c70041$11054220$0100000a@Dave510m> <20061104185424.GN32434@xxxxxxxxxxxxxxxx> <e6c6cc500611071858w5a76feebt393c28ed1e27058d@xxxxxxxxxxxxxx> <20061108045711.GD856@xxxxxxxxxxxxxxxx> <8071592.post@xxxxxxxxxxxxxxx> <5ba551214e573327ebc72e87ad1779a2@xxxxxxxxxx> <45964CE9.4060109@xxxxxxx>
|
I'm not familiar with Scala to contribute much to the technical side of
the discussion but the overall goal of good literal support is an
excellent one, I find the arguments laid out here: http://steve-yegge.blogspot.com/2006/09/bloggers-block-4-ruby-and-java-and.html (scroll down to 'Java's biggest problem literally' to get to the meat of it) ....more than convincing. My own pet peeve with java literals is constructing Swing UIs by hand. This is one of the area's where the design for Groovy (whatever else you may think about the language) stands out. My own code is full of stuff like Panel p = new Panel(new FlowLayout());
JButton b = new JButton("Press me!");
b.setEventListener(somethingOrOther);
p.add(b);
JSomething foo = new JSomething(blah, blah);
foo.setAttribute();
foo.setOtherAttribute();
foo.soGladIDontDoThisKindOfThingAnymore();
p.add(foo);
of course solving this needs more than just literals for maps.
AndyI agree this is not as straightforward as map literals in Ruby, etc. Since we want to extend the collection libraries anyway, |
Date: December 30, 2006
From: Tony Morris <tmorris@xxxxxxxxxxx>
In-reply-to:
<8097815.post@xxxxxxxxxxxxxxx>
References:
<4591F715.4030501@xxxxxxxxxxx> <8060223.post@xxxxxxxxxxxxxxx> <45922493.8010508@xxxxxxxxxxx> <45965D04.7080206@xxxxxxx> <8097815.post@xxxxxxxxxxxxxxx>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Eric Willigers wrote: > > > Martin Odersky wrote: >> Tony Morris wrote: >>> Martin, >>> Since the 'implicit' keyword is what defines an automatic coercion, does >>> this mean that the example on page 16 of An Introduction to Scala is >>> incorrect? (I said the last page in an earlier post, but this is a >>> mistake). >>> >>> >> On page 16 I only see the example on currying, and I can't see an >> implicit conversion in there. Why do you think it is incorrect? >> >> -- Martin >> > > Hi Martin, > > See page 12 Automatic User-Defined Coercions > The Acrobat status bar shows "16 of 51" because of the document's 4 header > pages. > > The current (2.3.1) compiler rejects the code - see > http://scala-webapps.epfl.ch/bugtracking/contribs/display.do?id=280 > > Regards, > Eric. > Hi Martin, My PDF reader was playing up. Thanks Eric for correcting me - it is in fact on page 12. Tony Morris http://tmorris.net/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFltflmnpgrYe6r60RAsGaAJ9F5YRgwxvmMBIdBeqL3w9w7HZSDwCff8KA Wrpc4VrLhVAhUBynvihHgAk= =Fy4T -----END PGP SIGNATURE-----
Date: December 30, 2006
From: Eric Willigers <ewilligers@xxxxxxxxx>
In-reply-to:
<45965D04.7080206@xxxxxxx>
References:
<4591F715.4030501@xxxxxxxxxxx> <8060223.post@xxxxxxxxxxxxxxx> <45922493.8010508@xxxxxxxxxxx> <45965D04.7080206@xxxxxxx>
Martin Odersky wrote: > > Tony Morris wrote: >> Martin, >> Since the 'implicit' keyword is what defines an automatic coercion, does >> this mean that the example on page 16 of An Introduction to Scala is >> incorrect? (I said the last page in an earlier post, but this is a >> mistake). >> >> > On page 16 I only see the example on currying, and I can't see an > implicit conversion in there. Why do you think it is incorrect? > > -- Martin > Hi Martin, See page 12 Automatic User-Defined Coercions The Acrobat status bar shows "16 of 51" because of the document's 4 header pages. The current (2.3.1) compiler rejects the code - see http://scala-webapps.epfl.ch/bugtracking/contribs/display.do?id=280 Regards, Eric. -- View this message in context: http://www.nabble.com/Automatic-User-Defined-Coercions-tf2884666.html#a8097815 Sent from the Scala mailing list archive at Nabble.com.
Date: December 30, 2006
From: martin odersky <martin.odersky@xxxxxxx>
In-reply-to:
<45922493.8010508@xxxxxxxxxxx>
References:
<4591F715.4030501@xxxxxxxxxxx> <8060223.post@xxxxxxxxxxxxxxx> <45922493.8010508@xxxxxxxxxxx>
Tony Morris wrote:
On page 16 I only see the example on currying, and I can't see an implicit conversion in there. Why do you think it is incorrect?Martin, Since the 'implicit' keyword is what defines an automatic coercion, does this mean that the example on page 16 of An Introduction to Scala is incorrect? (I said the last page in an earlier post, but this is a mistake).
-- Martin
Date: December 30, 2006
From: Jamie Webb <j@xxxxxxxxxxxxxxx>
In-reply-to:
<45964CE9.4060109@xxxxxxx>
References:
<001301c7001f$e255abc0$9801a8c0@Dave> <20061104155919.GM32434@xxxxxxxxxxxxxxxx> <001001c7002e$049b4a10$9801a8c0@Dave> <000c01c70041$11054220$0100000a@Dave510m> <20061104185424.GN32434@xxxxxxxxxxxxxxxx> <e6c6cc500611071858w5a76feebt393c28ed1e27058d@xxxxxxxxxxxxxx> <20061108045711.GD856@xxxxxxxxxxxxxxxx> <8071592.post@xxxxxxxxxxxxxxx> <5ba551214e573327ebc72e87ad1779a2@xxxxxxxxxx> <45964CE9.4060109@xxxxxxx>
On Sat, Dec 30, 2006 at 12:26:33PM +0100, martin odersky wrote:
> - Should we have a standardized way to create map and set literals? I mean a
> library solution which is
> implemented uniformly by all collection classes.
Yes, I think that would be quite useful.
Incidentally I already use the arrow notation you have below, such that
"abc" -> 1 == Pair("abc", 1).
> - Should there be a "default" implementation for maps and sets? If yes, one
> could envisage writing something like:
>
> new Map("abc" -> 1, "def" -> 2)
>
> If not, one would have to write new HashMap("abc" -> 1, "def" -> 2).
I wonder how that would work (I think it's not ideal that the library already
has three traits called Map), but I certainly find that HashMaps are needed
sufficiently frequently that I would prefer to have them available in the
default environment.
But then I'm not a fan of imports. I'd much rather write them once per project
and be done with it, for the most part. C let me do that...
/J
Date: December 30, 2006
From: martin odersky <martin.odersky@xxxxxxx>
In-reply-to:
<5ba551214e573327ebc72e87ad1779a2@xxxxxxxxxx>
References:
<001301c7001f$e255abc0$9801a8c0@Dave> <20061104155919.GM32434@xxxxxxxxxxxxxxxx> <001001c7002e$049b4a10$9801a8c0@Dave> <000c01c70041$11054220$0100000a@Dave510m> <20061104185424.GN32434@xxxxxxxxxxxxxxxx> <e6c6cc500611071858w5a76feebt393c28ed1e27058d@xxxxxxxxxxxxxx> <20061108045711.GD856@xxxxxxxxxxxxxxxx> <8071592.post@xxxxxxxxxxxxxxx> <5ba551214e573327ebc72e87ad1779a2@xxxxxxxxxx>
Doug Landauer wrote:
On Dec 27, 2006, at 10:31 PM, steve.bendiola wrote:I was going to update the wiki with the different ways to access/modify maps...I'd suggest also listing a way or two that you *can't* create maps, e.g., via a language-defined literal, like Ruby's Hash class, or Python's dictionaries, or even the weird Java "{{ ... }}" shortcut for constructors.
There is a way to do this in Scala, but only for immutable maps. I.e. new TreeMap[String, int] + "abc" -> 1 + "xyz" -> 2I agree this is not as straightforward as map literals in Ruby, etc. Since we want to extend the collection libraries anyway, notably for fattening up the Seq class, now is a good time to think about changing this. What do people think?
- Should we have a standardized way to create map and set literals? I mean a library solution which is
implemented uniformly by all collection classes.- Should there be a "default" implementation for maps and sets? If yes, one could envisage writing something like:
new Map("abc" -> 1, "def" -> 2)
If not, one would have to write new HashMap("abc" -> 1, "def" -> 2).
Cheers
-- Martin
Date: December 29, 2006
From: Patrick Roemer <sangamon@xxxxxxxxxxxxx>
In-reply-to:
<45954522.8070200@xxxxxxx>
References:
<en382m$tr4$1@xxxxxxxxxxxxx> <45954522.8070200@xxxxxxx>
Responding to Philipp Haller: > Otherwise my knowledge of Eclipse is too limited to be able to answer > your question (which I understood "make scala-actors.jar automatically > available to all newly created Scala projects"). That would be very nice, but this... > 1. Go to Project->Properties > 2. Under "Java Build Path"->Libraries do "Add External JARs" and choose > the "scala-actors.jar" that you find in share/scala/lib in the Scala > distribution. ...is absolutely sufficient for me. I had tried that but hadn't cleaned/rebuilt my project after adding the jar. The error markers prevailed, so I thought it hadn't worked and started to look into the plugin. Tried again now with rebuild, works perfectly. Thanks a lot! Best regards, Patrick
Date: December 29, 2006
From: Lex Spoon <lex@xxxxxxxxxxxxx>
References:
<F418C1909C57A14E9456C8BEA8856345017DA6ED@xxxxxxxxxxxxxxxxxx>
"Judson, Ross" <rjudson@xxxxxxxxxxxxxxxxxx> writes: > RichSQL was written as a demonstration of techniques in Scala; dbc is a > full-fledge library and environment for handling relational information. > I'd like to see dbc extended beyond JDBC into simply providing a way of > dealing with tabled/relational data in Scala. > > RichSQL uses a good bit of Scala's bag of tricks to make selects and > inserts very simple. It also relies on left-to-right execution of > statement parts, which is maybe not such a hot thing to do. I can't > remember if the Scala spec actually requires this or not. You can rely on the order if you want. The spec says, in section 6.5: Evaluation of f (e1, ..., en) usually entails evaluation of f and e1, ..., en in that order. -Lex
Date: December 29, 2006
From: Lex Spoon <lex@xxxxxxxxxxxxx>
References:
<1165533824.6067.4.camel@xxxxxxxxxxxxxxxxxx> <q94irgi5gzp.fsf@xxxxxxxxxxxxxxxxxxxxx> <1165874912.6075.29.camel@xxxxxxxxxxxxxxxxxx> <q941wn656k8.fsf@xxxxxxxxxxxxxxxxxxxxx> <1165940969.6342.10.camel@xxxxxxxxxxxxxxxxxx>
> What I mean by deploy is give the packaged application to a container,
> like Eclipse if you were writing a plugin or Tomcat if it was a servlet
> app. When I move to another computer instead of downloading scala and
> setting an environment variable, I can just let maven download it from
> the repository and package the scala jars with my app. This is really
> great when you are not the person compiling your code. I often use
> scala to create one or more components but my project will contain
> mostly java code. If someone else wants to make changes to my java code
> but doesn't know what scala is then they don't need to worry about
> downloading scala to build my code.
To support non-developers, another approach is to have a repository of
compiled components. Then non-developers (or developers of other
components) can install the compiled version, and not need to
recompile at all.
sbaz is designed to support this sort of thing. It distributes
compiled, ready-to-link versions of Scala and Java code, and it
carefully supports non-public repositories for internal use in a
development group. In all of my projects, I do "sbaz install whatever
whateverelse" in order to get my dependencies, and then ant and
Eclipse find them via the scala.home Java property.
Speaking of which, there is an existing convention for the Java
property pointing to a Scala installation: it's scala.home, not
scalaHome. For whatever it's worth.
> > Not meaning to get sidetracked, but I'm not getting your point
> > here. Are you saying that were it not for the explicit compiler and
> > library dependencies in the POM, you would need to set up Scala on the
> > computer to which you deploy your Scala-based program? Do you run this
> > program on this other computer? It's not clear what you mean by
> > "deploy" here, as the word has specific meaning to Maven as well.
So you know, the sbaz approach to dependencies is to grab, by default,
the latest version of all dependencies in your current repository.
The general idea is that, within one repository, all the latest
versions of everything are compatible.
If you ever make sbaz repositories accessible to your Maven plugin,
then there are some ways you can take advantage of this approach and
make it easier on the developer:
1. The compiler and library can be left out. If the developer
declines to say otherwise, then use the latest versions from
the repository.
2. The dependencies on other packages can be by name.
Version-specific dependencies are optional, and indeed unusual.
3. The repository should be possible to declare, but the default
can be the one that you get with a stock Scala installation
from the web site.
-Lex
Date: December 29, 2006
From: Philipp Haller <philipp.haller@xxxxxxx>
In-reply-to:
<en382m$tr4$1@xxxxxxxxxxxxx>
References:
<en382m$tr4$1@xxxxxxxxxxxxx>
Hi Patrick, > I'm just trying to figure out how to make scala-actors.jar known to the > current version (2.4.8) of the Eclipse plugin. From what I understand > this is a pure library addition, so it should be possible, right? I've Yes, it's a pure Scala library, so... > tried to replace the compiler/library jars with the ones from the latest > Scala distribution (2.3.1), adding scala-actors.jar to the lib dir and > to the Bundle-ClassPath and Export-Package sections of the compiler > plugin's manifest.mf, to no effect. Anything I'm missing or doing wrong, > or is it just not possible? ...you don't have to replace the compiler/library jars of the plugin. Otherwise my knowledge of Eclipse is too limited to be able to answer your question (which I understood "make scala-actors.jar automatically available to all newly created Scala projects"). Just for the record: For individual Scala projects, the required steps are the same as for any other library jar, i.e. 1. Go to Project->Properties 2. Under "Java Build Path"->Libraries do "Add External JARs" and choose the "scala-actors.jar" that you find in share/scala/lib in the Scala distribution. Cheers, Philipp
Date: December 29, 2006
From: Patrick Roemer <sangamon@xxxxxxxxxxxxx>
Hi, I'm just trying to figure out how to make scala-actors.jar known to the current version (2.4.8) of the Eclipse plugin. From what I understand this is a pure library addition, so it should be possible, right? I've tried to replace the compiler/library jars with the ones from the latest Scala distribution (2.3.1), adding scala-actors.jar to the lib dir and to the Bundle-ClassPath and Export-Package sections of the compiler plugin's manifest.mf, to no effect. Anything I'm missing or doing wrong, or is it just not possible? Thanks and best regards, Patrick
Date: December 29, 2006
From: Doug Landauer <zia@xxxxxxxxxx>
In-reply-to:
<8071592.post@xxxxxxxxxxxxxxx>
References:
<001301c7001f$e255abc0$9801a8c0@Dave> <20061104155919.GM32434@xxxxxxxxxxxxxxxx> <001001c7002e$049b4a10$9801a8c0@Dave> <000c01c70041$11054220$0100000a@Dave510m> <20061104185424.GN32434@xxxxxxxxxxxxxxxx> <e6c6cc500611071858w5a76feebt393c28ed1e27058d@xxxxxxxxxxxxxx> <20061108045711.GD856@xxxxxxxxxxxxxxxx> <8071592.post@xxxxxxxxxxxxxxx>
On Dec 27, 2006, at 10:31 PM, steve.bendiola wrote:
I was going to update the wiki with the different ways to access/modify maps...
I'd suggest also listing a way or two that you *can't* create maps,
e.g., via a language-defined literal, like Ruby's Hash class, or
Python's dictionaries, or even the weird Java "{{ ... }}" shortcut
for constructors.
Jamie Webb wrote:Trouble is, personally I would have trouble identifying 'tips' unless I'm asked a question.
Coming from Ruby and Python, I miss having a concise syntax for Hash/mapliterals, and for tuple literals. Not so much in the sense of considering it a flaw in Scala, but in the sense that it would save me time if I knew
there were no such syntax -- I wouldn't spend my time looking for it. One thing that would help with this kind of question would be a "pleac"page on Scala. Maybe it could be created collaboratively, on the Scala Wiki,
to get it going, before sending the results to the pleac folks. http://pleac.sourceforge.net/ http://pleac.sourceforge.net/pleac_java/hashes.html Just a thought. Maybe a New Year's Resolution for the more guilt-trippable among us ... -- Doug L.
Date: December 29, 2006
From: Jeff Nowakowski <jeff@xxxxxxxxxxxx>
In-reply-to:
<20061228234155.GA22555@xxxxxxxxxxxxxxxx>
References:
<4574763A.2090606@xxxxxxxxxx> <20061205000426.GD17826@xxxxxxxxxxxxxxxx> <4575465C.7030103@xxxxxxx> <ac0ce270612061058n464977bdt364543cde8a0e26c@xxxxxxxxxxxxxx> <20061207024745.GH17826@xxxxxxxxxxxxxxxx> <878xgrww8r.fsf@xxxxxxxxxxxxxxxxxx> <20061228234155.GA22555@xxxxxxxxxxxxxxxx>
Jamie Webb wrote:
Heh. The LGPL is pretty terrible too.
Ok, straying off topic, but what's wrong with it? I think it's a very good compromise between GPL and BSD.
-Jeff
Date: December 28, 2006
From: Jamie Webb <j@xxxxxxxxxxxxxxx>
In-reply-to:
<878xgrww8r.fsf@xxxxxxxxxxxxxxxxxx>
References:
<4574763A.2090606@xxxxxxxxxx> <20061205000426.GD17826@xxxxxxxxxxxxxxxx> <4575465C.7030103@xxxxxxx> <ac0ce270612061058n464977bdt364543cde8a0e26c@xxxxxxxxxxxxxx> <20061207024745.GH17826@xxxxxxxxxxxxxxxx> <878xgrww8r.fsf@xxxxxxxxxxxxxxxxxx>
On Thu, Dec 28, 2006 at 04:23:16PM -0500, Lex Spoon wrote: > I like Martin's general idea of a blanket, wiki-wide license plus It's certainly simplest. > exceptions for code that includes an explicit license notice. Yes... Though I think that if people want to retain ownership of their code, they are better off hosting it themselves and linking to it. Anyone can edit a wiki and screw up code or licence notices. > Additionally, there is no particular restriction that the text and > code have to be under different licenses; we can very well say that it > is all under the same license if we want. Yes, however my feeling is that it's much more legitimate to want to copy the code and use it as one's own, just from a practical perspective. If anyone found a use for the text, I think it would be reasonable for the authors to expect some sort of credit, even if it's just a link back to the Wiki page. > For the license choice, why not be as liberal as possible? The > general idea is that, if someone is posting to a wiki, then generally > they are happy to have that content widely quoted, modified, and > reused. One could say the same about open-source software in general, yet clearly the world doesn't see it that way... Would some contributors be dissuaded by a very liberal licence? I don't really know, but it seems quite possible given how anal some people get about the GPL. > If public domain does not make sense in our international > context, surely there is something close, e.g. "I release this content > for use for all purposes". Yes. See my previous post. > Runners up might be the MIT or Scala > licenses, which are close and are more commonly used. As I said, both of these are problematic. > While the GFDL is the FSF's recommended license for documentation, > significant problems with it have turned up. For your consideration, > I'll append part of the statement put before Debian's members a while > ago. In addition to the three problems this text identifies, note > that GFDL content is not even compatible with GPL content. Fair enough. Not the GFDL then. Maybe CC/Attribution? > Draw your own conclusions about why the FSF, with all of its legal > resources, might release such a license with these surprising > properties. Heh. The LGPL is pretty terrible too. BTW, Ross, if you're reading this, you definitely need to weigh in on this discussion. I can't make any changes without your approval. /J
Date: December 28, 2006
From: Lex Spoon <lex@xxxxxxxxxxxxx>
References:
<8016177.post@xxxxxxxxxxxxxxx> <458B41FA.9070206@xxxxxxxxxxx> <458BA700.9040105@xxxxxxx> <458BAA86.8080709@xxxxxxxxxxx> <458BB320.9030002@xxxxxxx> <458BC300.3080806@xxxxxxxxxxx> <loom.20061222T124921-678@xxxxxxxxxxxxxx> <458BEB20.3060500@xxxxxxxxxxx>
Tomi Maila <Tomi.Maila@xxxxxxxxxxx> writes: > Jamie Webb wrote: > > The trouble with adding a forum is that they don't attract the keen > > users, so > > questions go unanswered. I don't know about others, but I find the interface > > extremely irritating, so you won't find me reading one regularly. > > > > As an experiment, I'm writing this using the Gmame web interface. It looks > > pretty much like a forum, but of course it avoids splitting the community. I > > don't see how a forum would be an improvement on this. > > > This is also a good point, community should include both active users > and not-so-active users. I however think that Gmane is kind of > unattractive alternative looking too technical and all. Given all the interoperability software around, we can already consider this mailing list to be a message board. Already you can access it as a mailing list, as a web forum (http://www.gmane.org) or via a USENET news reader (using news.gmane.org as your server). I prefer the USENET interface, but everyone has their own taste. An IRC channel is something different and complementary. Essentially, IRC is faster paced than a message board. The individual messages are much shorter, and there is immediate response between the conversation participants. On a message board, people post longer messages and then tend to wait hours at the least for a reply. Anyway, this is a long-winded way of saying "me too". The server irc.freenode.net sounds like a good choice to me. -Lex
Date: December 28, 2006
From: "Burak Emir" <burak.emir@xxxxxxxxx>
In-reply-to:
<8081081.post@xxxxxxxxxxxxxxx>
References:
<F418C1909C57A14E9456C8BEA8856345014907E3@xxxxxxxxxxxxxxxxxx> <8081081.post@xxxxxxxxxxxxxxx>
I am tryig to compile the Arrow example from
http://scala.sygneca.com/code/arrows http://scala.sygneca.com/code/arrows
and I get this error:
Arrow.scala:123 error: not found: value Left
arr { i: I => if (sel(i)) Left(a(i)) else Right(b(i)) }
^
Arrow.scala:123 error: not found: value Right
arr { i: I => if (sel(i)) Left(a(i)) else Right(b(i)) }
^
two errors found
$ scala -version Scala code runner version 2.3.1 -- (c) 2002-2006 LAMP/EPFL
Date: December 28, 2006
From: "steve.bendiola" <steve.bendiola@xxxxxxxxx>
In-reply-to:
<F418C1909C57A14E9456C8BEA8856345014907E3@xxxxxxxxxxxxxxxxxx>
References:
<F418C1909C57A14E9456C8BEA8856345014907E3@xxxxxxxxxxxxxxxxxx>
I am tryig to compile the Arrow example from http://scala.sygneca.com/code/arrows http://scala.sygneca.com/code/arrows and I get this error: Arrow.scala:123 error: not found: value Left arr { i: I => if (sel(i)) Left(a(i)) else Right(b(i)) } ^ Arrow.scala:123 error: not found: value Right arr { i: I => if (sel(i)) Left(a(i)) else Right(b(i)) } ^ two errors found $ scala -version Scala code runner version 2.3.1 -- (c) 2002-2006 LAMP/EPFL Judson, Ross wrote: > > I've placed another example at http://scala.sygneca.com/code/arrows, > showing a possible implementation of the Arrow concept (a generalization > of monads originated by Hughes) in Scala. Once I had my "aha!" moment > and figured out what it all meant, I was pleased at how quickly the > implementation came together, and how naturally it fit in the Scala > language. > > I define an arrow by enriching a basic function with additional methods, > then using implicit methods to "lift" conventional functions into the > Arrow territory. The arrow trait itself looks like this: > > > /** An Arrow is a function from I to O, enriched with > additional functions for composition. */ > trait Arrow[I,O] extends Function1[I,O] { > /** Combine this arrow (from I to O) with another arrow > from O to X, creating a single arrow from I to X. */ > def compose[X](a: Arrow[O, X]): Arrow[I,X]; > /** An operator synonym for the compose method. */ > def >>>[X](a: Arrow[O, X]): Arrow[I,X]; > > /** Combines this arrow with another that takes the > same type of input to create an arrow that creates a > pair of the outputs of this arrow and the other. */ > def par[X](b: Arrow[I,X]): Arrow[I,Pair[O,X]]; > /** An operator synonym for the par method. */ > def &&&[X](b: Arrow[I,X]): Arrow[I,Pair[O,X]]; > > def intype: String > def outtype: String > def arrowtype: String > } > > > RJ > > -- View this message in context: http://www.nabble.com/Arrows-in-Scala-tf2229930.html#a8081081 Sent from the Scala mailing list archive at Nabble.com.
Date: December 28, 2006
From: Lex Spoon <lex@xxxxxxxxxxxxx>
References:
<4574763A.2090606@xxxxxxxxxx> <20061205000426.GD17826@xxxxxxxxxxxxxxxx> <4575465C.7030103@xxxxxxx> <ac0ce270612061058n464977bdt364543cde8a0e26c@xxxxxxxxxxxxxx> <20061207024745.GH17826@xxxxxxxxxxxxxxxx>
I like Martin's general idea of a blanket, wiki-wide license plus exceptions for code that includes an explicit license notice. Additionally, there is no particular restriction that the text and code have to be under different licenses; we can very well say that it is all under the same license if we want. For the license choice, why not be as liberal as possible? The general idea is that, if someone is posting to a wiki, then generally they are happy to have that content widely quoted, modified, and reused. If public domain does not make sense in our international context, surely there is something close, e.g. "I release this content for use for all purposes". Runners up might be the MIT or Scala licenses, which are close and are more commonly used. While the GFDL is the FSF's recommended license for documentation, significant problems with it have turned up. For your consideration, I'll append part of the statement put before Debian's members a while ago. In addition to the three problems this text identifies, note that GFDL content is not even compatible with GPL content. Draw your own conclusions about why the FSF, with all of its legal resources, might release such a license with these surprising properties. -Lex The full resolution is at http://www.debian.org/vote/2006/vote_001 . My comments are in [...] brackets. (2) How does it fail to meet Debian's standards for Free Software? The GFDL conflicts with traditional requirements for free software in a variety of ways, some of which are expanded upon below. As a copyleft license, one of the consequences of this is that it is not possible to include content from a document directly into free software under the GFDL. The major conflicts are: (2.1) Invariant Sections The most troublesome conflict concerns the class of invariant sections that, once included, may not be modified or removed from the documentation in future. Modifiability is, however, a fundamental requirement of the DFSG, which states: 3. Derived Works The license must allow modifications and derived works, and must allow them to be distributed under the same terms as the license of the original software. Invariant sections create particular problems in reusing small portions of the work (since any invariant section must be included also, however large), and in making sure the documentation remains accurate and relevant. [This is actually no big deal for the wiki; we could just say we have no invariant sections.] (2.2) Transparent Copies The second conflict is related to the GFDL's requirements for transparent copies of documentation (that is, a copy of the documentation in a form suitable for editing). In particular, Section 3 of the GFDL requires that a transparent copy of the documentation be included with every opaque copy distributed, or that a transparent copy is made available for a year after the opaque copies are no longer being distributed. For free software works, Debian expects that simply providing the source (or transparent copy) alongside derivative works will be sufficient, but this does not satisfy either clause of the GFDL's requirements. [I do not understand the subtleties here, but it sounds even more complicated than GPL's requirements about distributing source code. If we take our license choice seriously, then we would have to think carefully about, e.g., enabling printing of the wiki, how to make a stand-alone "transparent copy" for use when not net connected, how to deal with changes in the wiki's format should we ever change wiki software, and how to deal with stuff extracted from the wiki where we might want to transition to a new format for the "transparent copy". Would this be time well spent?] (2.3) Digital Rights Management The third conflict with the GFDL arises from the measures in Section 2 that attempt to overcome Digital Rights Management (DRM) technologies. In particular, the GFDL states that You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. This inhibits freedom in three ways: it limits use of the documentation as well as distribution, by covering all copies made, as well as copies distributed; it rules out distributing copies on DRM-protected media, even if done in such a way as to give users full access to a transparent copy of the work; and, as written, it also potentially disallows encrypting the documentation, or even storing it on a filesystem that supports permissions. [This has terrible implications. It seems to imply that if you send an encrypted email to someone, then you may not include any GFDL content. Hmm, in fact, 'GFDL "encrypted filesystem"' gets a lot of interesting Google hits.]
Date: December 28, 2006
From: "Burak Emir" <burak.emir@xxxxxxxxx>
In-reply-to:
<44B76E4E-7799-4235-9018-FA18F625EA19@xxxxxxxxx>
References:
<ac0ce270612280749p3e027f81pbbe737e45181afca@xxxxxxxxxxxxxx> <ECBF64C0-9F80-4614-98B9-F4A0D100978F@xxxxxxxxx> <ac0ce270612280906j78d40a94s32c4d936109c3956@xxxxxxxxxxxxxx> <5DCEEC94-A6D1-40EC-91DF-A3236B06BB83@xxxxxxxxx> <44B76E4E-7799-4235-9018-FA18F625EA19@xxxxxxxxx>
Full flattening of both LHS and RHS is more symmetric, and possibly
more desirable for ="">Why would you want Some(Some(x)) != Some(x) ?
Date: December 28, 2006
From: "Burak Emir" <burak.emir@xxxxxxxxx>
In-reply-to:
<45940F56.7000105@xxxxxxxxxxxxxx>
References:
<45940F56.7000105@xxxxxxxxxxxxxx>
I have some xml:
<?xml version = "1.0" ?>
<marius title="This is a test">
<narrative>now is the time for all good men to come to the aid of the
party.</narrative>
</marius>
...and I have some a method in an object to process it:
def process() = {
val src = ""> val cpa = scala.xml.parsing.ConstructingParser.fromSource(src, false)
val doc = cpa.document()
val model = new Model();
doc.docElem match {
case Elem(_, "marius", attributes, _, _) => model.title =
attributes.get("title")
case _ => {}
}
model
}
where Model has a variable title: String.
The compiler complains
found : scala.Option[scala.Seq[scala.xml.Node]]
required: java.lang.String
case Elem(_, "marius", attributes, _, _) => model.title =
attributes.get
("title")
^
one error found
...not unreasonably, scala.Option[scala.Seq[scala.xml.Node]] is actually
how XML attributes appear to be defined in Elem. How do I actually get
at the text of the title attribute, e.g. "This is a test" ? I suppose a
supplementary question is should I really be starting from doc.docElem
as the root node ?
Date: December 28, 2006
From: Jay Sachs <jay@xxxxxxxxx>
In-reply-to:
<5DCEEC94-A6D1-40EC-91DF-A3236B06BB83@xxxxxxxxx>
References:
<ac0ce270612280749p3e027f81pbbe737e45181afca@xxxxxxxxxxxxxx> <ECBF64C0-9F80-4614-98B9-F4A0D100978F@xxxxxxxxx> <ac0ce270612280906j78d40a94s32c4d936109c3956@xxxxxxxxxxxxxx> <5DCEEC94-A6D1-40EC-91DF-A3236B06BB83@xxxxxxxxx>
On Dec 28, 2006, at 12:23 PM, Jay Sachs wrote:
On Dec 28, 2006, at 12:06 PM, Burak Emir wrote:On 12/28/06, Jay Sachs <jay@xxxxxxxxx> wrote: On Dec 28, 2006, at 10:49 AM, Burak Emir wrote: > do you think it would make sense to define Some.equals method such > that Some(x) == x? But then wouldn't Some(None) == None ? Good point. One could make a special case for None.Options of options are quite rare, and a big obstacle to optimization of option types, but since we have them, it would surely be very confusing to have Some(None) == None. Also Some(Some (x)) should not be == Some(x). So here's what is meant.case class Some[a](x:a) extends Option[a]{ def equals(y:Any) = y match { case None => false case Some(z) => x == z case z => x == z } }
This doesn't do what your statement above says, namely Some(Some(x)) ! = Some(x):
Some(Some(3)) == Some(3)
x = Some(3) y = Some(3)
matches case 2: z = 3
=> Some(3) == 3
x = 3 y = 3
matches case 3: z = 3
=> 3 == 3
true
if I'm reading it correctly (and as a Scala newbie, possibilities for
mistakes are boundless).
Full flattening of both LHS and RHS is more symmetric, and possibly more desirable for ==.
Why would you want Some(Some(x)) != Some(x) ?
Date: December 28, 2006
From: Andy Dwelly <andy.dwelly@xxxxxxxxxxxxxx>
I have some xml: <?xml version = "1.0" ?> <marius title="This is a test"><narrative>now is the time for all good men to come to the aid of the party.</narrative>
</marius>
...and I have some a method in an object to process it:
def process() = {
val src = scala.io.Source.fromFile(in)
val cpa = scala.xml.parsing.ConstructingParser.fromSource(src, false)
val doc = cpa.document()
val model = new Model();
doc.docElem match {
case Elem(_, "marius", attributes, _, _) => model.title =
attributes.get("title")
case _ => {}
}
model
}
where Model has a variable title: String. The compiler complains found : scala.Option[scala.Seq[scala.xml.Node]] required: java.lang.Stringcase Elem(_, "marius", attributes, _, _) => model.title = attributes.get
("title")
^
one error found
...not unreasonably, scala.Option[scala.Seq[scala.xml.Node]] is actually
how XML attributes appear to be defined in Elem. How do I actually get
at the text of the title attribute, e.g. "This is a test" ? I suppose a
supplementary question is should I really be starting from doc.docElem
as the root node ?
Andy
Date: December 28, 2006
From: Jay Sachs <jay@xxxxxxxxx>
In-reply-to:
<ac0ce270612280906j78d40a94s32c4d936109c3956@xxxxxxxxxxxxxx>
References:
<ac0ce270612280749p3e027f81pbbe737e45181afca@xxxxxxxxxxxxxx> <ECBF64C0-9F80-4614-98B9-F4A0D100978F@xxxxxxxxx> <ac0ce270612280906j78d40a94s32c4d936109c3956@xxxxxxxxxxxxxx>
On Dec 28, 2006, at 12:06 PM, Burak Emir wrote:
On 12/28/06, Jay Sachs <jay@xxxxxxxxx> wrote: On Dec 28, 2006, at 10:49 AM, Burak Emir wrote: > do you think it would make sense to define Some.equals method such > that Some(x) == x? But then wouldn't Some(None) == None ? Good point. One could make a special case for None.Options of options are quite rare, and a big obstacle to optimization of option types, but since we have them, it would surely be very confusing to have Some(None) == None. Also Some(Some (x)) should not be == Some(x). So here's what is meant.case class Some[a](x:a) extends Option[a]{ def equals(y:Any) = y match { case None => false case Some(z) => x == z case z => x == z } }It's just a proposal, if nobody ever wished for this thing, it's probably not worth including.
I think it's difficult if not impossible to get the semantics right. You've eliminated Some(Some(x)) == Some(x), but what if the nested "Some" is inside a list:
Some( List(Some(3)) : List[Any] ) == List(3) : List[Any] ) Per your definition above, this evaluates to List(Some(3)) == List(3) which recursively will invoke Some.== and return true.
Date: December 28, 2006
From: "Burak Emir" <burak.emir@xxxxxxxxx>
In-reply-to:
<ECBF64C0-9F80-4614-98B9-F4A0D100978F@xxxxxxxxx>
References:
<ac0ce270612280749p3e027f81pbbe737e45181afca@xxxxxxxxxxxxxx> <ECBF64C0-9F80-4614-98B9-F4A0D100978F@xxxxxxxxx>
On Dec 28, 2006, at 10:49 AM, Burak Emir wrote:
>
>
> On 12/28/06, Eric Willigers <ewilligers@xxxxxxxxx> wrote:
> map.get("id") returns Some(1234), and Some(1234) != 1234
>
> do you think it would make sense to define Some.equals method such
> that Some(x) == x?
But then wouldn't Some(None) == None ?
Date: December 28, 2006
From: Jay Sachs <jay@xxxxxxxxx>
In-reply-to:
<ac0ce270612280749p3e027f81pbbe737e45181afca@xxxxxxxxxxxxxx>
References:
<ac0ce270612280749p3e027f81pbbe737e45181afca@xxxxxxxxxxxxxx>
On Dec 28, 2006, at 10:49 AM, Burak Emir wrote:
On 12/28/06, Eric Willigers <ewilligers@xxxxxxxxx> wrote:
map.get("id") returns Some(1234), and Some(1234) != 1234
do you think it would make sense to define Some.equals method such
that Some(x) == x?
But then wouldn't Some(None) == None ?
Date: December 28, 2006
From: Daniel Schregenberger <scdaniel@xxxxxxxxxxxxxxx>
In-reply-to:
<ac0ce270612280745r1cd40eenfc0177093989c480@xxxxxxxxxxxxxx>
References:
<ac0ce270612270816x6503bf52sd6f69fa387fa83cd@xxxxxxxxxxxxxx> <8070030.post@xxxxxxxxxxxxxxx> <ac0ce270612280745r1cd40eenfc0177093989c480@xxxxxxxxxxxxxx>
On Don, 2006-12-28 at 16:45 +0100, Burak Emir wrote:
> The trouble with this document as well as the other ones is that we
> use LaTeX and programs in the LaTeX source don't exists as separate
> scala files that could be run and tested. For scala.xml, I started to
> use XInclude and separate source files, this is much easier in XML
> (however, there is no fancy highlighting etc yet).
Assuming you use the listings package: try
\lstinputlisting{code/paths.scala}
-- Daniel
--
http://www.despite.ch/ -- http://www.klyde.ch/ -- http://www.npfdd.ch/
Date: December 28, 2006
From: "Burak Emir" <burak.emir@xxxxxxxxx>
map.get("id") returns Some(1234), and Some(1234) != 1234
Date: December 28, 2006
From: "Burak Emir" <burak.emir@xxxxxxxxx>
In-reply-to:
<8070030.post@xxxxxxxxxxxxxxx>
References:
<ac0ce270612270816x6503bf52sd6f69fa387fa83cd@xxxxxxxxxxxxxx> <8070030.post@xxxxxxxxxxxxxxx>
It should be:
atan2(im, re) instead of atan(re/im)
How might the community help?
When we experience bugs in the Scala compiler, we can Report a Bug through
http://scala.epfl.ch/bugs/index.html so the compiler is corrected and the
user's submission can optionally be added to the test suite.
Date: December 28, 2006
From: "Kobayashi, Tomoyas" <list.2006@xxxxxx>
In-reply-to:
<ac0ce270612270654k76a80f92t53fee59045fd2f62@xxxxxxxxxxxxxx>
References:
<4592748E.7030906@xxxxxx> <ac0ce270612270654k76a80f92t53fee59045fd2f62@xxxxxxxxxxxxxx>
Hi, Thank you for the clarification. That is very helpful.> To see why "def ..." introduces a method, consider that the interpreter is
> just a frontend for the compiler. When typing "stmt_i", it constructs a
> Scala program similar to
> object line_i {
> stmt_1;...;stmt_{i-1}
> def result = stmt_i
> }
> then compiles it, runs it, captures the result and prints it. Here,
> "stmt_1;
> ...; stmt_{i-1}" means everything that was typed in the interpreter
before
> stmt_i. That is why a "def ..." becomes a method, it a method of the > (implicit) enclosing class.Ah, I think I also see why the shell doesn't accept a total program that scalac can compile...
Regards, -- Kobayashi, Tomoyas Burak Emir wrote:
On 12/27/06, Kobayashi, Tomoyas <list.2006@xxxxxx> wrote:Hi,こんにちは ! In the interactive toplevel, when I define a function using "def"keyword, I get the following result: scala> def double(x:int) = {x*2} double: (scala.Int)scala.IntThis is the type of a method. Since functions are first class in Scala, the following code should alsowork, and it works indeed. scala> val double = {x:int => x*2} double: (scala.Int) => scala.Int = <function>This is the type of a function (an instance of Function1[int,int]) My question is that while the toplevel infers the type of the former as'(scala.Int)scala.Int', it infers that of the latter one as '(scala.Int) => scala.Int = <function>'. Is there any difference between them?Yes, a method has to be turned into a function to become a first classvalue. Most of the time, this happens automatically (using type information,the compiler knows that a function is expected. See http://article.gmane.org/gmane.comp.lang.scala/3101) Otherwise, it suffices to prefix the method name with &. To see why "def ..." introduces a method, consider that the interpreter is just a frontend for the compiler. When typing "stmt_i", it constructs a Scala program similar to object line_i { stmt_1;...;stmt_{i-1} def result = stmt_i }then compiles it, runs it, captures the result and prints it. Here, "stmt_1;...; stmt_{i-1}" means everything that was typed in the interpreter before stmt_i. That is why a "def ..." becomes a method, it a method of the (implicit) enclosing class. So methods and functions are not always interchangeable, and one is not syntactic sugar for the other. The syntax or calling either is the same, though. cheers, Burak
Date: December 28, 2006
From: Eric Willigers <ewilligers@xxxxxxxxx>
In-reply-to:
<8071592.post@xxxxxxxxxxxxxxx>
References:
<001301c7001f$e255abc0$9801a8c0@Dave> <20061104155919.GM32434@xxxxxxxxxxxxxxxx> <001001c7002e$049b4a10$9801a8c0@Dave> <000c01c70041$11054220$0100000a@Dave510m> <20061104185424.GN32434@xxxxxxxxxxxxxxxx> <e6c6cc500611071858w5a76feebt393c28ed1e27058d@xxxxxxxxxxxxxx> <20061108045711.GD856@xxxxxxxxxxxxxxxx> <8071592.post@xxxxxxxxxxxxxxx>
steve.bendiola wrote:
>
> I was going to update the wiki with the different ways to access/modify
> maps, but I don't understand why the last line in this code sample fails:
>
> val map = new scala.collection.mutable.HashMap[String, Any]
>
> map("likes") = "cheese"
> assume( map.get("likes") == Some("cheese") )
> assume( map("likes") == "cheese")
>
> assume( map.get("fakeKey") == None)
>
> map += "name" -> "Gromit"
> assume( map("name") == "Gromit")
>
> map += "id" -> 1234
> assume( map.get("id") == Some(1234) )
> assume(map.get("id") == 1234, "map.get(id) == 1234 failed" )
>
Replace the last line with
assume(map("id") == 1234)
This is equivalent to
assume(map.apply("id") == 1234)
map.get("id") returns Some(1234), and Some(1234) != 1234
--
View this message in context:
http://www.nabble.com/Maps-in-scala-tf2573926.html#a8071637
Sent from the Scala mailing list archive at Nabble.com.
Date: December 28, 2006
From: "steve.bendiola" <steve.bendiola@xxxxxxxxx>
In-reply-to:
<20061108045711.GD856@xxxxxxxxxxxxxxxx>
References:
<001301c7001f$e255abc0$9801a8c0@Dave> <20061104155919.GM32434@xxxxxxxxxxxxxxxx> <001001c7002e$049b4a10$9801a8c0@Dave> <000c01c70041$11054220$0100000a@Dave510m> <20061104185424.GN32434@xxxxxxxxxxxxxxxx> <e6c6cc500611071858w5a76feebt393c28ed1e27058d@xxxxxxxxxxxxxx> <20061108045711.GD856@xxxxxxxxxxxxxxxx>
I was going to update the wiki with the different ways to access/modify maps,
but I don't understand why the last line in this code sample fails:
val map = new scala.collection.mutable.HashMap[String, Any]
map("likes") = "cheese"
assume( map.get("likes") == Some("cheese") )
assume( map("likes") == "cheese")
assume( map.get("fakeKey") == None)
map += "name" -> "Gromit"
assume( map("name") == "Gromit")
map += "id" -> 1234
assume( map.get("id") == Some(1234) )
assume(map.get("id") == 1234, "map.get(id) == 1234 failed" )
Jamie Webb wrote:
>
> On Tue, Nov 07, 2006 at 08:58:56PM -0600, John Williams wrote:
>> This is good stuff! It's perfectly obvious once you see it, but it
>> would have taken me forever to think of this on my own. Has anyone
>> made a collection of tips like this somewhere? I think such a
>> collection would be a big help to Scala programmers who are trying to
>> move beyond writing Java-like code.
>
> The Wiki at scala.sygneca.com has various code examples, but they tend
> to be longer.
>
> Trouble is, personally I would have trouble identifying 'tips' unless
> I'm asked a question. Maybe someone could start a 'most hated Java
> idioms' page and we'll see how Scala fares...
>
> -- Jamie Webb
>
>
--
View this message in context:
http://www.nabble.com/Maps-in-scala-tf2573926.html#a8071592
Sent from the Scala mailing list archive at Nabble.com.
Date: December 28, 2006
From: Eric Willigers <ewilligers@xxxxxxxxx>
In-reply-to:
<ac0ce270612270758r3debc2ex91c136413d50ae0d@xxxxxxxxxxxxxx>
References:
<ac0ce270612220951l68b487f8hae0065d774f09d6e@xxxxxxxxxxxxxx> <8049177.post@xxxxxxxxxxxxxxx> <ac0ce270612270758r3debc2ex91c136413d50ae0d@xxxxxxxxxxxxxx>
Burak Emir-2 wrote:
>
>> I hadn't previously realised that pattern matching is weakly typed - the
>> type of a pattern does not need to be (a subtype of) the type of the
>> selector.
>
>
> we used to have that restriction, but it is not what one wants.
>
> trait Foo
> trait Bar
>
> (x:Foo with Bar) match {
> case z:Bar =>
> }
>
> about the checking, "sealed" freezes all subclasses that are case classes,
> it is still possible to extend them in other compilation units with
> non-case
> subclasses!
>
Hi Burak,
Many thanks for the detailed reply. I'm not convinced the above statement is
correct, and the compiler also appears to disagree.
// B.scala
sealed class B {}
case class B2 extends B {}
// D.scala
case class D2 extends B2 {} // legal
class D extends B {} // illegal
fsc B.scala D.scala
D.scala:4 error: illegal inheritance from sealed class B
class D extends B {}
^
one error found
The common case may be for developers to make the descendants of sealed
classes be case objects, final case classes or sealed classes having only
final case descendants.
However, the language specification makes little or no distinction between
case and non-case classes when it discusses "sealed".
Many thanks for the remainder of your email. As developers use your pattern
matching in non-trivial ways, we will appreciate what static checks you can
provide.
Regards,
Eric.
--
View this message in context:
http://www.nabble.com/Scala-paper%3A-Matching-Objects-with-Patterns-tf2871732.html#a8070479
Sent from the Scala mail