Re: [go-nuts] x/text: Interest in Unicode text segmentation?

2020-04-16 Thread mpvl
Most of the x/text packages use tries and not rangetables. These allow
arbitrary data (as long as it fits in an int) to be associated with runes
and allow operating on utf8 without having to convert to tunes.
https://godoc.org/golang.org/x/text/internal/triegen. But that’s not a
requirement.

The package
https://godoc.org/golang.org/x/text/internal/gen/bitfield converts Go
structs to ints and can be used to pack the rune data in a convenient way.

Furthermore Package
https://godoc.org/golang.org/x/text/internal/ucd
can be used for reading UCD files

And Package
https://godoc.org/golang.org/x/text/internal/gen
can be used to generate Go tables other than the trie and include utilities
to generate canonical x/text files, such as including the Unicode and CLDR
versions.

The top-level file gen.go is used to orchestrate building x/text and
captured dependencies between packages.

I may have some designs laying around for the API.

On Thu, 16 Apr 2020 at 21:46 Matt Sherman  wrote:

> Great. Yes, the data files are here:
> https://unicode.org/reports/tr41/tr41-26.html#Props0
>
> I’ve done a proof of concept here: https://github.com/clipperhouse/uax29
>
> To do it properly, I assume we’d want to use the house style here?
> https://github.com/golang/text/blob/master/unicode/rangetable/gen.go
>
> On Thu, Apr 16, 2020 at 1:52 PM  wrote:
>
>> Yes that would be interesting. Especially if it can be generated from the
>> Unicode raw data upon updates.
>>
>> On Wed, 15 Apr 2020 at 23:56 Ian Lance Taylor  wrote:
>>
>>> [ +mpvl ]
>>>
>>> On Wed, Apr 15, 2020 at 2:30 PM Matt Sherman 
>>> wrote:
>>> >
>>> > Hi, I am working on a tokenizer based on Unicode text segmentation
>>> (UAX 29). I am wondering if there would be an interest in adding range
>>> tables for word break categories to the x/text or unicode packages. It
>>> appears they could be code-gen’d alongside the rest of the range tables.
>>> >
>>> > Pardon if this is already being done and I have missed it. I see some
>>> mention of those categories (e.g. ALetter) in other places.
>>> >
>>> > My code is here. 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 golang-nuts+unsubscr...@googlegroups.com.
>>> > To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/2a058556-da51-46d0-a41b-28e323541332%40googlegroups.com
>>> .
>>>
>>

-- 
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/CAPQTvz1%3D2AL2HOTCdUsEuhjcnsmBK0Np-BMowojm91-XY4rr%2BQ%40mail.gmail.com.


Re: [go-nuts] DeepCloning a datastructure

2020-04-16 Thread Hugh Emberson
And, I realized just after posting that your data structure has private
fields in it as https://github.com/mohae/deepcopy won't work on those.



On Thu, Apr 16, 2020 at 9:02 PM Hugh Emberson 
wrote:

> On Thu, Apr 16, 2020 at 2:07 PM Marc Schöchlin  wrote:
>
>> i am searching for a convenient way to deep-clone a nested datastructure.
>>
>
> I've used https://github.com/mohae/deepcopy with some success.  YMMV.
>
> Regards,
> Hugh
>
>

-- 
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/CAJ5gAGmwjnqOtHeE17ScyM7SUZymrb9D-MJ4VG%3DD9Zo6oKesxQ%40mail.gmail.com.


Re: [go-nuts] How can I syslog without PID

2020-04-16 Thread Ian Lance Taylor
On Thu, Apr 16, 2020 at 8:16 PM Dean Schulze  wrote:
>
> I have a C program with a syslog command like this:
>
> syslog(LOG_INFO, "slurmctrld: initializing resources");
>
> It outputs the first line below in the syslog.  This C code executes a golang 
> binary that also does syslog commands:
>
> Syslogger, err = syslog.New(syslog.LOG_INFO, "slurmctld")
> 
> Syslogger.Info("slurmctld: initializing resources - completed")
>
> The golang code writes the last 3 entries in the syslog, but they include a 
> PID or thread id:
>
> Apr 16 19:18:37 slurmctld slurmctld: slurmctrld: initializing resources
> Apr 16 19:19:12 slurmctld slurmctld[24785]: slurmctrld: creating resource 
> group
> Apr 16 19:19:15 slurmctld slurmctld[24785]: slurmctrld: creating machines
> Apr 16 19:20:28 slurmctld slurmctld[24785]: slurmctld: initializing resources 
> - completed
>
> In golang is there a way to get syslog messages without the PID so they look 
> the same as from C code?

No, there isn't.  The Go log/syslog package in effect acts like the C
function syslog if LOG_PID is passed to openlog.

