Run Java And J2me ?


'dflemstr' said:
In scala, you can of course do things like "class lol { def #%&(that: Int) = whatever }" and introduce any operator. You can also make unary operators like "class lol { def unary_!!( that: Float) = foo }"...
It gives you a freedom unattainable in other languages.
I suspected that about Scala, but I wasn't sure. I guess it depends on what kind of freedom you like. I've never felt the need to introduce new operators, python's have been sufficient (and actually, even in other languages).
But having to change types or introduce new classes or other such nonsense to appease a compiler that knows nothing of my runtime has happened to me and I hate that.

No biggie, I don't mind delays :D
 
Last edited by a moderator:
To maybe lessen your doubt regarding DSLs and also to show you why new operators can be nifty, look at the "scala.util.parsing" package. With it's DSL features, I made a JSON parser that generates a map for me with the contents of a JSON file in... 23 lines of code, in like 5 minutes, based on regex parsing, as fast as some 200+ lines-versions I've seen in C++.

BTW, we've really gone kinda off-topic here, but since noone seems to care, it shouldn't be a problem ;) .

EDIT: The parser (read notes underneath)
CODE

import scala.util.parsing.combinator._

class JSON extends JavaTokenParsers {
def value : Parser[Any] = (
obj
| arr
| stringLiteral
| floatingPointNumber ^^ (_.toDouble)
| "null" ^^ (x => null)
| "true" ^^ (x => true)
| "false" ^^ (x => false)
)

def member: Parser[(String, Any)] = stringLiteral ~ ":" ~ value ^^
{ case name ~ ":" ~ value => (name, value) }

def obj: Parser[Map[String, Any]] = "{" ~> repsep(member, ",") <~ "}" ^^ (Map() ++ _)
def arr: Parser[List[Any]] = "[" ~> repsep(value, ",") <~ "]"
}



Operators used:
| = alternative values
^^ = if left matches, then execute this right function on the match
~ = left follows right
~> = left follows right, discard left
<~ = left follows right, discard right

so stringLiteral ~ ":" ~ value matches everything with a stringLiteral followed by a colon followed by a value.
 
Last edited by a moderator:
'dflemstr' said:
To maybe lessen your doubt regarding DSLs and also to show you why new operators can be nifty, look at the "scala.util.parsing" package. With it's DSL features, I made a JSON parser that generates a map for me with the contents of a JSON file in... 23 lines of code, in like 5 minutes, based on regex parsing, as fast as some 200+ lines-versions I've seen in C++.

BTW, we've really gone kinda off-topic here, but since noone seems to care, it shouldn't be a problem ;).
I'll have a look.

Thing is, Python not being good for DSLs is a design choice which most pythonistas agree on. One of the disagreements with the Ruby people. Friendly disagreements :D

I'd actually be very glad if people would listen to Gosling in using Scala instead of Java. It would make me less angry at him for Java in the first place. I'm concerned less by the language itself (which besides the over-complex type system is one of the best I've seen), but more by JVM and how Scala interacts with it. There is a mismatch between styles and the runtime itself is not really that good, although DaVinci might help.
For example, I was really disappointed when I saw Actors work as green threads only co-operatively. It's a limitation of the runtime.
 
Last edited by a moderator:
I agree with you fully; modern languages should be used instead of the old ones. And yes, the JVM platform is very lmited, but since it's available virtually everywhere, it's a wise choice of platform.
The actors problem can be avoided, because you can make them use an event-based structure instead (which is what many other implementations do in other languages) but I won't dvie too deeply into that, either.

BTW: I won't force you to look on some daft scala code if you don't want to, so I posted the JSON parser I made (a bit reformatted, though; originally it was 23 lines but to the compiler it's only 5) so as not to force you to use google and skimming through 200 pages of irrelevant examples :p
 
Last edited by a moderator:
'dflemstr' said:
I won't force you to look on some daft scala code if you don't want to, so I posted the JSON parser I made (a bit reformatted, though; originally it was 23 lines but to the compiler it's only 5) so as not to force you to use google and skimming through 200 pages of irrelevant examples :p
Thanks, an example helps when I'm not used to the idioms in a language. This may come as a shock to you, but I've seen a very similar parser written in python :D It used dictionary lookup instead of pattern matching though. Can't find the link, though, and it's bad cause it was very elegant.

Anyway, the dispatch itself was something like this
{'+', plus, '-', minus, 'end', endParse}, where the values are functions. Slightly less elegant than pattern matching, but much more pragmatic.
 
Last edited by a moderator:
I hope that you understood that my description of python was being "the root of all evil" was very ironic. As I said, I write eggs for python servers all the time, and am using Trac for various projects. So no, Python's capabilities don't shock me :p
 
Last edited by a moderator:
'dflemstr' said:
I hope that you understood that my description of python was being "the root of all evil" was very ironic. As I said, I write eggs for python servers all the time, and am using Trac for various projects. So no, Python's capabilities don't shock me :p
I was just joking :D
 
Last edited by a moderator:
Back
Top