Re: [go-nuts] Generic function aliases

2018-12-04 Thread messju mohr
Erm, function names may be const, but functions are first class citizen types 
and can of course be assigned to variables and be passed around.

just my 2c

On Tue, Dec 04, 2018 at 10:27:19AM -0800, Liam Breck wrote:
>Ah yes, var works. But it should be const, since func names aren't
>variables.
>On Tue, Dec 4, 2018, 5:40 AM Axel Wagner <[1]axel.wagner...@googlemail.com
>wrote:
> 
>  You can use
>  var Gi = g.G(int)
>  or you can use
>  func Gi(i int) error { return g.G(i) }
>  for the same effect. Which is pretty much the reason why
>  alias-declarations ended up only be added for types - all other
>  declarations can already be emulated sufficiently well. :)
>  On Mon, Dec 3, 2018 at 11:39 PM Liam Breck <[2]l...@networkimprov.net>
>  wrote:
> 
>Type aliases appear in the contracts draft design. Has anyone
>suggested alias declarations for generic functions? This would
>simplify syntax for callers...
>package g
>func G(type T)(i T) error { ... }
>---
>package main
>import "g"
>func Gi g.G(int) // declare alias
>func f() {
>   Gi(1)
>}
> 
>--
>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 [3]golang-nuts+unsubscr...@googlegroups.com.
>For more options, visit [4]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 [5]golang-nuts+unsubscr...@googlegroups.com.
>For more options, visit [6]https://groups.google.com/d/optout.
> 
> References
> 
>Visible links
>1. mailto:axel.wagner...@googlemail.com
>2. mailto:l...@networkimprov.net
>3. mailto:golang-nuts+unsubscr...@googlegroups.com
>4. https://groups.google.com/d/optout
>5. mailto:golang-nuts+unsubscr...@googlegroups.com
>6. 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] [ANN] fixed point math library

2018-11-29 Thread messju mohr
Hello,

this looks like a really nice and useful library! :)

Just one thing: At first glance i saw that fixed.Cmp() returns 0 when both 
operands are NaN.
I think it would be more consistent if fixed.Cmp() would return NaN if any of 
it's operands are NaN.

just my 2ct
messju


On Thu, Nov 29, 2018 at 12:47:05AM -0600, robert engels wrote:
>For those interesting in financial apps, I have released ‘fixed'
>at [1]https://github.com/robaho/fixed a high performance fixed-point math
>library primarily designed for to work with currencies.
>The benchmarks: (Decimal is the shopspring library, big Int/Float are the
>stdlib)
> 
>  BenchmarkAddFixed-8 20   0.83 ns/op  
>   0 B/op  0 allocs/op
>  BenchmarkAddDecimal-8300   457 ns/op 
> 400 B/op 10 allocs/op
>  BenchmarkAddBigInt-81   19.2 ns/op   
>   0 B/op  0 allocs/op
>  BenchmarkAddBigFloat-8  2000   110 ns/op 
>  48 B/op  1 allocs/op
>  BenchmarkMulFixed-8 1   12.4 ns/op   
>   0 B/op  0 allocs/op
>  BenchmarkMulDecimal-8   200094.2 ns/op   
>  80 B/op  2 allocs/op
>  BenchmarkMulBigInt-81   22.0 ns/op   
>   0 B/op  0 allocs/op
>  BenchmarkMulBigFloat-8  300050.0 ns/op   
>   0 B/op  0 allocs/op
>  BenchmarkDivFixed-8 1   19.3 ns/op   
>   0 B/op  0 allocs/op
>  BenchmarkDivDecimal-8100  1152 ns/op 
> 928 B/op 22 allocs/op
>  BenchmarkDivBigInt-8200068.4 ns/op   
>  48 B/op  1 allocs/op
>  BenchmarkDivBigFloat-8  1000   151 ns/op 
>  64 B/op  2 allocs/op
>  BenchmarkCmpFixed-8 20   0.28 ns/op  
>   0 B/op  0 allocs/op
>  BenchmarkCmpDecimal-8   1   10.8 ns/op   
>   0 B/op  0 allocs/op
>  BenchmarkCmpBigInt-828.37 ns/op  
>   0 B/op  0 allocs/op
>  BenchmarkCmpBigFloat-8  27.74 ns/op  
>   0 B/op  0 allocs/op
>  BenchmarkStringFixed-8  200099.0 ns/op   
>  16 B/op  1 allocs/op
>  BenchmarkStringDecimal-8 500   326 ns/op 
> 144 B/op  5 allocs/op
>  BenchmarkStringBigInt-8 1000   209 ns/op 
>  80 B/op  3 allocs/op
>  BenchmarkStringBigFloat-8300   571 ns/op 
> 272 B/op  8 allocs/op
> 
>--
>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 [2]golang-nuts+unsubscr...@googlegroups.com.
>For more options, visit [3]https://groups.google.com/d/optout.
> 
> References
> 
>Visible links
>1. https://github.com/robaho/fixed
>2. mailto:golang-nuts+unsubscr...@googlegroups.com
>3. 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] Re: How to make the first character in a string lowercase?