If this is important to you I recommend that you just copy the
log/syslog package and edit it for your needs.  It's about 400 lines.

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/CAOyqgcVze3ix%2BUdHU%3Da-zgAxrJo6XXk_qXVekc2QK%3D5gMs2C7A%40mail.gmail.com.


Re: [go-nuts] How can I syslog without PID

2020-04-16 Thread Dan Kortschak
You can get the PID with https://golang.org/pkg/os/#Getpid and use that
you construct a string to hand in as tag to syslog.New.

On Thu, 2020-04-16 at 20:16 -0700, Dean Schulze wrote:
> I have a C program with a syslog command like this:
> 
> syslog(LOG_INFO, "slurmctrld: initializing resources");
> 
> It outputs the first line below in the syslog.  This C code executes
> a golang binary that also does syslog commands:
> 
> Syslogger, err = syslog.New(syslog.LOG_INFO, "slurmctld")
> 
> Syslogger.Info("slurmctld: initializing resources - completed")
> 
> The golang code writes the last 3 entries in the syslog, but they
> include a PID or thread id:
> 
> Apr 16 19:18:37 slurmctld slurmctld: slurmctrld: initializing
> resources
> Apr 16 19:19:12 slurmctld slurmctld[24785]: slurmctrld: creating
> resource group
> Apr 16 19:19:15 slurmctld slurmctld[24785]: slurmctrld: creating
> machines
> Apr 16 19:20:28 slurmctld slurmctld[24785]: slurmctld: initializing
> resources - completed
> 
> In golang is there a way to get syslog messages without the PID so
> they look the same as from C code?
> 
> -- 
> 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/18e63047-8b38-4276-8584-17d0a5714c21%40googlegroups.com
> .


-- 
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/d7e0ad94a9b527751ee702accc4468284313f643.camel%40kortschak.io.


Re: [go-nuts] DeepCloning a datastructure

2020-04-16 Thread Hugh Emberson
On Thu, Apr 16, 2020 at 2:07 PM Marc Schöchlin  wrote:

> i am searching for a convenient way to deep-clone a nested datastructure.
>

I've used https://github.com/mohae/deepcopy with some success.  YMMV.

Regards,
Hugh

-- 
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/CAJ5gAGmUQYRW04%3DkSM2DfiMQhVCQg6xPnZ8ohaOGBPjsaUF8nQ%40mail.gmail.com.


[go-nuts] How can I syslog without PID

2020-04-16 Thread Dean Schulze
I have a C program with a syslog command like this:

syslog(LOG_INFO, "slurmctrld: initializing resources");

It outputs the first line below in the syslog.  This C code executes a 
golang binary that also does syslog commands:

Syslogger, err = syslog.New(syslog.LOG_INFO, "slurmctld")

Syslogger.Info("slurmctld: initializing resources - completed")

The golang code writes the last 3 entries in the syslog, but they include a 
PID or thread id:

Apr 16 19:18:37 slurmctld slurmctld: slurmctrld: initializing resources
Apr 16 19:19:12 slurmctld slurmctld[24785]: slurmctrld: creating resource 
group
Apr 16 19:19:15 slurmctld slurmctld[24785]: slurmctrld: creating machines
Apr 16 19:20:28 slurmctld slurmctld[24785]: slurmctld: initializing 
resources - completed

In golang is there a way to get syslog messages without the PID so they 
look the same as from C code?

-- 
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/18e63047-8b38-4276-8584-17d0a5714c21%40googlegroups.com.


[go-nuts] DeepCloning a datastructure

2020-04-16 Thread Marc Schöchlin
Hello List,

i am searching for a convenient way to deep-clone a nested datastructure.

My data structure looks like this:

(map[string]map[string]*processing.AccountingSet) (len=1) {
 (string) (len=16) "foo1.bar.com:443": (map[string]*processing.AccountingSet) 
(len=1) {
  (string) (len=3) "all": (*processing.AccountingSet)(0xc90060)({
   count: (int64) 90,
   sum: (int64) 8001480,
   codes: (map[int]int) (len=1) {
    (int) 301: (int) 90
   },
   classes: (map[int]int) (len=6) {
    (int) 0: (int) 90,
    (int) 50: (int) 0,
    (int) 500: (int) 0,
    (int) 1000: (int) 0,
    (int) 6000: (int) 0,
    (int) 3: (int) 0
   }
  })
 }
}

How can i make a exact, deep, and completely independent copy of that structure?

What i tried:
(c.stats contains the mentioned data structure which should by copied to 
c.stats)

import "github.com/ulule/deepcopier"

c.lastStats = map[string]map[string]*AccountingSet{}
err = deepcopier.Copy(c.stats).To(c.lastStats)
if err != nil {
        glog.Errorf("unable to clone : '%s'", err.Error())
}

