Can someone please help me with this code? I’m trying to collect a list of thunks (0-ary functions)
and later iterate over the list and call them. The compiler gives me a very uninformative message: “Not applicable to”, but I don’t know what it is trying to tell me.
I’d like removes
to be a list of objects each of type Unit=>Unit. Isn’t there a way to do this easier than to define an extra function named thunk? Also isn’t there a way to function-call all these functions simply as some clever call to map? removes.map(..some..magic..)
def qmReduce():Unit = {
var maxPosCount:Integer = hash.foldLeft(0){ case (acc, (k, _)) => max(k,acc) }
def loop():Unit = {
var changed = false
var removes:List[Unit=>Unit] = Nil
def addCBF(clause:Clause,posCount:Integer,length:Integer):Unit = {
changed = true
addClause(clause,posCount,length,false,false)
}
def removeCBF(clause:Clause,posCount:Integer,length:Integer):Unit = {
def thunk():Unit = {
removeClause(clause,posCount,length)
}
removes = thunk::removes // <--- compiler says "Not applicable to"
}
for((posCount -> _) <- hash) {
if (posCount < maxPosCount)
reduceOne(posCount,addCBF,removeCBF)
}
for(thunk <- removes)
thunk()
maxPosCount = hash.foldLeft(0){
case (acc, (k, _)) => if (k<maxPosCount) max(k,acc) else acc
}
if (changed)
loop()
}
loop()
}