6 ms·
See my answer on Quora to "Will Scala ever remove XML literals?" http://www.quora.com/Will-Scala-ever-remove-XML-literals http://www.quora.com/Will-Scala-ever-r
by jorgeortiz85 15y ago
See my answer on Quora to "Will Scala ever remove XML literals?" http://www.quora.com/Will-Scala-ever-remove-XML-literals http://www.quora.com/Will-Scala-ever-remove-XML-literals
Summary: No. At the time that Scala was started, built-in support for XML showcased one area were object-oriented decomposition failed and functional programming proved quite useful. Today the benefits of FP are more well known, and it's generally agreed that if Scala were starting from scratch it would not include XML literals. However, given that XML literals are in the language already, that large code bases have come to rely on them, and that they generally don't get in the way if you don't use them, it's unlikely that they will be removed.
- _sh 15y agoSolution: move it to a library, like perl did with it's format syntax, and take it out of core.
- jorgeortiz85 15y agoThis is hard because Scala's XML support affects the parser. At the lexical level. Scala does have compiler plugins, but it doesn't have parser plugins.
- corruptmemory 15y agoAgreed. Macros and reader macros ;-)
- jorgeortiz85 15y agoLet me know when you figure out how to statically type check those. You could publish a paper or two, I'm sure.
- corruptmemory 15y agoNemerle already does it: http://nemerle.org/macros.html http://nemerle.org/macros.html, so does Template Haskell: http://www.haskell.org/haskellwiki/Template_Haskell http://www.haskell.org/haskellwiki/Template_Haskell
- a_strange_guy 15y agoYou don't typecheck macros since they run at compile time. You typecheck the expanded code instead.
- samth 15y agoAnd we did! Check out: http://blog.racket-lang.org/2011/03/languages-as-libraries-pldi-2011.html http://blog.racket-lang.org/2011/03/languages-as-libraries-p...
- corruptmemory 15y agoTo reiterate a point implied by other commenters: macro-expansion is a compile-time operation. If the language utilizes a typing system to help promote sound programming then the results of the expansion will be compiled in the context of type constraints - the expansion is either sound or unsound w.r.t. such constraints. To some extent there is a continuing popular schism with the idea that "strongly typed" must be synonymous with the lack of "eval", which, at least in principle, cannot be true. In fact, StandardML does have the ability to extend the environment of a program at run-time (as well as Typed Racket). All the necessary typing and meta-data is retained at run-time so that newly evaluated code is checked for type-consistency just like when the "main code" was compiled. So, not only can one expand macros at compile time and verify that the expansions are sound, one can also do the same at run-time.