Scala Meta: Confused about the versions - scala

In the tutorial you find 2 versions for Scala-Meta.
lazy val MetaVersion = "3.7.2"
lazy val MetaVersion1 = "1.8.0"
I am a bit confused as they seem to refer the same project:
lazy val scalameta1 = "org.scalameta" %% "scalameta" % MetaVersion1
lazy val scalameta = "org.scalameta" %% "scalameta" % MetaVersion
Can somebody point out the difference, and when you use which one of these?
The Tutorial only mentions "3.7.2", but with that I got the exception
ERROR: new-style ("inline") macros require scala.meta
explained here: new-style-inline-macros-require-scala-meta

3.7.2 is the current version of scalameta (actually already 3.7.4).
1.8.0 is the last version of scalameta that worked with scalameta macro annotations through scalameta paradise compiler plugin (1 2 3).
So if you need the latest version of scalameta you use 3.7.4. If you need scalameta macros you use 1.8.0.

Related

Working with ReactiveMongo (for play framework apps) in 2020

I'v set up and new project of playframework 2.8, and my dilemmas are:
1. which dependency should I use:
"org.reactivemongo" %% "reactivemongo" % "1.0"
OR
"org.reactivemongo" %% "play2-reactivemongo" // dont even think that there is 1.0 for play 2.8, is it deprecated?
2. up until now I used play-json for serialize/deserialize my objects that I insets or fetch from mongo, for example:
object MongoSerializer {
implicit val InstantFormat = CommonSerializers.InstantSerializers.BSONFormat
implicit val MetadataFormat: OFormat[Metadata] = Json.format[Metadata]
implicit val PairingFormat: OFormat[Pairing] = Json.format[Pairing]
implicit val pairTypeFormat: Format[PairType] = EnumFormats.formats(PairType)
}
and in my dbconfig I used _.collection[JSONCollection], but I remember someone wrote that JSONCollection is about to be deprecated and there will be only support for BSONCollection so I wanted to work with BSONCollection.
so as you can see I'm a bit confused, if there is someone who can help me understand what setup should I use and which serialize/deserialize will go best with it I will appreciate it allot. thanks!
I will go for the first option because some of my result is an aggregation/customization of different collections. Thus, I will have to write custom BSON/JSON converters myself.

Can't get the banana-rdf to work with scalajs

From my understanding I should be able to use the banana-rdf library in my scalajs code? I followed the instructions on the website and added the following to my build.sbt:
val banana = (name: String) => "org.w3" %% name % "0.8.4" excludeAll (ExclusionRule(organization = "org.scala-stm"))
and added the following to my common settings:
resolvers += "bblfish-snapshots" at "http://bblfish.net/work/repo/releases"
libraryDependencies ++= Seq("banana", "banana-rdf", "banana-sesame").map(banana)
It all compiles fine until it gets to the point where it does the fast optimizing. Then I get the following error:
Referring to non-existent class org.w3.banana.sesame.Sesame$
I tried changing Seasame for Plantain but got the same outcome.
Am I missing something?
I was using the "%%" notation which is for a jvm module.
Changed it to "%%%" and it was able to find the correct library.
NOTE. I had to use Plantain as this is the only one currently compiled for scalajs

Simulacrum: macro implementation not found

I've got a simple code in Scala to try simulacrum lib:
import simulacrum._
#typeclass trait Semigroup[A] {
#op("|+|") def append(x: A, y: A): A
}
But this doesn't work. Compiler says
Error:(3, 2) macro implementation not found: macroTransform (the most
common reason for that is that you cannot use macro implementations in
the same compilation run that defines them) #typeclass trait
Semigroup[A] {
What can cause this error?
I do not create a macro, I just reuse an existing one.
My build.sbt file is simple:
name := "Macr"
version := "0.1"
scalaVersion := "2.12.5"
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
libraryDependencies += "com.github.mpilquist" %% "simulacrum" % "0.12.0"
As noted by Oleg Pyzhcov in the comments, macros don't work with Scala 2.12.4 and 2.12.5 when compiling on Java 9 or 10. However, this has been fixed in Scala 2.12.6, so upgrading should solve the problem.

Reproducing Shapeless examples of HList-style operations on standard tuples

I'm very new to Scala, and have been looking at the shapeless package to provide HList-like operations for Scala's tuples.
I'm running scala 2.10.5, and I've successfully installed the package (version 2.2.0-RC6) as well as all dependencies.
When I try to run the following example (from the shapeless feature overview) in the REPL,
scala> import shapeless._; import syntax.std.tuple._
scala > (23, "foo", true).head
I get the following error message:
<console>:17: error: could not find implicit value for parameter c: shapeless.ops.tuple.IsComposite[(Int, String, Boolean)]
(23, "foo", true).head
I'll bet this is a silly error on my part, and I've been digging through a lot of forums on this.
What am I missing?
Thanks in advance for your help.
You're likely missing the macro paradise dependency. Without that, I get the same error you see, with it, the example compiles.
Your build.sbt should include something like this:
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.2.0-RC6",
compilerPlugin("org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full)
)

How do I enable continuations in Scala?

Question says it all.
(Yet, the details of how to get access to the shift and reset operations has changed over the years. Old blog entries and Stack Overflow answers may have out of date information.)
See also What are Scala continuations and why use them? which talks about what you might want to do with shift and reset once you have them.
Scala 2.11
The easiest way is to use sbt:
scalaVersion := "2.11.6"
autoCompilerPlugins := true
addCompilerPlugin(
"org.scala-lang.plugins" % "scala-continuations-plugin_2.11.6" % "1.0.2")
libraryDependencies +=
"org.scala-lang.plugins" %% "scala-continuations-library" % "1.0.2"
scalacOptions += "-P:continuations:enable"
In your code (or the REPL), do import scala.util.continuations._
You can now use shift and reset to your heart's content.
historical information for Scala 2.8, 2.9, 2.10
You have to start scala (or scalac) with the -P:continuations:enable flag.
In your code, do import scala.util.continuations._
You can now use shift and reset to your heart's content.
If you're using sbt 0.7, see https://groups.google.com/forum/#!topic/simple-build-tool/Uj-7zl9n3f4
If you're using sbt 0.11+, see https://gist.github.com/1302944
If you're using maven, see http://scala-programming-language.1934581.n4.nabble.com/scala-using-continuations-plugin-with-2-8-0-RC1-and-maven-td2065949.html#a2065949
Non SBT solution:
scala -Xpluginsdir /.../scala/lib/ -P:continuations:enable
Works on scala 2.11.6, but the plugin/library said that it will no longer be included with Scala 2.12