Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Li Haoyi
    @lihaoyi
    :p
    maybe send a pr showing what it would look like and what use cases it would allow?
    Oron Port
    @soronpo
    It can be used for linting like this (along with singleton-ops)
    class Foo
    def foo[N](implicit n : sourcecode.Name.Aux[N], r : Require[SubString[N, 3]=="foo", "variable name must begin with 'foo'"]) : Foo = new Foo
    
    val foo1 = foo() //OK
    val goo1 = foo() //Compile-time fail: variable name must begin with 'foo'
    Additionally, I can create custom naming compositions to occur at compile-time, instead of run-time.
    Nick Childers
    @Voltir
    er, has anyone seen this error before: could not find implicit value for parameter name: sourcecode.Name
    erp, nevermind
    was 2.12.5 macro death - upgrading to 2.12.6 fixed it
    Oron Port
    @soronpo

    @lihaoyi, consider the following:

    abstract class Foo(implicit n : sourcecode.Name) {
      def getName = n.value
    }
    val wrapper : Foo = {
      println(new Foo{}.getName)
      new Foo{}
    }
    println(wrapper.getName)

    This will print

    wrapper
    wrapper

    Is it possible to modify the macro so it would print:

    $anon
    wrapper

    ?

    Ólafur Páll Geirsson
    @olafurpg
    @soronpo I think the owner chain is identical for those two
    Oron Port
    @soronpo
    It is, as far as I can tell. Is there no way to know which is the last expression (in the block)?
    Matthew Tovbin
    @tovbinm
    Howdy, I am trying to get a handle on the class name for lambda functions like this Seq(1, 2, 3).map(x => x + 1).map(x => x / 2). In Scala 2.11.x it becomes class anonfun$1 which is super ugly.
    I would like to have the generated class name to be a bit nicer. Say MyAppFunL1C20 meaning file MyApp.scala + Line 2 + Column 20.
    I believe it's not currently possible to do with sourcecode library, so my question is - is it valuable enough to have in a library? or should I try writing my own macro for it?
    Oron Port
    @soronpo
    I think this is very application specific
    You can have an implicit that gets both name and location and in your application you implement the mechanism if (x.name.value.contains("$")) ...
    Matthew Tovbin
    @tovbinm
    I would like to be able to serialize a sequence of lambda transformations and it seems to be possible now with scala 2.11.x just by just serializing the class names anonfun$1, anonfun$23, anonfun$41 etc, and then using reflection to insatiate classes.
    the problem that these classes are fragile to code changes and do not uniquely identify the actual function in the user's code.
    This message was deleted
    Wojtek Pituła
    @Krever
    Hey all, I would like to extract a method body (source code) or body of a code block (both are fine). I think its not possible with current impl (Text captures last expression in the block). It feel like something relatively easy but I cant really figure out how to approach this. I looked ad Text macro implementation but its not helpful in this case.
    The problematic part is: how to get code for given Tree/Expr.
    Li Haoyi
    @lihaoyi
    @Krever I don't think it's easy to do with the current macro API. Text is meant to do it, but it doesn't (and has bugs apart from that)
    might need to do something aggressive, like re-parse the whole file in the macro and find the piece of text you care about
    Wojtek Pituła
    @Krever
    I have very little experience with macros but I was thinking about having something like def text[T](thunk: =>T) = macro xxxand then rely on rangepos to get relevant part of the file. But this a long shot as I have never done it before and rely only on stuff I heard , so I cant say if it can work
    Li Haoyi
    @lihaoyi
    possible. RangePos didnt work well back in 2.11 and 2.12, but maybe now in 2.13 they’ve fixed all the old issues
    Matt Hicks
    @darkfrog26

    Is this incorrect usage?

    object Test {
      def test()(implicit file: sourcecode.File, line: sourcecode.Line): Unit = {
        println(s"Called from: $file, $line")
      }
    }

    I'm getting [E047] Cyclic Error when I try to use that on Dotty

    Li Haoyi
    @lihaoyi
    looks fine, might be a bug in dotty
    Oron Port
    @soronpo
    @darkfrog26 Maybe in dotty use using instead of implicit
    Matt Hicks
    @darkfrog26
    @soronpo same error
    @lihaoyi has this project not been tested on Dotty?
    Li Haoyi
    @lihaoyi
    you'll need to ask the dotty folks
    Oron Port
    @soronpo
    It's part of the dotty community build. What dotty version are you using?
    Matt Hicks
    @darkfrog26
    @soronpo 0.27.0-RC1
    Oron Port
    @soronpo
    Try the nightly
    You will need to compile sourcecode locally for it
    Matt Hicks
    @darkfrog26
    looks like 3.0.0-M1 was released 11 hours ago
    Oron Port
    @soronpo
    There is a tag. I don't know if it was actually published. I know there were issues with that.
    Matt Hicks
    @darkfrog26
    yeah, apparently publishing failed
    Matt Hicks
    @darkfrog26
    How do I get the class name using sourcecode? I want package.class but there doesn't appear to be any way to get that directly
    I suppose I could use Pkg and FileName, remove .scala from the end of the filename and then concatenate them...
    Matt Hicks
    @darkfrog26
    Any information on when sourcecode will support Scala.js on Dotty?
    Li Haoyi
    @lihaoyi
    FullName?
    Matt Hicks
    @darkfrog26
    @lihaoyi doesn't FullName potentially include method name as well? I'd still have to break it out, right?
    Matt Hicks
    @darkfrog26
    @lihaoyi any idea when a new release will be out supporting Dotty 3.0.0-M1?
    Tobias Roeser
    @lefou
    Please push the latest release tag(s) to github
    Matt Hicks
    @darkfrog26
    why is sourcecode not publishing for Scala.js on 3.0.0-RC1?
    The support for releases on this project is awful. I submitted a ticket at the end of January (com-lihaoyi/sourcecode#100) for a bug in the release and haven't even gotten a response. I guess I'll have to branch the project and do my own release.
    Matt Hicks
    @darkfrog26
    Done! I created a fork (https://github.com/outr/sourcecode) that restructures the directories and added a build.sbt file, and published under my organization: "com.outr" %%% "sourcecode" % "0.2.4" and has support for Scala.js + 3.0.0-RC1
    Darren Bishop
    @DarrenBishop
    hi folks. how do you pass a Name or Line to a macro behind a function that wants to do something with that meta-data
    ?
    Oron Port
    @soronpo
    I don't understand what you are trying to do.
    Darren Bishop
    @DarrenBishop
    nevermind, figured it out. I misread/misunderstood the error message i got
    i am writing a function and macro pair; the function has implicits i.e. Name and Line etc, that i want to propagate to my macro
    all good now though :thumbsup: