On Mon, Jan 20, 2025 at 11:35 AM 'Dan Kortschak' via golang-nuts <golang-nuts@googlegroups.com> wrote: > > On Mon, 2025-01-20 at 10:42 -0800, Ian Lance Taylor wrote: > > Calling append with an empty slice is well defined. Calling min or > > max with an empty slice is not. > > If the only input to min/max were the slice, this would be true, but I > do not think it is in the case that is implemented in the standard > library where the signatures are fn(T, ...T), e.g. s := []int{}; > max(42, s...) is 42.
I would say that this is because the language doesn't provide a way to write what the spec says. The spec says "The built-in functions min and max compute the smallest—or largest, respectively—value of a fixed number of arguments of ordered types. There must be at least one argument." The language doesn't support writing that function declaration. That is, the declaration is not really fn(T, ...T). It's fn(T, T, T, ...) where there must be at least one value. We could change the definition of min/max to permit writing max(42, s...). But today the spec does not permit that. And to me the change doesn't seem worth making. We already have slices.Min and slices.Max. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUCap7wbGnPMNL82_QVrzvZVO_%2BjEo5E10gONCMnxJNMA%40mail.gmail.com.