I would nevertheless like to understand the flow for developing a program, especially using the worksheet. I suspect, now, that part of my problems are simply the limitations of IntelliJ, but my inability to understand when IntelliJ is just wrong. Here’s an example. I refactored the package/object/class as per the suggestions in this thread.
package theg
import scala.collection.immutable
import scala.Function.const
object graph {
case class Graph[A](Vertices: List[A], Edges: List[(A, A)]) {
val vertexSet = Vertices.toSet
type Edge = (A, A)
type Matching = Set[Edge]
def isMatching(edges: Matching): Boolean = {
// This is a function for testing, to make sure machings have been calculated correctly.
// To test whether the Set of edges is a matching,
// we make sure that it is in fact a subset of the graph Edges,
// and also it has no duplicates among its src and dst A objects
val verticesOfEdges: Set[A] = edges.foldLeft(Set[A]()) {
(acc: Set[A], edge: Edge) => acc.union(Set(getSrc(edge), getDst(edge)))
}
edges.subsetOf(Edges.toSet) && 2 * edges.size == verticesOfEdges.size
}
... the rest omitted
The I updated the worksheet as follows:
import Function._
import theg.graph._
def f(src:Int,edges:List[(Int,Int)]):(Int,List[Int]) = {
(src, edges.map(_._2))
}
val x1 = tupled(f _)
//val y1 = untupled(x1 _)
val g = Graph(List(1, 2, 3, 4), List((3,4), (4,3), (2,1), (3,2), (1, 2), (1, 3), (2, 3), (1,4), (2,4)))
println("" + g.findPath(4, g.testPath,const(false)))
val h = Graph(List(1,2,3,4,5,6,7,8),
List((1,2),(1,7),
(2,3),(2,4),
(3,4),(3,5),(3,7),
(4,8),
(5,6),(5,8),
(6,7),(6,8)))
h.findMaximumMatching(Set())
When I tried to evaluate the worksheet, I got an error (sorry I don’t remember the exact message) to the effect that it is unable to evaluate graph
in theg.graph._
. Sigh
so after I closed it up for the day, deciding have a fresh look tomorrow. The next day, I git-pulled my code from my office computer, and IT WORKS PERFECTLY. I think there’s something in the IntelliJ environment which is confused, because I’m not managing any of the IntelliJ bookkeeping files in git.
Moral of the story, there are lots and lots of magical things that need to work together, and it’s pretty difficult to understand. And when it doesn’t work, distinguishing tool issues, from novice mistakes is also not so easy.