by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Stefan Wachter
    @swachter
    Sorry - wrong channel!
    vito-c
    @vito-c
    so I'm a little confused about the state of macros in scala 2.13 can/should we use scalameta to create macros or should we stick with the whitebox/blackbox solution?
    Ólafur Páll Geirsson
    @olafurpg
    @vito-c use whitebox/blackbox
    scalameta doesnt have anything to do with macros anymore
    vito-c
    @vito-c
    aww ok I really liked the ability to print trees using structureLabeled
    urbanchr
    @urbanchr

    Hi, I am a bit puzzled: I tried the example from the docs about parsing the simple "a + b".

    import $ivy.`org.scalameta::scalameta:4.3.21`
    
    import scala.meta._
    
    println("a + b".parse[Stat].get.structure)

    Unfortunately I get an error that is not very helpful

    java.lang.NoSuchMethodError: scala.meta.Dialect.allowEndMarker()Z
      scala.meta.internal.parsers.ScalametaParser$EndMarkerIntro$.unapply(ScalametaParser.scala:607)
      scala.meta.internal.parsers.ScalametaParser$$anonfun$3.applyOrElse(ScalametaParser.scala:3907)
      scala.meta.internal.parsers.ScalametaParser$$anonfun$3.applyOrElse(ScalametaParser.scala:3902)
      scala.PartialFunction$Lifted.apply(PartialFunction.scala:310)
    ...

    What do I do wrong? I use Ammonite 2.2.0 and Scala 2.13.3 (under Java 9). Thanks!

    Tomasz Godzik
    @tgodzik
    looks like maybe not all jars are being pulled in Ammonite? It does work in a main method and worksheets
    urbanchr
    @urbanchr
    How can I find out which one is not pulled? Which one should be present?
    Tomasz Godzik
    @tgodzik
    not sure, it looks like altogether wroong/not all jars are being loaded
    Tomasz Godzik
    @tgodzik
    it would be good to report an issue to ammonite, it doesn't look like a problem with scalameta
    might be wrong, but I don't see what could cause it, that method should be available
    urbanchr
    @urbanchr

    Very strange: I tried exactly the same code on another machine (Linux as opposed to my main Mac). As expected it loads quite a few jars on the first run.

    Loading...
    Welcome to the Ammonite Repl 2.1.4 (Scala 2.13.2 Java 11.0.7)
    @ import $ivy.`org.scalameta::scalameta:4.3.21` 
    https://repo1.maven.org/maven2/org/scalameta/scalameta_2.13/4.3.21/scalameta_2.13-4.3.21.pom
      100.0% [##########] 3.1 KiB (1.4 KiB / s)
    ...

    But the snippet then produces a very similar error:

     @ println("a + b".parse[Stat].get.structure) 
    java.lang.NoSuchMethodError: 'boolean scala.meta.Dialect.allowEndMarker()'
      scala.meta.internal.parsers.ScalametaParser$EndMarkerIntro$.unapply(ScalametaParser.scala:607)
      scala.meta.internal.parsers.ScalametaParser$$anonfun$3.applyOrElse(ScalametaParser.scala:3907)
      scala.meta.internal.parsers.ScalametaParser$$anonfun$3.applyOrElse(ScalametaParser.scala:3902)
      scala.PartialFunction$Lifted.apply(PartialFunction.scala:310)
      scala.PartialFunction$Lifted.apply(PartialFunction.scala:306)
      scala.meta.internal.parsers.ScalametaParser.entrypointStat(ScalametaParser.scala:3938)
      scala.meta.internal.parsers.ScalametaParser.$anonfun$parseStat$2(ScalametaParser.scala:59)
      scala.meta.internal.parsers.ScalametaParser.parseRule(ScalametaParser.scala:48)
      scala.meta.internal.parsers.ScalametaParser.parseStat(ScalametaParser.scala:59)
      scala.meta.parsers.Parse$.$anonfun$parseStat$1(Parse.scala:14)
      scala.meta.internal.parsers.ScalametaParser$$anon$214.apply(ScalametaParser.scala:4190)
      scala.meta.parsers.Api$XtensionParseDialectInput.parse(Api.scala:25)
      scala.meta.parsers.Api$XtensionParseInputLike.parse(Api.scala:14)
      ammonite.$sess.cmd2$.<clinit>(cmd2.sc:1)

    I can send the log of all jars that have been pulled the first time.

    Ólafur Páll Geirsson
    @olafurpg
    @urbanchr what happens if you use an older version like 4.3.0?
    urbanchr
    @urbanchr
    I can confirm 4.3.0 works as expected.
    urbanchr
    @urbanchr
    Also, 4.3.10, 4.3.15, 4.3.18, 4.3.20 work. But reliably 4.3.21 seems not. Tried on two computers, one MacOSX and one Linux. Any more information I can provide?
    Tomasz Godzik
    @tgodzik
    Also it seems to not work only in Ammonite. No idea what's going on
    urbanchr
    @urbanchr

    But note that I tried this consistent behaviour out under the following two versions of Ammonite:

    Linux: Ammonite Repl 2.1.4 (Scala 2.13.2 Java 11.0.7)
    MacOSx: Ammonite Repl 2.2.0 (Scala 2.13.3 Java 9)

    These were just randomly installed on these computers.

    Philipp Dörfler
    @phdoerfler

    Hi! Given:

    def mkParam(p: Param): Term.Param = q"${p.value}: String"

    and

    for {
    …
        params   = matched.params.map(mkParam)
    } yield q"def $name($params): Response = client.$method($path)"

    I run into two issues:

    error: type mismatch;
     found   : meta.Term.Ascribe
     required: scala.meta.Term.Param
    def mkParam(p: Param): Term.Param = q"${p.value}: String"
                                        ^

    and

    error: type mismatch when unquoting;
     found   : List[scala.meta.Term.Param]
     required: scala.meta.Term.Param
      } yield q"def $name($params): Response = client.$method($path)"
                          ^

    I did not find documentation about how to construct interpolated quasi quote strings to create parameter lists for def and how to create Parameters in general. How do I do this and/or where in the documentation is this?

    Ólafur Páll Geirsson
    @olafurpg
    @phdoerfler
    what happens if you do param"${p.value}: String" instead of q"${p.value}: String"?
    Philipp Dörfler
    @phdoerfler
    I can do that? O.o
    Ólafur Páll Geirsson
    @olafurpg
    This compiles
    @ def mkParam(p: Term.Name): Term.Param = param"${p}: String"
    Philipp Dörfler
    @phdoerfler
    oh wow I had no idea, yeah it does
    thanks! That leaves me with the other problem, still
    error: type mismatch when unquoting;
     found   : List[scala.meta.Term.Param]
     required: scala.meta.Term.Param
      } yield q"def $name($params): Response = client.$method($path)"
                          ^
    Ólafur Páll Geirsson
    @olafurpg
    @ val params = List(param"a: Int", param"b: String")
    params: List[Term.Param] = List(
      Term.Param(List(), Term.Name("a"), Some(Type.Name("Int")), None),
      Term.Param(List(), Term.Name("b"), Some(Type.Name("String")), None)
    )
    
    @ q"def foo(..$params) = a".syntax
    res7: String = "def foo(a: Int, b: String) = a"
    add .. before $params
    Philipp Dörfler
    @phdoerfler
    most excellent @olafurpg thanks a lot! I feel like I missed some essential part in the documentation
    Ólafur Páll Geirsson
    @olafurpg
    Those references are quite dense
    Philipp Dörfler
    @phdoerfler
    sometimes, I am too :P
    ah, yes, I see it now. Thanks again! Seems that the documentation was meant to be read slightly different than how I browsed it
    Philipp Dörfler
    @phdoerfler
    image.png
    OK, so, how do I construct a Term.Name using string interpolation? When I do this, all I get is a Stat
    method: Term.Name = q"${someString.toLowerCase}" is what I do

    I also, in my neverending wisdom, tried adding <>:

    error: type mismatch when unquoting;
     found   : String
     required: scala.meta.Term.Name
        method: Term.Name   = q"<${someString.toLowerCase}>"

    to no avail.

    error: type mismatch;
     found   : scala.meta.Stat
     required: scala.meta.Term.Name
        method: Term.Name   = q"${someString.toLowerCase}"
    oh, I see it now. The example doesn't actually have a $ sign. Oh my
    Guess I have to create them manually
    Ólafur Páll Geirsson
    @olafurpg
    Term.Name(String)
    There are some cases where you can interpolate a string and it's interpreted as a term name
    but it's usually simplest to use Term.Name(String) if you know you need a term name
    Philipp Dörfler
    @phdoerfler
    I see. Yeah, Term.Name(String) is what I have been using so far. I was just curious since the table in the docs makes it look like q"" can (reliably) be used for this
    I gotta say scalameta is really cool and it's fun to use :)
    Ólafur Páll Geirsson
    @olafurpg
    you can construct literal term names with quasiquotes
    q"a" becomes Term.Name("a")
    Ólafur Páll Geirsson
    @olafurpg
    I added a note in the quasiquote spec about using Term.Name when interpolation is needed scalameta/scalameta@4e5dabd
    Ólafur Páll Geirsson
    @olafurpg
    @urbanchr the issue appears to be caused by this line in Ammonite where it adds scalameta 4.3.20 to the classpath by default https://github.com/lihaoyi/Ammonite/blob/master/build.sc#L205
    urbanchr
    @urbanchr
    @olafurpg: Thanks a lot for digging into that.