[go-nuts] cross-compile mac to linux

2018-05-06 Thread Steven Roth
Can anyone point me to a recipe or guidance on how to set up a
cross-compilation environment on a Mac that will allow me to build
CGO-enabled Go code to run on Ubuntu?  The program I'm building is pure Go
except for an unavoidable dependency on libsqlite3.

Thanks in advance,
Steve

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: I don't know about callbacks in Golang

2018-05-06 Thread Juliusz Chroboczek
> Callbacks are rarely used in Go's ecosystem.

https://golang.org/pkg/sort/#Slice
https://golang.org/pkg/sync/#Map.Range

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: [ANN] GoKi Trees and GoGi GUI

2018-05-06 Thread Steven Wiley
It sure does look like you put a great deal of effort into this project. 
Here are a couple of impressions after trying the demos and skimming 
through part of the source code.

First, I had to pull down a lot of other packages in order to get things to 
build. Did you happen to write up a dependency list somewhere? It might be 
helpful to list them in the readme so that fumblers like me won't have to 
do it trail and error. (FYI: I just added the non-standard lib dependency 
list to oksvg and rasterx.) Here are the additional packages I needed for 
gi : 

   - https://github.com/BurntSushi/xgb
   - https://github.com/chewxy/math32
   - https://github.com/go-gl/mathgl
   - https://github.com/goki/prof
   - https://github.com/jinzhu/copier
   - https://github.com/json-iterator/go
   - https://github.com/modern-go/reflect2
   - https://github.com/modern-go/concurrent

Also, I noticed that you need a go version greater than 1.9.4. I was 
getting a "math.Round not found" error until I upgraded to go1.10.2.


So, once I got everything building, I was getting a few font path not found 
errors during runtime. (OS: Fedora 27), but still text was visible. Some 
things worked quite smoothly, like the transition from a simple panel to a 
scrolling panel as a window was resized to smaller than the window 
content.  Other things were not behaving so well, like typing text into a 
text label, and the text would appear in a different location than the 
cursor. More seriously, almost every example I tried would at some point 
would hang and go non-responsive.  I am happy to work with you offline if 
you want to track down some of these problems.


As for looking at the code itself, as other people have mentioned it does 
seem to get a little heavy into use of reflection. Also, the ki package is 
very full featured, with a lot of capabilities built in to the tree nodes, 
like intra-node messaging, attribute maps, and more. So, I will echo some 
other comments here and suggest that you might want to consider letting 
some of those responsibilities fall to an object referenced by the node, 
which might allow simpler nodes to avoid unneeded overhead.


I have been playing around a bit with GUIs also, but decided to base my 
stuff on SDL 2. It looks like you are basing off of  something called shiny 
(golang.org/x/exp/shiny) ? Abstracting away the OS specific layer to make 
an all-platform GUI is a notoriously hard thing to do robustly, and is a 
frequent source of problems, just like intermittent hangups. Even with 
something as well supported as SDL, I was getting an intermittent bug until 
I realized I absolutely need to call runtime.LockOSThread(). Something like 
that might be going on here, and again we can follow up offline if you 
wish, or if you have any questions about using oksvg or rasterx.


cheers,

Steve





On Friday, May 4, 2018 at 3:39:35 AM UTC-7, Randall O'Reilly wrote:
>
> https://github.com/goki/goki — key demo in: 
> https://github.com/goki/goki/tree/master/gi/examples/widgets 
>
> This is the first release of a new Go framework built around the Tree as a 
> core data structure (Ki = Tree in Japanese), which includes as its first 
> application a fully-native Go GUI (built on top of a modified version of 
> the Shiny OS-specific backend drivers, supporting Mac, Linux, and Windows 
> so far). 
>
> Building on the central idea in Go that having a few powerful 
> data-structures is essential for making many problems easier to solve, the 
> GoKi trees are an attempt to provide a powerful tree structure that can 
> support things like scene graphs, DOM’s, parsing trees, etc. 
>
> The GoGi graphical interface system is a kind of “proof is in the pudding” 
> test, which weighs in at under 20k LOC and provides a reasonably 
> full-featured GUI — with a bit more work it should be able to do most of 
> the stuff you can do in Qt, and already includes a (self) reflection-driven 
> GUI designer. 
>
> The overall design is an attempt to integrate existing standards and 
> conventions from widely-used frameworks, including Qt (overall widget 
> design), HTML / CSS (styling), and SVG (rendering). Rendering in SVG is 
> directly supported by the GoGi 2D scenegraph, with enhanced functionality 
> for interactive GUI's. This 2D framework also integrates with a (planned) 
> 3D scenegraph, to support interesting combinations of these frameworks. 
> Currently GoGi is focused on desktop systems, but nothing prevents 
> adaptation to mobile. 
>
> Right now the rendering is based off of a modified version of 
> https://github.com/fogleman/gg, but I’m very interested in integrating 
> the new rasterx system that Steven Wiley recently announced. 
>
> I’d be very interested in people’s impressions, suggestions, etc, and 
> welcome all interested contributors (there’s certainly much more to do) — 
> it would be great if this could provide the start for a widely-supported 
> Go-native GUI framework!  This was my first Go project 

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-05-06 Thread Yuval Lifshitz
seems like math accuracy issues are known, or even, by design. see:
https://github.com/golang/go/issues/9546
https://github.com/golang/go/issues/9545


On Sunday, 6 May 2018 00:05:13 UTC+3, Paul Hankin wrote:
>
> On Friday, 27 April 2018 23:57:42 UTC+2, Michael Jones wrote:
>>
>> Yuval,
>>
>> There are fundamental issues here.
>>
>> 1. That equation (de Moivre, Binet) is from the algebra of ideal numbers. 
>> Numbers of infinite precision. Not the realm of computer arithmetic. It 
>> works fine with double precision (go: float64, c/c++: double) up to F(75) 
>> but must fail for F(76) due to the limited precision of 64-bit floating 
>> point and has nothing to do with language.
>>
>> F(76) = 3416454622906707 but the best we can do in 64 bits is 
>> 3416454622906706 even with a Pow() function good to +/-1 least significant 
>> bit.
>>
>> 2. Another difference between algebra and computer arithmetic 
>> (well...actually about the floor function) is that one of your two power 
>> terms is not needed. Psi < 1 so Psi^N is pretty small, so small, that it 
>> never changes the value of the rounded result. So you can just evaluate:
>>
>> return round(math.Pow(math.Phi, float_n) / sqrt_5)
>>
>
> A neat not-very-well-known trick is to use that phi^n = Fib(n)phi + 
> Fib(n-1). Numbers of the form a*phi+b where a and b are integers are closed 
> under multiplication, so you can compute phi^n exactly using integer 
> arithmetic -- in log(n) arithmetic operations.
>
> https://play.golang.org/p/j4mZ93c820R
>
> -- 
> Paul
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: How to fake os.Stdout in golang for testing?

2018-05-06 Thread Manlio Perillo
Il giorno domenica 6 maggio 2018 06:35:08 UTC+2, Mirko Friedenhagen ha 
scritto:
>
> Hello,
>
> I am trying out golang and like it's concepts (coming from Python and Java 
> mostly, not having Exceptions felt a bit strange at the start, though :-)).
>
> * Now I try to write tests for 
> https://github.com/caradojo/trivia/blob/master/go/trivia.go for the fun 
> of it. 
> * I want to do this without modifying the code (too much).
> * I already introduced my own fake[1] random and now need to replace 
> os.Stdout with a fake implementation as the results of the game implemented 
> here are written with `fmt.Println` resp. `fmt.Printf`.
> * My first approach was to use a tempfile[2], this works but I do not like 
> to touch the disk during tests.
> * In Java `System.out` is just a `PrintStream` which is easily replaced by 
> sth. like `System.setOut(new PrintStream(new ByteArrayOutputStream()));`
> * Now in golang `os.Stdout` is an `*os.File` which is mostly a wrapper for 
> an OS specific file. 
>

For your example code the solution is simple: don't use fmt.Printf, but use 
fmt.Fprintf that accepts an io.Writer instead.  Pass the writer as the 
function argument.

You can also use the log package, but I personally use it *only* to report 
(handled) errors to the terminal or to the log file.

> [...]

Manlio 

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] How to fake os.Stdout in golang for testing?

2018-05-06 Thread alex . rou . sg
The output of text printed with the log as created in my example and fmt 
are exactly the same. 
The only change you would have to make is have a global log var and then do 
a simple search and replace all fmt.Printf to logVar.Printf.

So the only argument you gave for not changing would be not wanting to 
change the original source.
If changing the code is an absolute impossibility then sure the os.Stdout 
redirect makes sense.

On Sunday, 6 May 2018 18:44:10 UTC+8, Mirko Friedenhagen wrote:
>
>
> On Sunday, May 6, 2018 at 8:21:14 AM UTC+2, alex@gmail.com wrote:
>>
>> Or use log instead of fmt
>>
>> var stdout = log.New(os.Stdout, "", 0) 
>>
>> Then you can easily redirect it to any io.Writter like
>>
>> buf := {}
>> stdout = log.New(buf, "", 0)
>>
>
> Hello Alex,
>
> good point, however firstly I do not want to modify the original code. My 
> first goal is to cover it completely with tests. This being a test project 
> for legacy code refactoring, the program *must* always produce the output 
> given here: 
> https://github.com/mfriedenhagen/trivia/blob/master/reference/result.txt.
>
> Regards
> Mirko
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] How to fake os.Stdout in golang for testing?

2018-05-06 Thread mfriedenhagen

On Sunday, May 6, 2018 at 8:21:14 AM UTC+2, alex@gmail.com wrote:
>
> Or use log instead of fmt
>
> var stdout = log.New(os.Stdout, "", 0) 
>
> Then you can easily redirect it to any io.Writter like
>
> buf := {}
> stdout = log.New(buf, "", 0)
>

Hello Alex,

good point, however firstly I do not want to modify the original code. My 
first goal is to cover it completely with tests. This being a test project 
for legacy code refactoring, the program *must* always produce the output 
given here: 
https://github.com/mfriedenhagen/trivia/blob/master/reference/result.txt.

Regards
Mirko

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] How to fake os.Stdout in golang for testing?

2018-05-06 Thread mfriedenhagen
On Sunday, May 6, 2018 at 7:32:47 AM UTC+2, Lars Seipel wrote:
>
> On Sat, May 05, 2018 at 08:55:17AM -0700, mfried...@gmail.com 
>  wrote: 
> > * Now in golang `os.Stdout` is an `*os.File` which is mostly a wrapper 
> for 
> > an OS specific file. 
>
> You can always use os.Pipe to get an actual file descriptor to write to. 
>

Hello Lars,

thanks, I now have 

func dieOn(err error, t *testing.T) {
   if err != nil {
  t.Fatal(err)
   }
}

// Returns output to `os.Stdout` from `runnable` as string.
func catchStdOut(t *testing.T, runnable func()) (string) {
   realStdout := os.Stdout
   defer func() { os.Stdout = realStdout }()
   r, fakeStdout, err := os.Pipe()
   dieOn(err, t)
   os.Stdout = fakeStdout
   runnable()
   // need to close here, otherwise ReadAll never gets "EOF".
   dieOn(fakeStdout.Close(), t)
   newOutBytes, err := ioutil.ReadAll(r)
   dieOn(err, t)
   dieOn(r.Close(), t)
   return string(newOutBytes)
}

I like that better

 

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: fallthrough for select

2018-05-06 Thread Jan Mercl
On Sun, May 6, 2018 at 6:34 AM  wrote:

