不正确的函数声明语法错误:意外的cornerFinder,期望(

不正确的函数声明语法错误:意外的cornerFinder,期望(

问题描述:

I receive this error when I try to run this code: syntax error: unexpected cornerFinder, expecting (

case "-v2":
        func cornerFinder(censusData []CensusGroup) {
            if len(censusData) <= 10000{
                for i := 0; i <= 10000; i++ {
                    if (censusData.latitude > maxLat){
                        maxLat = censusData.latitude
                    }
                    if (censusData.latitude < minLat){
                        minLat = censusData.latitude
                    }
                    if (censusData.longitude > maxLong){ 
                        maxLong = censusData.longitude
                    }
                    if (censusData.longitude < minLong){
                        minLong = censusData.longitude
                    }
                }    
            }
            mid := len(data)/2
            done := make(chan bool)
            go func() {
                cornerFinder(censusData[:mid])
                done<- true
            } ()
            cornerFinder(censusData[mid:len(censusData)])
            <-done
            return
        }
        cornerFinder(censusData)

Its giving this error on the second line of the code:

func cornerFinder(censusData []CensusGroup) {

I think it something trivial that I am missing. Been stuck on it for a couple of hours. Help would be appreciated

Function declarations are only allowed at top level. Assign a function literal to a local variable instead.

    var cornerFinder func(censusData []CensusGroup)
    cornerFinder = func(censusData []CensusGroup) {
       ... function body from the question
    }
    cornerFinder(censusData)

A short variable declaration is not used here because the function calls itself recursively.