[go-nuts] How do I set a pkg's version?

2022-11-01 Thread 'Mark' via golang-nuts
I am creating a pkg. It has a `go.mod` file: ``` module github.com/.../mypkg go 1.19 ``` And code files with functions in .go files all in the mypkg pkg. How do I specify which version the mypkg pkg is? I know about using `$ git tag vX.Y.Z` and `$ git push origin vX.Y.Z`, but is there any way I

Re: [go-nuts] How do I set a pkg's version?

2022-11-02 Thread 'Mark' via golang-nuts
like --version print the json. >> >> Note that this is about the version of some binary - not the version of a >> package. However, you could embed go.mod. But there may be better ways. >> >> Hope this helps. >> >> 'Mark' via golang-nut

[go-nuts] Trying to create a test app for a library package

2022-11-02 Thread 'Mark' via golang-nuts
I have this layout: ``` mylib/ mylib/go.mod # module github.com/me/mylib mylib/mylib.go mylib/mylib_test.go ``` All this works fine, with both .go files being in the same pkg: mylib. However, there are some tests that I can't really do using the test module because they write to stdout. So I want

Re: [go-nuts] How do I set a pkg's version?

2022-11-02 Thread 'Mark' via golang-nuts
--version print the json. >>> >>> Note that this is about the version of some binary - not the version of >>> a package. However, you could embed go.mod. But there may be better ways. >>> >>> Hope this helps. >>> >>> 'Mark' via go

[go-nuts] Is it possible to switch on type T in a generic function?

2022-11-08 Thread 'Mark' via golang-nuts
Given a function: func F[T comparable](a T) { } is it possible to check T's type inside F? My use case is that I have a function with signature G[T comparable](x []T) and inside G I want to sort the elements in slice x where T could be int or string. This arises in a tiny generic set module I

Re: [go-nuts] Is it possible to switch on type T in a generic function?

2022-11-08 Thread 'Mark' via golang-nuts
t.Strings(elements) / s := "{" sep := "" for _, element := range elements { s += fmt.Sprintf("%s%s", sep, element) sep = " " } return s + "}" } On Tuesday, November 8, 2022 at 9:19:48 AM UTC Jan M

Re: [go-nuts] Is it possible to switch on type T in a generic function?

2022-11-08 Thread 'Mark' via golang-nuts
o this: https://go.dev/play/p/oKTGSm_o22a > > To answer the specific question you asked, there is an issue that tracks > the ability to do a switch directly on a type parameter: > https://github.com/golang/go/issues/45380 > > But you can also work around the lack of that feature b

Re: [go-nuts] Is it possible to switch on type T in a generic function?

2022-11-09 Thread 'Mark' via golang-nuts
>>> observe that essentially you're trying to solve the same problem that the >>> fmt package is solving when it converts maps to string. It uses the >>> internal fmtsort <https://pkg.go.dev/internal/fmtsort> package, which, >>> as luck would have it, ha

[go-nuts] How to read struct field names from an empty slice of structs

