I’ve currently put together the following code that does recognise elements and allegedly add them to the set but when I print out the set the set is filled with functions
class PropositionOrderer extends Identity{
var Names = SortedSet[Name] _
override def variable = {
_ match {
case name =>
Names+(name)
Variable(name)
}
}
}
I want to then call it on a proposition and get the sorted list of names in the proposition
type Names = SortedSet[Name]
val Names = SortedSet[Name] _
def vars: Proposition => Names =
{
case p =>
val prop = new PropositionOrderer
prop.visit(p)
println(prop.Names)
//this just to fit the return definition
Names("Dan","Web")
}
If I return prop.Names it says that I’m returning an object of the wrong type. Any ideas?
There are several problems here. I will list a few. Correcting these should get you on track.
First, you defining
Namesin two different ways, which is no good. It looks like you meant for it to be a type, so stick with that.Next, if you want to define a new, empty
SortedSet, the syntax is as below. (Note that variable names should always be lowercase. Uppercase is reserved for type names.)Third, if you want to add something to the
Set, you have to use+=, otherwise the existing set doesn’t change.