Re: [go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread 'Daniel Lepage' via golang-nuts
On Tue, Dec 6, 2022 at 10:29 PM hey...@gmail.com wrote: > > sorts defined by an ordering function purely dependent on the value of > the element > > Hmm, I thought the function was agnostic to what really get compared? If > it offers two index numbers, and the return value says the one with large

[go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread hey...@gmail.com
Reversing and then using the stable sort sounds like an elegant solution. Thanks! @Robert I totally missed the indexes could refer to swapped items. I somehow had the impression that go would memorize the returned order and swap them in one go. This explains it. Thanks a lot. On Wednesday, D

[go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread Andrew Harris
> In my real code I have other criteria to compare the slice items, but if they tie, I want to use the reverse of their original order. Oh, forgot to say: FWIW - I think reversing and then sort.SliceStable might be a solution - asymptotically reverse should be less complex than the sort, or pro

Re: [go-nuts] Re: Why not tuples?

2022-12-06 Thread Diogo Baeder
That was perfectly put, Daniel, thanks! :-) And, indeed, what I've been doing is to unmarshal as a "[][]any" and then coercing to the right types. I also agree tuples have a place in the world. They're quite common when dealing with tabular data - for example, to reduce the amount of repetition

[go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread Andrew Harris
Just as an intuitive argument, we could do: sort.Slice(s, func(i, j int) bool { log.Println(i, j); return i > j }) The appearances of i and j per step recapitulate the logic of the sorting algo in some weak sense; not slice order On Tuesday, December 6, 2022 at 7:28:39 PM UTC-8 hey...@gmail.com w

Re: [go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread Robert Engels
If you compare indexes then the elements are swapped you have messed up the order. Imagine the first comparison is 0,15 - you have now swapped those elements - there is no guarantee what order the elements are compared in. The index passed in is simply to look up the element. I am supposed th

[go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread hey...@gmail.com
> sorts defined by an ordering function purely dependent on the value of the element Hmm, I thought the function was agnostic to what really get compared? If it offers two index numbers, and the return value says the one with larger index number should be at the front, shouldn't the sort functi

[go-nuts] Re: glog - Security Vulnerability Report

2022-12-06 Thread peterGo
Please follow the Go Security Policy: https://go.dev/security/policy All security bugs in the Go distribution should be reported by email to secur...@golang.org. This mail is delivered to the Go Security team. On Tuesday, December 6, 2022 at 6:44:37 PM UTC-5 Marco Arboleda wrote: > Good after

Re: [go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread hey...@gmail.com
I do want to compare indexes. Is that something possible to do? In my real code I have other criteria to compare the slice items, but if they tie, I want to use the reverse of their original order. I expect `return i > j` to put items with larger index numbers at the front, why that doesn't see

[go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread Andrew Harris
Oh, to reverse by index ... I think this doesn't quite fit in the idea of sorts defined by an ordering function purely dependent on the value of the element. I think there may have been a feature request for a `slices.Reverse` function in golang.org/

Re: [go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread Eric Hubbard
sort.Slice(s, func(i, j int) bool { return i > j }) You are comparing the indexes and not the values -Eric http://www.google.com/profiles/eric.hubbard On Tue, Dec 6, 2022 at 6:45 PM Andrew Harris wrote: > Subtly: > return s[i] > s[j] > > Is the right sort func > > I think it'd be recomme

[go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread hey...@gmail.com
Thanks for the quick reply. But that seems to compare values. I'd like to compare index numbers. The fact that original values follow index number order is a coincidence. > I think it'd be recommended to look at the generics slices package, which also has a sort Do you mean golang.org/x/exp/sl

[go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread Andrew Harris
Subtly: return s[i] > s[j] Is the right sort func I think it'd be recommended to look at the generics slices package, which also has a sort On Tuesday, December 6, 2022 at 6:39:29 PM UTC-8 hey...@gmail.com wrote: > Hi, > > I have this very simple sorting code: > > s := make([]int, 0, 10

[go-nuts] Why this simple sorting code doesn't work?

2022-12-06 Thread hey...@gmail.com
Hi, I have this very simple sorting code: s := make([]int, 0, 100) for i := 1; i <= 20; i++ { s = append(s, i) } sort.Slice(s, func(i, j int) bool { return i > j }) log.Print(s) I expect it to print numbers in reverse order, since items with larger index numbers should be at the front. Howe

[go-nuts] glog - Security Vulnerability Report

2022-12-06 Thread Marco Arboleda
Good afternoon, My company is using the glog library as a dependency in some of our code. However, one of my pipelines for a project I'm working on started failing today. It was due to a security issue flagged by our static code analysis tool. The relevant lines

Re: [go-nuts] Re: Why not tuples?

2022-12-06 Thread 'Daniel Lepage' via golang-nuts
On Sat, Dec 3, 2022 at 11:34 PM burak serdar wrote: > > > On Sat, Dec 3, 2022 at 8:47 PM Diogo Baeder wrote: > >> Now, imagine this scenario: I have a web application which has to access >> a webservice that responds with JSON payloads; These payloads are a list of >> values, where each value is

[go-nuts] Interfaces for nested types with common structure

2022-12-06 Thread 'Daniel Lepage' via golang-nuts
Hi everyone, I am trying to figure out if there's a good way to build a helper that can be used against different sets of nested types that have a common structure. So, for example, say there are two libraries, `lib1` and `lib2` and both define types Foo, Bar, and Baz with: type Foo struct { ...

Re: [go-nuts] Re: Why not tuples?

2022-12-06 Thread Roman Kuprov
I might be missing something, but you can just iterate over your list of structs and delete/set-to-default-value the offending field before shipping it to your client. Same as tuples afaic. On Monday, December 5, 2022 at 8:39:17 PM UTC-7 diogo...@gmail.com wrote: > Hi folks, > > Thanks for all

[go-nuts] [security] Go 1.19.4 and Go 1.18.9 are released

2022-12-06 Thread announce
Hello gophers, We have just released Go versions 1.19.4 and 1.18.9, minor point releases. These minor releases include 2 security fixes following the security policy : - os, net/http: avoid escapes from os.DirFS and http.Dir on Windows The os.DirFS functi

[go-nuts] Re: HTTPS proxy issue using CONNECT method

2022-12-06 Thread Mauro Monteiro
Hello Graham Thanks a lot for your explanation ! I really appreciate. Mauro On Tuesday, December 6, 2022 at 7:58:01 AM UTC gbarr wrote: > Hi Mauro, > > In your curl examples the CONNECT method was used in both cases because > you forced it to with the --proxytunnel option. If you run those s