2018-10-29 Thread messju mohr
I don't know if that is "the easiest", but I would do something like this:
https://play.golang.org/p/DOhP5kc8rO4

On Sun, Oct 28, 2018 at 11:35:33PM -0700, dhananja...@gmail.com wrote:
>https://play.golang.org/p/vFW8NxzL_hv
>this will work fine
>On Saturday, 24 November 2012 16:21:23 UTC+5:30, Nikolai wrote:
> 
>  Hi!
>  What is the easiest way to make a string "LikeThis" --> "likeThis"?

-- 
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: Examples testing with two newline, but only one newline

2018-08-13 Thread messju mohr
Here is a running version that shows the original poster's problem:


On Mon, Aug 13, 2018 at 07:16:08AM -0700, gary.willoug...@victoriaplumb.com 
wrote:
>Your program doesn't work.
> 
>On Saturday, 11 August 2018 09:10:04 UTC+1, 子風 wrote:
> 
>  Hi
>  [1]https://play.golang.org/p/AIB-yJaExVu
>  When I want to use examples to test my code, I find something odd.
>  Example1 could pass, but Example2 failed
> 
>--- FAIL: Example2 (0.00s)
>got:
>hello
>.
> 
>123
>want:
>hello
>.
>123
>FAIL
>exit status 1
> 
>  It seems Examples could only show one newline.
>  Is there a solution to solve it? Thanks
> 
>--
>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 [2]golang-nuts+unsubscr...@googlegroups.com.
>For more options, visit [3]https://groups.google.com/d/optout.
> 
> References
> 
>Visible links
>1. https://play.golang.org/p/AIB-yJaExVu
>2. mailto:golang-nuts+unsubscr...@googlegroups.com
>3. 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] Re: Set LD_LIBRARY_PATH while executing go test

2017-06-16 Thread messju mohr
... and a shell agnostic way would be:

$ env LD_LIBRARY_PATH=/foo/bar go test

(see the man page of env(1))

regards


On Fri, Jun 16, 2017 at 04:12:15AM -0700, Uli Kunitz wrote:
>Bash supports:
>```
>LD_LIBRARY_PATH=/foo/bar go test 
>```
>Is that what you want?

-- 
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] remove last index of character from string and also want use strings.LastIndex(s, sep string)

2017-05-29 Thread messju mohr
Ah, my bad. Of course, you are right.

On Fri, May 26, 2017 at 05:55:14PM -0700, long.a...@gmail.com wrote:
>Thanks for your reply. the `str[0:len(str)-1]` not work for NO ascii
>chracters.
>https://play.golang.org/p/7i6-3Zcy36
> 
>On Friday, May 26, 2017 at 11:06:10 PM UTC+8, messju mohr wrote:
> 
>  Hi,
> 
>  On Fri, May 26, 2017 at 07:10:43AM -0700, [1]long...@gmail.com wrote:
>  >    var str = "a/b/c/d/c"
>  >    // I want remove last chracter from str
>  >    var strRunes = []rune(str)
>  >    var newStrRunes = strRunes[0 :
>  len(strRunes)-1]
>  >    // then I want get last index of
>  chracters `/c`, I need convert to string back!???
>  >    strings.LastIndex(string(newStrRunes),
>  "/c")
>  >    // Does there have a method that
>  LastIndex(rs []rune, s string)
>  >    Thanks for your help!
> 
>  You don't have to convert to a slice of runes:
> 
>  var str = "a/b/c/d/c"
>  var newStr = str[0:len(str)-1]
>  fmt.Println(strings.LastIndex(newStr, "/c"))
> 
>  Or you have to convert your slice back to a string:
> 
>  var str = "a/b/c/d/c"
>  var strRunes = []rune(str)
>  var newStrRunes = strRunes[0 : len(strRunes)-1]
>  fmt.Println(strings.LastIndex(string(newStrRunes),
>  "/c"))
> 
>  HTH
>  messju
> 
>--
>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 [2]golang-nuts+unsubscr...@googlegroups.com.
>For more options, visit [3]https://groups.google.com/d/optout.
> 
> References
> 
>Visible links
>1. javascript:
>2. mailto:golang-nuts+unsubscr...@googlegroups.com
>3. 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] remove last index of character from string and also want use strings.LastIndex(s, sep string)

