This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ scalac -Yrangepos -Xprint-pos -Xprint:parser,typer y.scala | |
| [[syntax trees at end of parser]] // y.scala | |
| [0:171]package [0:0]<empty> { | |
| [0:51]object X extends [9:51][52]scala.AnyRef { | |
| [9]def <init>() = [9]{ | |
| [9][9][9]super.<init>(); | |
| [9]() | |
| }; | |
| [13:26]val d = [21:26][21:26][21:26]new [25:26]D(); | |
| [29:49][29:37]d.method([38:48][38:43]value = [46:48]10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object ImplicitMacros { | |
| implicit class C(val a: Int) { | |
| def add(b: _) = macro Impl.add | |
| } | |
| } | |
| trait Impl extends Macro { | |
| def add(b: c.Tree) = { | |
| import c.universe._ | |
| val s = Select(c.prefix.tree, TermName("a")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > last core/compile:compile | |
| [debug] | |
| [debug] Initial source changes: | |
| [debug] removed:Set() | |
| [debug] added: Set(/home/antoras/dev/Scala/sbt-example-paradise/core/src/main/scala/macrouse/Test.scala) | |
| [debug] modified: Set() | |
| [debug] Removed products: Set() | |
| [debug] Modified external sources: Set() | |
| [debug] Modified binary dependencies: Set() | |
| [debug] Initial directly invalidated sources: Set(/home/antoras/dev/Scala/sbt-example-paradise/core/src/main/scala/macrouse/Test.scala) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sbt._ | |
| import Keys._ | |
| object BuildSettings { | |
| val buildSettings = Defaults.defaultSettings ++ Seq( | |
| organization := "org.scalamacros", | |
| version := "1.0.0", | |
| scalacOptions ++= Seq( | |
| "-deprecation", | |
| "-feature", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ scalac x.scala | |
| $ scala Test | |
| List(Test$B$@4ce32802, Test$C$@5557c2bd) | |
| List(Test$A$@5ef4f44a, Test$D$@23d256fa) | |
| List(Test$A$@5ef4f44a, Test$B$@4ce32802) | |
| List(Test$C$@5557c2bd, Test$B$@4ce32802, Test$A$@5ef4f44a) | |
| List(Test$B$@4ce32802, Test$A$@5ef4f44a, Test$B$@4ce32802) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trib = 1 : 1 : 1 : zipWith (+) trib (zipWith (+) (tail trib) (tail (tail trib))) | |
| take 15 trib --[1,1,1,3,5,9,17,31,57,105,193,355,653,1201,2209] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trib n = if n <= 2 then 1 else loop 1 1 1 2 | |
| where loop a b c i = if i < n then loop b c (a+b+c) (i+1) else c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (100 until 10000).par.filter(x=>(2 to math.sqrt(x).toInt).filter(x%_==0).find{p=>val str=s"$p$x${x/p}";str.length==9&&str.sorted=="123456789"}.isDefined).sum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def p32 = { | |
| def hasAllDigits(str: String) = | |
| str.length == 9 && str.sorted == "123456789" | |
| def multiplicants(x: Int) = | |
| (2 to math.sqrt(x).toInt) filter (x%_ == 0) | |
| def isPandigital(x: Int) = | |
| multiplicants(x) exists (p => hasAllDigits(s"$p$x${x/p}")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object X extends App { | |
| val s = StatementParser("x = (x + 1)") | |
| println(s) | |
| } | |
| trait Expression | |
| case class Plus(a: Expression, b: Expression) extends Expression | |
| case class Var(name: String) extends Expression | |
| case class Num(n: Int) extends Expression | |
| trait Statement |