Re: [go-nuts] Re: couldn't print numbers ordered with goroutine

2024-04-20 Thread 'Dan Kortschak' via golang-nuts
On Sun, 2024-04-21 at 15:06 +1200, Justin Israel wrote:
> And really I wasn't even commenting on the nature of the channel.
> Only the scheduling of the goroutines. Buffered or not, they would
> still be random order right? 

Absolutely. Your answer was spot on. The issue is the ordering of the
goroutines' execution, not the behaviour of channels. I just wanted to
clarify the comment that responsed to that.

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7d71acf0bcf19fbf2ddb5264485f328e08f323fa.camel%40kortschak.io.


Re: [go-nuts] Re: couldn't print numbers ordered with goroutine

2024-04-20 Thread Justin Israel
On Sun, Apr 21, 2024, 2:07 PM 'Dan Kortschak' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> On Sat, 2024-04-20 at 18:55 -0700, Robert Solomon wrote:
> > channels are not queues, as Justin said
>
> They can be; buffered channels are queues.
>
> From https://go.dev/ref/spec#Channel_types
>
> > Channels act as first-in-first-out queues. For example, if one
> > goroutine sends values on a channel and a second goroutine receives
> > them, the values are received in the order sent.



And really I wasn't even commenting on the nature of the channel. Only the
scheduling of the goroutines. Buffered or not, they would still be random
order right?


>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/oMFIFDi_Irg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/05501e4c795fdcb4b91ffa3c35f95984772c9cde.camel%40kortschak.io
> .
>

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAPGFgA2xbShBJNd1Sg2BOOsN%2BtU0050PcbDiGtOCNULsQG%3Dwig%40mail.gmail.com.


Re: [go-nuts] compiling go-1.22.2 and go-1.21.9 fail due to timeout during test of net/http package