> ... I feel like any kind of switch-like statements should be able to
fallthrough.

switch x := f.(type) {
case *Foo:
...
falthrough
case *Bar:
x.Baz() // <- What type is 'x' here?
}


-- 

-j

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] I don't know about callbacks in Golang

2018-05-06 Thread Justin Israel
Callbacks are not something that is considered a standard aspect to Go
programming, in the same sense as you might see them in something like
js/Node.js async programming. The fact that you mentioned Web programming
explains why you might have been exposed to the concept, when it is
describing your http handlers (function mapped to urls like  "/hello"). So
it is likely that you won't see too much specific training material on the
topic of "callbacks". But if you are interested in web services, you could
take a look at some of the tutorials on the curated awesome-go site:
https://github.com/avelino/awesome-go#tutorials

If you just want to see a generic example of passing functions as
arguments, to be used as callbacks:
https://play.golang.org/p/IvY3RCpEJvN

Justin


On Sun, May 6, 2018 at 12:49 PM Eduardo Moseis Fuentes 
wrote:

> Thank you to take time to respons me. Specifily I don't have a problem to
> solve in fact the problem is I don't know how the callbacks works. Well my
> goal is to learn golang and all its semantic and after that focus my time
> on  how to program in backend with go.. but I need to learn its semantic
> before,  and my book's name is " Learning-Go-latest " it has a topic named
> callbacks on page 29. I will look more references to learn callbacks or
> golang in general. Do you know about some reference online or offline maybe
> another book wich always is oriented on develop in the scope web Do you
> know if someone would like to have an apprentice?.of before hand thanks.
> God Bless you
>
> sorry by my bad english but I'am lerning too
>
> 2018-05-05 15:55 GMT-06:00 Justin Israel :
>
>> Can you explain what problem you actually want to solve by learning about
>> callbacks? Maybe there is a better learning reference to offer you based on
>> your actual goals.
>>
>> Justin
>>
>>
>> On Sat, May 5, 2018, 12:52 PM Eduardo Moseis Fuentes 
>> wrote:
>>
>>> HI everyone I´m Eduardo from Guatemala and I'm beginer. I'm  interesting
>>> in all scope golang in fact  I was download a little book about it, but I
>>> need learn more about callbacks because the book don´t has enough
>>> information on callbacks. May somebody  tell me where can I  find more
>>> information?. HELP ME PLEASE  THANKS God Bless you
>>>
>>> --
>>> 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.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Possible issue with math.Floor on Linux

2018-05-06 Thread Andrei Avram
Indeed, it was about precision, the issue is with Windows, not with Go. 
I've used only one time.Now call and the planets have aligned.

package main

import (
"time"
"math"
"fmt"
)

func main() {
now := time.Now()

datetime := now.Add(time.Hour * 24 * 7 * 4 * 12 * 3)
seconds := -1 * int(now.Sub(datetime).Seconds())
a := 29030400
x := float64(seconds)/float64(a)

fmt.Println("input:", x, "floor:", math.Floor(x))
}

Result on both systems: input: 3 floor: 3.

Thank you all! 


On Saturday, May 5, 2018 at 7:54:27 AM UTC+3, Andrei Avram wrote:
>
> Yes, this could be it. First I was fooled by println rounding 2.9 to 3, 
> thinking floor is not working properly on Linux.
>
> Thanks!
>
> On Saturday, May 5, 2018 at 1:49:34 AM UTC+3, Steven Hartland wrote:
>>
>> You could be seeing a side effect on fact that windows only ticks every 
>> 15ms.
>>
>> On Fri, 4 May 2018 at 21:56, Andrei Avram  wrote:
>>
>>> This code is extracted from something real. Someone on the team noticed 
>>> the unit tests (which I wrote on a Linux machine) were failing on their 
>>> Windows machine.
>>> I'll continue studying this and come back if I find something new.
>>>
>>> Thank you both for your time, I appreciate it!
>>>
>>>
>>> On Friday, May 4, 2018 at 11:42:00 PM UTC+3, speter wrote:
>>>
 To file a bug (and have it treated seriously) you would need to 
 demonstrate that it is causing problems in a program that actually does 
 something useful, not just a pathological code sample. My expectation 
 would 
 be that once you start doing some real processing, the difference between 
 time.Now() invocations becomes non-zero, that is this "issue" doesn't 
 reproduce with "real" practical programs.


 On Fri, May 4, 2018 at 10:26 PM, Andrei Avram  
 wrote:

