Perplexing error

107 views
Skip to first unread message

P Padil

unread,
Sep 9, 2024, 3:25:10 PMSep 9
to golan...@googlegroups.com
Can someone please explain to me why the following doesn’t work:

slices.SortFunc(ilps, func(u, w *big.Int) int { return u.Cmp(w) })

I get:
slices.SortFunc(ilps, (func(u, w *big.Int) int literal)) (no value) used as value

Much appreciated!

Regards,
Pete

Jan Mercl

unread,
Sep 9, 2024, 3:32:54 PMSep 9
to P Padil, golan...@googlegroups.com
On Mon, Sep 9, 2024 at 9:24 PM P Padil <ppad...@gmail.com> wrote:

> Can someone please explain to me why the following doesn’t work:
>
> slices.SortFunc(ilps, func(u, w *big.Int) int { return u.Cmp(w) })
>
> I get:
> slices.SortFunc(ilps, (func(u, w *big.Int) int literal)) (no value) used as value

Providing a complete, self-contained, runnable code help others to help you.

Without that I can only guess: you have used the non-value, as
indicated by the error message, as a RHS in an assignment. But its
signature shows it does not return any value:
https://pkg.go.dev/slices#SortFunc

tl;dr: SortFunc sorts the underlying array of the argument slice but
it does not return the slice.

P Padil

unread,
Sep 9, 2024, 3:48:37 PMSep 9
to Jan Mercl, golan...@googlegroups.com
Got it. I missed that the signature of the SortFunc does not include a return value. Thanks!
Reply all
Reply to author
Forward
0 new messages