2017-05-26 Thread messju mohr
Hi,

On Fri, May 26, 2017 at 07:10:43AM -0700, long.a...@gmail.com wrote:
>var str = "a/b/c/d/c"
>// I want remove last chracter from str
>var strRunes = []rune(str)
>var newStrRunes = strRunes[0 : len(strRunes)-1]
>// then I want get last index of chracters `/c`, I need 
> convert to string back!???
>strings.LastIndex(string(newStrRunes), "/c")
>// Does there have a method that LastIndex(rs []rune, s string)
>Thanks for your help!

You don't have to convert to a slice of runes:

var str = "a/b/c/d/c"
var newStr = str[0:len(str)-1]
fmt.Println(strings.LastIndex(newStr, "/c"))

Or you have to convert your slice back to a string:

var str = "a/b/c/d/c"
var strRunes = []rune(str)
var newStrRunes = strRunes[0 : len(strRunes)-1]
fmt.Println(strings.LastIndex(string(newStrRunes), "/c"))

HTH
messju

-- 
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 optimization bug in go1.8?

2017-05-08 Thread messju mohr

It's not strange, it's intended behaviour of the playground. See the "about" 
page of the playground:
"[...] In the playground the time begins at 2009-11-10 23:00:00 UTC 
(determining the significance of this date is an exercise for the reader). This 
makes it easier to cache programs by giving them deterministic output. [...]"


On Mon, May 08, 2017 at 10:22:14AM -0400, Decker, Ryan C. wrote:
>See here: [1]https://play.golang.org/p/EjdQRUnwQF
>The weird thing is that time.Now().UnixNano() doesn't appear to ever
>change in the playground...
>On Mon, May 8, 2017 at 10:21 AM, Decker, Ryan C. <[2]rdec...@siena.edu>
>wrote:
> 
>  I usually follow the example and go with time.Now().UnixNano() which you
>  can see here:
>  On Mon, May 8, 2017 at 10:07 AM, messju mohr
>  <[3]mes...@lammfellpuschen.de> wrote:
> 
>Hi,
> 
>in xrand() you are initialising r with the same constant seed for
>every call, so you always get the same pseudo random number.
> 
>See: <[4]https://play.golang.org/p/XwNmYv5nzJ>
> 
>cheers
>messju
> 
>On Mon, May 08, 2017 at 03:26:08AM -0700,
>[5]sivarajshabin...@gmail.com wrote:
>>    Hi All,
>>
>>    Firstly, sorry for the title that sounds like a click bait. I
>am not
>>    understanding what exactly is wrong with this program
>>    [1][6]https://play.golang.org/p/Tl0wpaCqK7
>>
>>    package main
>>
>>    import  (
>>        "fmt"
>>        "math/rand"
>>        "runtime"
>>    )
>>
>>    func xrand()  int  {
>>        r := rand.New(rand.NewSource(99))
>>        return r.Int()
>>    }
>>
>>    func main()  {
>>        fmt.Printf("Version %s\n", runtime.Version())
>>        fmt.Printf("looks buggy \t1: %d, 2: %d, 3: %d\n",
>xrand(), xrand(),
>>    xrand())
>>       
>>        r1 := rand.New(rand.NewSource(99))
>>        fmt.Printf("Looks fine  \t1: %d, 2: %d, 3: %d\n",
>r1.Int(),
>>    r1.Int(), r1.Int())
>>    }
>>    Output>>>>
>>
>>  Version go1.8
>>  looks buggy     1: 1108929909, 2: 1108929909, 3: 1108929909
>>  Looks find      1: 1108929909, 2: 1298032409, 3: 913431059
>>
>>    When I generate a random number with "math/rand", like the
>example given
>>    in documentation [2][7]https://play.golang.org/p/O2k_za0AW7
>except that I
>>    return the randomly generated integer from a function, But the
>function
>>    keeps returning the same value any number of time I call it. On
>the
>>    contrary running the same code from the main generates random
>values,
>>    there isn't a reason to doubt rand package. However in the
>second print
>>    statement where random numbers are properly generated the first
>value
>>    always is the same value returned by xrand(), here there is
>something to
>>    doubt rand package.
>>
>>    What am I missing here?  Could it be a bug?
>>
>>    Thanks in advance.
>>
>>    Cheers
>>    Shabinesh
>--
>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 [8]golang-nuts+unsubscr...@googlegroups.com.
>For more options, visit [9]https://groups.google.com/d/optout.
> 
>  --
>  Ryan C. Decker '08
>  Sr. Network & Systems Engineer
>  Siena College ITS
>  515 Loudon Road
>  Loudonville, NY 12211
>  [10]rdec...@siena.edu
>  CONFIDENTIALITY NOTICE: This e-mail, including any attachments, is for
>  the sole use of the intended recipient(s) and may contain confidential
>  and privileged information. Any unauthorized review, use, disclosure, or
>  distribution is prohibited. If you received this e-mail and are not the
>  intended recipient, please inform the sender by e-mail reply and destroy
>  all copies of the original message.
> 
>--
>Ryan C. Decker '08
>  