2024-04-20 Thread Ian Lance Taylor
On Sat, Apr 20, 2024 at 7:34 PM Ron Hermsen  wrote:
>
> compiling go-1.22.2 and go-1.21.9 fail due to timeout during test of net/http 
> package
>
> I tried a number of earlier releases but looks only the latest two fail.
> (each build takes about 40min, so didn't try more options)
>
> 
> ok  net 8.598s
> panic: test timed out after 9m0s
> running tests:
> 
> FAILnet/http540.260s
> 
> FAIL
> go tool dist: Failed: exit status 1
>
>
> system details:
> TinyCoreLinux, CorePlus64-15.0
>
> $ uname -a
> Linux testapps 6.6.8-tinycore64 #666 SMP Sat Dec 23 16:41:21 UTC 2023 x86_64 
> GNU/Linux
>
> Both source version and the bootstrap are 1.22.2 (or both are 1.21.9).
>
> Tried source version 1.22.2 and bootstrap version 1.22.0 which failed the 
> net/http package the same way.


I don't know why the tests are taking so long on your system, but your
Go distribution is installed and working.  It is only failing during
the testing phase.

To explore what is happening with net/http, try running "go test
-test.short -test.v net/http".  On my laptop it takes just a few
seconds.  Using -test.v may show which test is hanging.

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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWhdXE%3DhC5RHyTfsnJ3PqPwpqqjetwDrKZKpTE%3DptjruA%40mail.gmail.com.


[go-nuts] compiling go-1.22.2 and go-1.21.9 fail due to timeout during test of net/http package

2024-04-20 Thread Ron Hermsen
compiling go-1.22.2 and go-1.21.9 fail due to timeout during test of 
net/http package

I tried a number of earlier releases but looks only the latest two fail.
(each build takes about 40min, so didn't try more options)


ok  net 8.598s
panic: test timed out after 9m0s
running tests:

FAILnet/http540.260s

FAIL
go tool dist: Failed: exit status 1


system details:
TinyCoreLinux, CorePlus64-15.0

$ uname -a
Linux testapps 6.6.8-tinycore64 #666 SMP Sat Dec 23 16:41:21 UTC 2023 
x86_64 GNU/Linux

Both source version and the bootstrap are 1.22.2 (or both are 1.21.9).

Tried source version 1.22.2 and bootstrap version 1.22.0 which failed the 
net/http package the same way.

build output 
1 of 2: https://pastebin.com/tGwUvvJ6
2 of 2: https://pastebin.com/2yZvZapp

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/387b9cd3-c2d5-4006-9180-8510af14356fn%40googlegroups.com.


Re: [go-nuts] Re: couldn't print numbers ordered with goroutine

2024-04-20 Thread 'Dan Kortschak' via golang-nuts
On Sat, 2024-04-20 at 18:55 -0700, Robert Solomon wrote:
> channels are not queues, as Justin said

They can be; buffered channels are queues.

>From https://go.dev/ref/spec#Channel_types

> Channels act as first-in-first-out queues. For example, if one
> goroutine sends values on a channel and a second goroutine receives
> them, the values are received in the order sent. 

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/05501e4c795fdcb4b91ffa3c35f95984772c9cde.camel%40kortschak.io.


[go-nuts] Re: couldn't print numbers ordered with goroutine

2024-04-20 Thread Robert Solomon
channels are not queues, as Justin said

On Saturday, April 20, 2024 at 8:18:18 PM UTC-4 Justin Israel wrote:

> On Sunday, April 21, 2024 at 11:18:24 AM UTC+12 Taňryberdi Şyhmyradow 
> wrote:
>
> Hello guys,
> For the following lines, I wanted to print numbers in ordered, but 
> couldn't. Could you please help me and explain the reason
> Thanks in advance
>
> ```
> numbers := []int{1, 2, 3, 4, 5}
>
> // Create a buffered channel to handle multiple values
> printed := make(chan int, len(numbers))
>
> for _, n := range numbers {
> fmt.Println("Sending", n, "to the channel")
> go func() {
> printed <- n
> }() // Pass the value of n by copying it
> }
>
> // Receive all values from the channel in a loop
> for i := 0; i < len(numbers); i++ {
> fmt.Println(<-printed)
> }
> ```
>
>
> When you start a bunch of goroutines in a loop, there is no guarantee as 
> to what order the scheduler will start each one. 
> Thus you will see them delivered in different orders on each run. You have 
> to decide on some form of synchronization. Maybe you choose to run a single 
> goroutine worker that will loop over the source slice, and push the values 
> into the channel in order. Or maybe you will keep using many goroutines but 
> collect them all in the receiver, sort them after the last value is 
> received, and then print them out. Or, maybe your receiver will have some 
> kind of buffering where it collects values and only prints them when it has 
> the next one in sequence. 
>
>
>
> -- 
> Tanryberdi Shyhmyradov
>
>

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2b4dcdb7-28fc-46e1-90c2-7c01aeac1e44n%40googlegroups.com.


[go-nuts] Re: couldn't print numbers ordered with goroutine

2024-04-20 Thread Justin Israel


On Sunday, April 21, 2024 at 11:18:24 AM UTC+12 Taňryberdi Şyhmyradow wrote:

Hello guys,
For the following lines, I wanted to print numbers in ordered, but 
couldn't. Could you please help me and explain the reason
Thanks in advance

```
numbers := []int{1, 2, 3, 4, 5}

// Create a buffered channel to handle multiple values
printed := make(chan int, len(numbers))

for _, n := range numbers {
fmt.Println("Sending", n, "to the channel")
go func() {
printed <- n
}() // Pass the value of n by copying it
}

// Receive all values from the channel in a loop
for i := 0; i < len(numbers); i++ {
fmt.Println(<-printed)
}
```


When you start a bunch of goroutines in a loop, there is no guarantee as to 
what order the scheduler will start each one. 
Thus you will see them delivered in different orders on each run. You have 
to decide on some form of synchronization. Maybe you choose to run a single 
goroutine worker that will loop over the source slice, and push the values 
into the channel in order. Or maybe you will keep using many goroutines but 
collect them all in the receiver, sort them after the last value is 
received, and then print them out. Or, maybe your receiver will have some 
kind of buffering where it collects values and only prints them when it has 
the next one in sequence. 



-- 
Tanryberdi Shyhmyradov

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ae085bdf-544f-4958-b85f-e36dcaea8ca7n%40googlegroups.com.


[go-nuts] couldn't print numbers ordered with goroutine

2024-04-20 Thread Taňryberdi Şyhmyradow
Hello guys,
For the following lines, I wanted to print numbers in ordered, but
couldn't. Could you please help me and explain the reason
Thanks in advance

```

numbers := []int{1, 2, 3, 4, 5}

// Create a buffered channel to handle multiple values
printed := make(chan int, len(numbers))

for _, n := range numbers {
fmt.Println("Sending", n, "to the channel")
go func() {
   printed <- n
}() // Pass the value of n by copying it
}

// Receive all values from the channel in a loop
for i := 0; i < len(numbers); i++ {
fmt.Println(<-printed)
}

```


-- 
Tanryberdi Shyhmyradov

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAK-WaRiONRf5p3XaxExXh7m6fh4ZXE6U9HuRr%3DxiP9Z2NZeMAQ%40mail.gmail.com.


Re: [go-nuts] why math.Pow gives different results depending on exp type

2024-04-20 Thread Dominik Honnef
Also, Staticcheck catches this:

$ curl -Os https://go.dev/play/p/oIKGb_uyLb3.go
$ staticcheck oIKGb_uyLb3.go 
oIKGb_uyLb3.go:9:38: the integer division '1 / 13' results in zero (SA4025)

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/87cyqkm409.fsf%40honnef.co.


Re: [go-nuts] why math.Pow gives different results depending on exp type

2024-04-20 Thread Kurtis Rader
This has nothing to do with the math.Pow function. Dividing two ints (1/13)
is not the same as dividing a float by an int (1.0/13). Replace your two
`fmt.Printf()` calls with

   println(1 / 13)
   println(1.0 / 13)

and observe the difference. The fact that both `math.Pow` arguments are of
type `float64` does not affect the division operator. It only causes the
result of the division to be coerced to a `float64` if possible. See
https://go.dev/ref/spec#Conversions.

On Fri, Apr 19, 2024 at 10:52 PM DrGo  wrote:

> ```
> package main
>
> import (
> "fmt"
> "math"
> )
>
> func main() {
> fmt.Printf("%g\n", 1-(math.Pow(0.6, 1/13)))   //result=0
> fmt.Printf("%g\n", 1-(math.Pow(0.6, 1.0/13))) //
> result=0.038532272011602364
> }
> ```
> https://go.dev/play/p/oIKGb_uyLb3
>
> --
> 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 on the web visit
> https://groups.google.com/d/msgid/golang-nuts/245517a8-37f9-4ad4-bc42-a1204beb723fn%40googlegroups.com
> 
> .
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD__eo%2B2PV8_LZYK4Z-%3Dhi_tKor1s2jomAMWPXWdcr%2BaLg%40mail.gmail.com.


Re: [go-nuts] why math.Pow gives different results depending on exp type

2024-04-20 Thread 'Dan Kortschak' via golang-nuts
On Fri, 2024-04-19 at 22:51 -0700, DrGo wrote:
> ```
> package main
> 
> import (
>   "fmt"
>   "math"
> )
> 
> func main() {
>   fmt.Printf("%g\n", 1-(math.Pow(0.6, 1/13)))   //result=0
>   fmt.Printf("%g\n", 1-(math.Pow(0.6, 1.0/13))) //
> result=0.038532272011602364
> }
> ```

1/13 is 0 since both parts of the expression are int, and so it
truncates. After this, it is converted to 0.0. So you have 0.6^0 which
is 1.

https://go.dev/play/p/tq2VAPIWXCy

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/57f6740ba2d3e8df8fd4e30402eabb241a6af81b.camel%40kortschak.io.