> But I don't think it is because Windows is so much faster than Linux
>>
>  
> Yeah... :) I was exploring all cases.
>
>
>  and/or the way the time package implemented is different between 
>> Windows and Linux
>
>
> Could this be considered a possible Go bug and would it worth opening 
> an issue on Github?
>
>
> On Friday, May 4, 2018 at 10:57:46 PM UTC+3, speter wrote:
>>
>> So on Linux it's working as expected. In the playground time is 
>> "virtual"; the start time is fixed and it doesn't progress unless you 
>> explicitly Sleep -- because you don't Sleep in your program, time.Now() 
>> returns the same time on both invocation.
>>
>> So the only slightly surprising part is that on Windows, time as 
>> measured by time.Now() doesn't progress between the two statements. But 
>> I 
>> don't think it is because Windows is so much faster than Linux. :) I'd 
>> guess this is because the way Windows manages time is different from how 
>> Linux manages it, and/or the way the time package implemented is 
>> different 
>> between Windows and Linux. The result of the cross-platform differences 
>> seems to be less precision on Windows -- at least in this specific 
>> scenario.
>>
>> Peter
>>  
>>
>> On Fri, May 4, 2018 at 9:33 PM, Andrei Avram  
>> wrote:
>>
>>> Peter and Ian, you are both wright regarding the printing. Still, on 
>>> Linux I have different values than on Go Playground.
>>>
>>> Regarding the speed, Peter, do you think that on Windows the two 
>>> calls just run faster every time?
>>>
>>> On Friday, May 4, 2018 at 9:07:15 PM UTC+3, speter wrote:

 b is slightly less than 3 because there is a bit of time between 
 the two calls to time.Now().

 If you substitute this:
 fmt.Printf("input: %20.18f\n", b)

 you get something like
 input: 2.99965553350911

 HTH
 Peter

 On Fri, May 4, 2018 at 7:26 PM, Andrei Avram  wrote:

> Hello everyone,
>
> Today I ran into a situation that is strange to me. I ran the 
> following code on two Linux machines (go run floor.go), on two 
> Windows 
> ones, and on Go Playground.
>
> package main
>
> import (
> "time"
> "math"
> )
>
> func main() {
> datetime := time.Now().Add(time.Hour * 24 * 7 * 4 * 12 * 3)
> seconds := -1 * int(time.Now().Sub(datetime).Seconds())
> a := 29030400
> b := float64(seconds) / float64(a)
>
> println("input:", b)
> println("floor:", math.Floor(b))
> }
>
> On Linux the output is:
>
> input: +3.00e+000
> floor: *+2.00e+000*
>
> On Windows and Playground:
>
> input: +3.00e+000
> floor: 

Re: [go-nuts] How to fake os.Stdout in golang for testing?

2018-05-06 Thread alex . rou . sg
Or use log instead of fmt

var stdout = log.New(os.Stdout, "", 0) 

Then you can easily redirect it to any io.Writter like

buf := {}
stdout = log.New(buf, "", 0)


On Sunday, 6 May 2018 13:32:47 UTC+8, Lars Seipel wrote:
>
> On Sat, May 05, 2018 at 08:55:17AM -0700, mfried...@gmail.com 
>  wrote: 
> > * Now in golang `os.Stdout` is an `*os.File` which is mostly a wrapper 
> for 
> > an OS specific file. 
>
> You can always use os.Pipe to get an actual file descriptor to write to. 
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.