This doesn't work. The target structure is empty after the copy operation.

Regards
Marc


-- 
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/c860e575-28a0-1642-b097-28f592a83e43%40256bit.org.


Re: [go-nuts] x/text: Interest in Unicode text segmentation?

2020-04-16 Thread Matt Sherman
Great. Yes, the data files are here:
https://unicode.org/reports/tr41/tr41-26.html#Props0

I’ve done a proof of concept here: https://github.com/clipperhouse/uax29

To do it properly, I assume we’d want to use the house style here?
https://github.com/golang/text/blob/master/unicode/rangetable/gen.go

On Thu, Apr 16, 2020 at 1:52 PM  wrote:

> Yes that would be interesting. Especially if it can be generated from the
> Unicode raw data upon updates.
>
> On Wed, 15 Apr 2020 at 23:56 Ian Lance Taylor  wrote:
>
>> [ +mpvl ]
>>
>> On Wed, Apr 15, 2020 at 2:30 PM Matt Sherman  wrote:
>> >
>> > Hi, I am working on a tokenizer based on Unicode text segmentation (UAX
>> 29). I am wondering if there would be an interest in adding range tables
>> for word break categories to the x/text or unicode packages. It appears
>> they could be code-gen’d alongside the rest of the range tables.
>> >
>> > Pardon if this is already being done and I have missed it. I see some
>> mention of those categories (e.g. ALetter) in other places.
>> >
>> > My code is here. 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 golang-nuts+unsubscr...@googlegroups.com.
>> > To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/2a058556-da51-46d0-a41b-28e323541332%40googlegroups.com
>> .
>>
>

-- 
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/CAMPnbukLN%3DSVkhBQ1TM8TYfp-t1Z3Wxc6MuAi6UZFYYnumU3rw%40mail.gmail.com.


Re: [go-nuts] x/text: Interest in Unicode text segmentation?

2020-04-16 Thread mpvl
Yes that would be interesting. Especially if it can be generated from the
Unicode raw data upon updates.

On Wed, 15 Apr 2020 at 23:56 Ian Lance Taylor  wrote:

> [ +mpvl ]
>
> On Wed, Apr 15, 2020 at 2:30 PM Matt Sherman  wrote:
> >
> > Hi, I am working on a tokenizer based on Unicode text segmentation (UAX
> 29). I am wondering if there would be an interest in adding range tables
> for word break categories to the x/text or unicode packages. It appears
> they could be code-gen’d alongside the rest of the range tables.
> >
> > Pardon if this is already being done and I have missed it. I see some
> mention of those categories (e.g. ALetter) in other places.
> >
> > My code is here. 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 golang-nuts+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/2a058556-da51-46d0-a41b-28e323541332%40googlegroups.com
> .
>

-- 
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/CAPQTvz2Grj-TR64we3a_w2iz1vwhPweO0sYL88Gy4Z-__zavCw%40mail.gmail.com.


Re: [go-nuts] Re: "Go build failed." in Go tour requires explicit Kill