Re: [go-nuts] Possible optimization bug in go1.8?

2017-05-08 Thread messju mohr
Hi,

in xrand() you are initialising r with the same constant seed for
every call, so you always get the same pseudo random number.

See: 

cheers
messju


On Mon, May 08, 2017 at 03:26:08AM -0700, sivarajshabin...@gmail.com wrote:
>Hi All,
> 
>Firstly, sorry for the title that sounds like a click bait. I am not
>understanding what exactly is wrong with this program
>[1]https://play.golang.org/p/Tl0wpaCqK7
> 
>package main
> 
>import  (
>    "fmt"
>    "math/rand"
>    "runtime"
>)
> 
>func xrand()  int  {
>    r := rand.New(rand.NewSource(99))
>    return r.Int()
>}
> 
>func main()  {
>    fmt.Printf("Version %s\n", runtime.Version())
>    fmt.Printf("looks buggy \t1: %d, 2: %d, 3: %d\n", xrand(), xrand(),
>xrand())
>   
>    r1 := rand.New(rand.NewSource(99))
>    fmt.Printf("Looks fine  \t1: %d, 2: %d, 3: %d\n", r1.Int(),
>r1.Int(), r1.Int())
>}
>Output
> 
>  Version go1.8
>  looks buggy     1: 1108929909, 2: 1108929909, 3: 1108929909
>  Looks find      1: 1108929909, 2: 1298032409, 3: 913431059
> 
>When I generate a random number with "math/rand", like the example given
>in documentation [2]https://play.golang.org/p/O2k_za0AW7 except that I
>return the randomly generated integer from a function, But the function
>keeps returning the same value any number of time I call it. On the
>contrary running the same code from the main generates random values,
>there isn't a reason to doubt rand package. However in the second print
>statement where random numbers are properly generated the first value
>always is the same value returned by xrand(), here there is something to
>doubt rand package.
> 
>What am I missing here?  Could it be a bug?
> 
>Thanks in advance.
> 
>Cheers
>Shabinesh

-- 
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] fmt verb to single quote text

2017-01-06 Thread messju mohr
If you want to generate javascript code I suggest the encoding/json package 
from the stdlib.
Like: https://play.golang.org/p/vHKcCfWJPz

On Thu, Jan 05, 2017 at 09:06:06AM -0800, bsr wrote:
>Alexander. thank you very much for helping out. 
>your program does output my desired string, but value is read from parsing
>struct comment and not sure how to get the same effect of multi line
>string `hello ... \n world`
>In other word, my input is "hello ... \n world" and not sure how to
>convert to support multi line string like `hello ... \n world`
>thanks in advance,
>bsr.
> 
>On Thursday, January 5, 2017 at 11:52:39 AM UTC-5, Alexander Kapshuk
>wrote:
> 
>  On Thu, Jan 5, 2017 at 6:45 PM, bsr <[1]bsr...@gmail.com> wrote:
>  > Please see the example [2]https://play.golang.org/p/SeG7oO5Us0
>  >
>  > I am doing some javascript codegen and I want my values single quoted.
>  so,
>  > in the above example, I want the output to be
>  >
>  >
>  > { v: 'hello ... \n world'}
>  >
>  >
>  > instead of
>  >
>  > { v: '"hello ... \n world"'}  or { v: "hello ... \n world"}
>  >
>  > how can I do that?
>  >
>  > thanks,
>  > bsr.
>  >
>  > --
>  > 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 [3]golang-nuts...@googlegroups.com.
>  > For more options, visit [4]https://groups.google.com/d/optout.
> 
>  [5]https://play.golang.org/p/GEQpdi6C6s
> 
>--
>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 [6]golang-nuts+unsubscr...@googlegroups.com.
>For more options, visit [7]https://groups.google.com/d/optout.
> 
> References
> 
>Visible links
>1. javascript:
>2. https://play.golang.org/p/SeG7oO5Us0
>3. javascript:
>4. https://groups.google.com/d/optout
>5. https://play.golang.org/p/GEQpdi6C6s
>6. mailto:golang-nuts+unsubscr...@googlegroups.com
>7. 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.