2022-11-21 Thread &#x27;Mark&#x27; via golang-nuts
I have a two level general-purpose data structure: a struct containing one or more slices of structs. I want to be able to use reflection to populate this, but as a first step I want to extract the "table names" (i.e., the names of the fields of the outer struct), and the "field names" (the nam

[go-nuts] Re: How to read struct field names from an empty slice of structs

2022-11-21 Thread &#x27;Mark&#x27; via golang-nuts
After struggling, I finally solved it; playground On Monday, November 21, 2022 at 10:55:06 AM UTC Mark wrote: > I have a two level general-purpose data structure: a struct containing one > or more slices of structs. > I want to be able to use reflection to po

[go-nuts] How to fix an awful marshal reflection hack

2022-11-30 Thread &#x27;Mark&#x27; via golang-nuts
I have this code which works but has a horrible hack: ... nullable := false kind := field.Kind() // field's type is reflect.Value if kind == reflect.Ptr { // FIXME How can I improve upon this truly awful hack? switch field.Type().String() { case "*int", "*int8", "*uint8", "*int16", "*ui

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-11-30 Thread &#x27;Mark&#x27; via golang-nuts
Yes, I'd already tried that (that's what I started with) and unfortunately it doesn't work. On Wednesday, November 30, 2022 at 3:37:47 PM UTC bse...@computer.org wrote: > On Wed, Nov 30, 2022 at 5:29 AM 'Mark' via golang-nuts < > golan...@googlegroups.com&g

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-12-01 Thread &#x27;Mark&#x27; via golang-nuts
I tried without the print statements too.) And, of course the tests fail. So I'm _still_ using the awful hack! On Wednesday, November 30, 2022 at 5:30:24 PM UTC bse...@computer.org wrote: > On Wed, Nov 30, 2022 at 10:17 AM 'Mark' via golang-nuts < > golan...@googlegroups.com

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-12-01 Thread &#x27;Mark&#x27; via golang-nuts
shal.go from line 133 function marshalTableMetaData(). If you run: go test it all works; but if you replace the call to hack() and use nullable as you did in the playground, some of the tests fail. On Thursday, December 1, 2022 at 9:45:48 AM UTC kortschak wrote: > On Thu, 2022-12-01 at 00:

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-12-01 Thread &#x27;Mark&#x27; via golang-nuts
ormal processing. So the complete -- and working -- code is in the repo and go test works. But replacing the call to hack() with kind = field.Type().Elem().Kind() breaks the tests. On Thursday, December 1, 2022 at 1:09:50 PM UTC Marvin Renich wrote: > * 'Mark' via golang-nuts [22120

[go-nuts] Which tool provide's the Go playground's import handling...

2023-01-06 Thread &#x27;Mark&#x27; via golang-nuts
If I visit the Go playground and change the body of `main()` to, say, `fmt.Println("hello", math.Abs(-5))` and then click Run, the `import "fmt"` line is _automatically_ corrected to be `import (\n\t"fmt"\n\t"math"\n)`. I'd like to be able to use this functionality so tha

Re: [go-nuts] Which tool provide's the Go playground's import handling...

2023-01-06 Thread &#x27;Mark&#x27; via golang-nuts
Thanks, that's just what I needed :-) On Friday, January 6, 2023 at 8:21:02 AM UTC kortschak wrote: > On Fri, 2023-01-06 at 00:13 -0800, 'Mark' via golang-nuts wrote: > > If I visit the Go playground and change the body of `main()` to, say, > > `fmt.Println("he

[go-nuts] Doc suggestion (& one const suggestion)

2023-05-02 Thread &#x27;Mark&#x27; via golang-nuts
In the docs file modes are often shown in octal, e.g., `0600`. Doc suggestion: update octal to use the modern unambiguous format, e.g., `0o600`. Const suggestion: add at least one const to `os`, e.g., ```go const ModeUserRW = 0o600 // plus any one or two others that are really common? ``` If th

[go-nuts] Can a struct be made comparable?

2023-07-13 Thread &#x27;Mark&#x27; via golang-nuts
I have a package which has a function `Do[T comparable](a, b []T) Result`. I have a struct: ```go type N struct { x int y int t string } ``` Is it possible to make `N` comparable; in particular by a field of my choice, e.g., `t`? Or will I have to make, say, `DoFunc(a, b []N, eq func(i, j N

[go-nuts] Re: Can a struct be made comparable?

2023-07-14 Thread &#x27;Mark&#x27; via golang-nuts
What I really want to do is to be able to diff slices of structs on the basis of one single field. For example, given: ``` type Item struct { I int S string } ``` and given `a` and `b` are both of type`[]Item`, I want to diff these slices based purely on the `S` field, ignoring the `I` field.

[go-nuts] Re: Can a struct be made comparable?

2023-07-14 Thread &#x27;Mark&#x27; via golang-nuts
In fact the diff pkg mentioned above does work but is of no use to me since for each change it gives back only the field(s) used, not the original structs (or pointers to them), so I can't see any way back to the original structs (or their slice indexes). On Friday, July 14, 2023 at 8:58:41 AM

[go-nuts] Re: Can a struct be made comparable?

2023-07-14 Thread &#x27;Mark&#x27; via golang-nuts
Hi Brian, Your code certainly identifies the different items. However, that's not a diff tool in the sense I mean. Unix diff and tools like it don't just say x[i] != y[i], they find the longest common subsequences and in essence produce a series of edit commands that would turn slice x into slice

[go-nuts] Re: Can a struct be made comparable?

2023-07-14 Thread &#x27;Mark&#x27; via golang-nuts
Hi Brian, Ah, thank you, that helped a lot. On Friday, July 14, 2023 at 11:54:51 AM UTC+1 Brian Candler wrote: > The 'diff' package you showed identifies the changed object index by means > of a "Path" attribute in the Changelog entry. If the top level object is a > slice, then Atoi(change.Path

[go-nuts] Re: Can a struct be made comparable?

2023-07-14 Thread &#x27;Mark&#x27; via golang-nuts
I finally worked out how to make my go-diff pkg (v1.1.0) able to diff sequences of structs based on a key function. On Friday, July 14, 2023 at 12:27:46 PM UTC+1 Mark wrote: > Hi Brian, > Ah, thank you, that helped a lot. > > On Friday, J

[go-nuts] Re: Error handling

2023-07-30 Thread &#x27;Mark&#x27; via golang-nuts
Given that this proposal is to reduce boilerplate, and assuming the semantic issues could be solved, it seems to me that the 'return' is redundant (i.e., could be implicit) and that 'orelse' could be done with the existing 'else' keyword, i.e., ``` result, err := someCall() else rest, err ``` A

[go-nuts] How to convert an svg to a png (or gif) image?

2023-08-03 Thread &#x27;Mark&#x27; via golang-nuts
I know this has been asked before, just wondered if there were any pure-Go solutions? -- 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...@goo

[go-nuts] Re: How to convert an svg to a png (or gif) image?

2023-08-04 Thread &#x27;Mark&#x27; via golang-nuts
Thanks! On Friday, August 4, 2023 at 8:46:18 AM UTC+1 Tamás Gulácsi wrote: > https://pkg.go.dev/github.com/goki/gi/svg > > Mark a következőt írta (2023. augusztus 3., csütörtök, 13:18:48 UTC+2): > >> I know this has been asked before, just wondered if there were any >> pure-Go solutions? >> > -

[go-nuts] How to constrain an integral type's values

2023-09-08 Thread &#x27;Mark&#x27; via golang-nuts
I often create small multi-value flag types, e.g. ```go type mode uint8 const ( argMode mode = iota baseMode cmdMode ) ``` The problem is that if I write, say, `m := baseMode`, although `m` has the correct type (`mode`), there is no way to constrain its values to the consts I've declared. In th

[go-nuts] bufio.Scanner - possible bug or doc err?

2023-10-12 Thread &#x27;Mark&#x27; via golang-nuts
I'm reading Debian *Package files, some of which are over 1M lines long. I used bufio.Scanner and found that it won't read past 1M lines (I'm using Go 1.21.1 linux/amd64). Is this a limitation of bufio.Scanner? If so then it ought to be in the docs. Or is it a bug? Or maybe I made a mistake (alth

Re: [go-nuts] bufio.Scanner - possible bug or doc err?

2023-10-12 Thread &#x27;Mark&#x27; via golang-nuts
nd it worked fine, so I > suspect it's a bug in your code. But if not, please provide a complete > working executable example, with data, to help identify the problem. > > -rob > > > On Thu, Oct 12, 2023 at 7:39 PM 'Mark' via golang-nuts < > golan...@googleg

Re: [go-nuts] bufio.Scanner - possible bug or doc err?

2023-10-12 Thread &#x27;Mark&#x27; via golang-nuts
MaxScanTokenSize), or must run sequential scans on a reader, should use bufio.Reader instead. Just a thought. Thanks. On Thursday, October 12, 2023 at 8:56:05 PM UTC+1 Ian Lance Taylor wrote: > On Thu, Oct 12, 2023 at 10:21 AM 'Mark' via golang-nuts > wrote: > > > >

Re: [go-nuts] bufio.Scanner - possible bug or doc err?

2023-10-14 Thread &#x27;Mark&#x27; via golang-nuts
Yes, that's a much better solution. On Friday, October 13, 2023 at 8:40:45 PM UTC+1 Ian Lance Taylor wrote: > On Thu, Oct 12, 2023 at 11:42 PM 'Mark' via golang-nuts > wrote: > > > > Yes, I can see now. > > > > Perhaps consider changing: >

[go-nuts] Is there a Go equivalent to Python's ctypes library?

2023-11-21 Thread &#x27;Mark&#x27; via golang-nuts
I would like to be able to access a dynamic C library (and ideally C++), i.e., `.so` or `.dll` _without_ using cgo, i.e., without needing a compiler on the target platform. Python provides a `ctypes` module with this facility. Is there an equivalent for Go? -- You received this message because

[go-nuts] Re: Is there a Go equivalent to Python's ctypes library?

2023-11-21 Thread &#x27;Mark&#x27; via golang-nuts
Thank you, that looks just like what I want. On Tuesday, November 21, 2023 at 10:21:14 AM UTC Mark wrote: > I would like to be able to access a dynamic C library (and ideally C++), > i.e., `.so` or `.dll` _without_ using cgo, i.e., without needing a compiler > on the target platform. > Python p

[go-nuts] Re: Is there a Go equivalent to Python's ctypes library?

2023-11-21 Thread &#x27;Mark&#x27; via golang-nuts
My reply was to Salih but somehow my reply ended up appearing first. According to the purego docs you don't need a compiler, essentially it provides a means of opening a dll/so and registering and calling functions within the dll/so. On Tuesday, November 21, 2023 at 12:58:20 PM UTC Tamás Gulács

[go-nuts] a simple linux audio player pkg?

2023-11-22 Thread &#x27;Mark&#x27; via golang-nuts
Is there a simple vorbis/oga audio player package for Go that works on Linux. The only API I need is something like this: player.SetFilename(string) error // string is say tune.ogg; stops playing previous if any player.Play(float32) error // plays current filename from given second e.g. 0.0 for

Re: [go-nuts] a simple linux audio player pkg?

2023-11-23 Thread &#x27;Mark&#x27; via golang-nuts
nd > convert to PCM) and github.com/ebitengine/oto/v3 to play the PCM. > I don't know of a full ogg player in Go > > > On Wed, Nov 22, 2023 at 2:02 PM 'Mark' via golang-nuts < > golan...@googlegroups.com> wrote: > >> Is there a simple vorbis/oga aud

Re: [go-nuts] a simple linux audio player pkg?

2023-11-23 Thread &#x27;Mark&#x27; via golang-nuts
e used github.com/jfreymuth/oggvorbis to read the ogg file (and > convert to PCM) and github.com/ebitengine/oto/v3 to play the PCM. > I don't know of a full ogg player in Go > > > On Wed, Nov 22, 2023 at 2:02 PM 'Mark' via golang-nuts < > golan...@googlegroups.com&

Re: [go-nuts] a simple linux audio player pkg?

2023-11-23 Thread &#x27;Mark&#x27; via golang-nuts
r 22, 2023 at 10:31:25 PM UTC Raffaele Sena wrote: > >> I have used github.com/jfreymuth/oggvorbis to read the ogg file (and >> convert to PCM) and github.com/ebitengine/oto/v3 to play the PCM. >> I don't know of a full ogg player in Go >> >> >> On Wed,

[go-nuts] range func experiment typo?

2024-01-19 Thread &#x27;Mark&#x27; via golang-nuts
In the RangefuncExperiment doc it says: for k, v := range g { ... } // g has type Seq[K,V], k and v have types K and V but shouldn't this be: for k, v := range g { ... } // g has type Seq2[K,V], k and v have types K and V Anyway, it looks interesting

[go-nuts] Can't figure out how to create an All() iter.Seq[T] method

2024-03-13 Thread &#x27;Mark&#x27; via golang-nuts
I've been trying to learn how to create an `All() iter.Seq[T]` method for a simple set type (a map wrapper): playground It won't work in the playground of course, but when I do: `GOEXPERIMENT=rangefunc go run .` using Go 1.22 I get this error: ``` cann

Re: [go-nuts] Can't figure out how to create an All() iter.Seq[T] method

2024-03-13 Thread &#x27;Mark&#x27; via golang-nuts
Thank you, that solved the problem. On Wednesday, March 13, 2024 at 1:22:06 PM UTC Sebastien Binet wrote: > hi Mark, > > On Wed Mar 13, 2024 at 13:32 CET, 'Mark' via golang-nuts wrote: > > I've been trying to learn how to create an `All() iter.Seq[T]` method > &