2020-04-16 Thread Marvin Renich
* Brian Candler  [200416 12:20]:
> I've noticed this too.  This is with the tour, rather than play.golang.org.
> 
> To reproduce (I'm using Chrome 80 under macOS 10.14):
> 
> * Go to a tour page which doesn't compile, e.g. 
> https://tour.golang.org/methods/25
> * Click Run
> * At this point it shows an error - but the Run button has become Kill
> * Now you have to click Kill.  The line "Program exited: killed" is added.
> * Now you can edit and re-run
> 
> The "Kill" step appears to be superfluous, as noted by the OP.

This is exactly what I am seeing, on any tour page when the build fails.
Go to the "Hello, 世界" page (https://tour.golang.org/welcome/1) and
edit the code to produce an error.

...Marvin

-- 
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/20200416170100.h6fdaiyvphifjpfu%40basil.wdw.


[go-nuts] Re: "Go build failed." in Go tour requires explicit Kill

2020-04-16 Thread Jake Montgomery

On Wednesday, April 15, 2020 at 1:02:47 PM UTC-4, Marvin Renich wrote:
>
> In the Go tour, what is the purpose of requiring the user to explicitly 
> press the "Kill" button when the build fails?  This seems completely 
> unnecessary to me. 
>
> If this is just a natural consequence of the internal implementation, it 
> would, in my opinion, be well worth the effort to make a failed build 
> exit without requiring the user to press "Kill". 
>
> ...Marvin 
>
>
As far as I can tell, you do not ever need to hit 'kill'. If the build 
(compile) fails, then it exists immediately. If the program gets into an 
infinite loop, or otherwise takes too long, it will eventually exit with 
the message:

timeout running programProgram exited: status 255.


It looks to me like the kill button is there in case you create a long 
running program and do not wish to wait for the timeout. 

Are you seeing different behavior? If so it may be a bug.


 

-- 
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/77efb0a1-d9da-41cc-8f00-d2161d00d283%40googlegroups.com.


Re: [go-nuts] Re: wording in Go tour, methods/19

2020-04-16 Thread Marvin Renich
* Volker Dobler  [200416 02:28]:
> On Wednesday, 15 April 2020 17:58:11 UTC+2, Marvin Renich wrote:
> >
> > In the Go tour at https://tour.golang.org/methods/19 it says 
> >
> >   The error type is a built-in interface similar to fmt.Stringer: 
> 
> I agree that this might be misunderstood in the sense of fmt.Stringer
> being built-in too, but if this is commonly misunderstood it probably
> is not a long-lasting, problematic confusion (for most purposes it
> simply doesn't matter wether fmt.String is a predeclared built-in or
> declared in the stdlib).

Whether the confusion is long lasting or not, it requires re-reading the
statement and possibly looking up the definition of fmt.Stringer to
understand what is being said.  Making the statement clearer on initial
read is definitely better.

> > A much better wording would be 
> >
> >   The error type is a built-in interface; its definition is similar to 
> >   fmt.Stringer: 
> 
> I think I disagree here. The similarity of error and fmt.Stringer is
> both being a one-method interface and this method has the same
> signature for both (no arguments, string return) but their _actual_
> "definition" is pretty different as one is built-in, the other isn't.

Okay, then what is the point of saying the two are "similar"?  I am
simply advocating that the fact that error is built-in be separated from
any comparison to fmt.Stringer, for whatever comparison you would like
to make.  Would you like this better (I don't particularly, but it is
better than what is there now)?

  The error type is an interface similar to fmt.Stringer, but it is
  built-in:

Making written communication easier to understand is always an important
goal, even if it means being somewhat more verbose.  This is especially
true in a tutorial such as the Go tour.

...Marvin

-- 
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/20200416115637.kmi7fn5muxzwibe6%40basil.wdw.


[go-nuts] Re: How to scan input with termui?

2020-04-16 Thread Brian Candler
 inputParagraph.Text = fmt.Scanf("%s", input) // Error: assignment 
mismatch: 1 variable but fmt.Scanf returns 2 values

The error message is clear: fmt.Scanf returns two values (BTW, neither of 
them is the value extracted).  Check the documentation for fmt.Scanf here:
https://golang.org/pkg/fmt/#Scanf
https://golang.org/pkg/fmt/#hdr-Scanning
https://golang.org/pkg/fmt/#example_Sscanf

outputParagraph.Text += fmt.Printf("The string you entered is: %s", input) 
// multiple-value fmt.Printf() in single-value context

In this case you want fmt.Sprintf instead:
https://golang.org/pkg/fmt/#Sprintf

-- 
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/c6dc6c49-b18b-4655-b206-7227e1fdb7d1%40googlegroups.com.


[go-nuts] How to scan input with termui?

2020-04-16 Thread 洪嘉鴻
Hello everyone:
I use golang with Win10. I started to learn termui recently.
However, I couldn't find any examples about how to scan input with this 
.
I tried to write simple code , but 
there are some errors.
I have no idea how to edit it.
Could anyone help me to solve this problem?

Any help is appreciated.
Thank you very much!
Max

-- 
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/1f93237a-5143-4d20-b3d8-1d681a310af5%40googlegroups.com.


[go-nuts] Re: wording in Go tour, methods/19

2020-04-16 Thread Volker Dobler
On Wednesday, 15 April 2020 17:58:11 UTC+2, Marvin Renich wrote:
>
> In the Go tour at https://tour.golang.org/methods/19 it says 
>
>   The error type is a built-in interface similar to fmt.Stringer: 
>
> The words closest to "similar to" are "built-in interface", implying 
> that the way error is similar to fmt.Stringer is that it is a built-in 
> interface, which it clearly isn't.  I would be surprised if this is not 
> a source of confusion to a significant number of programmers who are new 
> to go and using the tour to get acquainted. 
>

I agree that this might be misunderstood in the sense of fmt.Stringer
being built-in too, but if this is commonly misunderstood it probably
is not a long-lasting, problematic confusion (for most purposes it
simply doesn't matter wether fmt.String is a predeclared built-in or
declared in the stdlib).
 

> A much better wording would be 
>
>   The error type is a built-in interface; its definition is similar to 
>   fmt.Stringer: 
>

I think I disagree here. The similarity of error and fmt.Stringer is
both being a one-method interface and this method has the same
signature for both (no arguments, string return) but their _actual_
"definition" is pretty different as one is built-in, the other isn't.

V. 

-- 
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/2501221d-c555-40b0-9648-b4b8bc54377a%40googlegroups.com.