gopherdata / gophernotes

The Go kernel for Jupyter notebooks and nteract.
MIT License
3.82k stars 265 forks source link

variadic parameter must be of unnamed slice type #135

Closed hlalibe closed 6 years ago

hlalibe commented 6 years ago

Struggling with the following code (which i simplified), Error is on line: book_up_data = append(book_up_data, stringup) If i comment it out, works ok. Error message is: types.NewSignature: variadic parameter must be of unnamed slice type

//create empty slice for up data
var book_up_data plotter.Values

//read 60 rows of up data and append together in slice
j := 1
for j <= 60 {
    stringup, err := strconv.ParseFloat(df[i+j-1][16], 64)
    if err != nil {
        panic(err)
    }
    book_up_data = append(book_up_data, stringup)

    //move to next row
    j = j + 1
}

I've researched the topic of variadic parameters and unnamed slice type and tried to change the definition of book_up_data, but no results. The overall code is meant to prepare data to produce a chart. df is created by reading the content of an excel file, works nicely. No error messages when running program from terminal.

sbinet commented 6 years ago

does it work if you replace it with:

book_up_data = append(book_up_data, plotter.Value{stringup}...)
hlalibe commented 6 years ago

I then get for that same line: repl.go:11:41: not a type: plotter.Value <*ast.SelectorExpr>

hlalibe commented 6 years ago

Just realised, you missed the s I think at the end of plotter.Values. So if I use book_up_data = append(book_up_data, plotter.Values{stringup}...) then i get the same error as my first post: types.NewSignature: variadic parameter must be of unnamed slice type

SpencerPark commented 6 years ago

I think this is a gomacro bug so I'll bring @cosmos72 into the discussion here.

Using a type around a slice with variadic signatures is not allowed by types. See types.NewSignature.

The following doesn't work:

type T []float64
var t T
append(t, 1.0)

where as this does

type T []float64
- var t T
+ var t []float64
append(t, 1.0)
cosmos72 commented 6 years ago

Thanks for the extremely short code showing the problem, it made fixing it much easier :)

hlalibe commented 6 years ago

thanks @cosmos72 , it's working fine on my side now.