5 ms·
Scala's upcoming dynamic capabilities
- pietrofmaggi 16y agoA recent interview of Martin Odersky on SE-Radio introduces this and other nice features that are in the works for Scala: http://www.se-radio.net/2011/02/episode-171-scala-update-with-martin-odersky/ http://www.se-radio.net/2011/02/episode-171-scala-update-wit...
- xtho 16y agoI guess scala isn't already complex or rather implicit enough. Is this implemented as a library or does it also require changes to the language/compiler?
- baconserker 16y agoIt required a small language change, which I believe you can see in it's entirety here: https://lampsvn.epfl.ch/trac/scala/changeset/23993 https://lampsvn.epfl.ch/trac/scala/changeset/23993
- carsongross 16y ago"You're going the wrong way!" http://www.youtube.com/watch?v=NEZv0FUPtcc http://www.youtube.com/watch?v=NEZv0FUPtcc
- rit 16y agoLast week I spent a little bit of time trying to figure out how the Dynamic trait works and what its good for. I managed to do a quick and dirty 5 minute mockup of a "Callable" Map that lets you invoke keys as method names: https://gist.github.com/797513 https://gist.github.com/797513
- gtani 16y agoexamples with XML tree https://gist.github.com/783394 https://gist.github.com/783394 what to call it? http://groups.google.com/group/scala-language/browse_thread/thread/93645910e3b2fcee http://groups.google.com/group/scala-language/browse_thread/...
- metageek 16y agodef invokeDynamic(name: String)(args: Any*) = { println("Invoke Dynamic: (name = %s)(args: %s)".format(name, args)) get(name.asInstanceOf[String]) } Why do you need the asInstanceOf(), when name is already declared to be a String? Sorry if this is obvious; I don't know Scala (I've glanced at it, but the 2.8 compiler is too slow on my laptop--as in, about one line per minute).
- rit 16y agoSorry, you don't. It's a leftover from an earlier attempt to do something different with dynamic. Your assumption is correct: It is already a string and there is no purpose to casting it to a String. I don't recall exactly where that artifact came from but I recall the original release of Dynamic had a very different method signature and I was fiddling to figure out the new signatures when I wrote this. The examples I found when I wrote this used the old interface and the new one had no docs or examples yet so I did a bit of playing. I've updated the gist to remove the unnecessary asInstanceOf and demonstrate it as proper code.
- metageek 16y agoAh, nice. Thanks for answering.