Re: [go-nuts] Generic constant type parameters?

2024-10-15 Thread 'Robert Engels' via golang-nuts
Hmm, I thought I had it “working” using this code https://go.dev/play/p/pzKacmi3aPe but there is a compiler error, but according to the accepted proposal documentation this should be valid https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-

Re: [go-nuts] Re: Generic constant type parameters?

2024-10-15 Thread Robert Engels
Obviously one way to do it is to copy and paste the code and/or generate under different type or package with different decimal place values. On Oct 15, 2024, at 10:53 PM, Robert Engels wrote:Not really. The idea is that use multiple types with different number of decimal places. Eg. 7 for interm

Re: [go-nuts] Re: Generic constant type parameters?

2024-10-15 Thread Robert Engels
Not really. The idea is that use multiple types with different number of decimal places. Eg. 7 for intermediate operations and 2 for summary values, etc. Thanks for trying to help though. On Oct 15, 2024, at 10:35 PM, Cleberson Pedreira Pauluci wrote:Hi, Robert.I'm sorry. Now I got it.But I think

Re: [go-nuts] Re: Generic constant type parameters?

2024-10-15 Thread Cleberson Pedreira Pauluci
Hi, Robert. I'm sorry. Now I got it. But I think what you are trying to do is not possible in Go yet. @Ian already answered about this. Have you thought of another way to do this? Maybe reading the "nPlaces" value from something like a configuration file and storing it as an encapsulated field

Re: [go-nuts] Re: Generic constant type parameters?

2024-10-15 Thread Robert Engels
I think you misunderstood the question or it wasn’t clear. The struct can only contain a single int64 - so you cannot add another value to hold the number of decimal places. The idea is to track the number of decimal places via the type (or method on the type) so the compiler knows it while generat

Re: [go-nuts] Generic constant type parameters?

2024-10-15 Thread Ian Lance Taylor
On Tue, Oct 15, 2024 at 5:01 PM 'Robert Engels' via golang-nuts wrote: > > Is there someway of doing this with Go generics? > https://github.com/robaho/cpp_fixed/blob/6770b217acd84e4b723449e4c4bb42c92e7f2af1/fixed.h#L18-L23 Not at present, sorry. Ian -- You received this message because you a

[go-nuts] Re: Generic constant type parameters?

2024-10-15 Thread Cleberson Pedreira Pauluci
Hi. Maybe you can use encapsulation instead of standalone function and generics. Encapsulation is a fundamental principle in software engineering. It controls which parts of a package are visible from the outside and which are not. It hides implementation details, allowing changes that do not af

[go-nuts] Generic constant type parameters?

2024-10-15 Thread 'Robert Engels' via golang-nuts
Hi, Is there someway of doing this with Go generics? https://github.com/robaho/cpp_fixed/blob/6770b217acd84e4b723449e4c4bb42c92e7f2af1/fixed.h#L18-L23 I could make the type and interface and add a method for ‘decimal places’, but I would like all of the constants to be resolved at compile time.

[go-nuts] Re: Non-blocking Read from StdoutPipe and StderrPipe

2024-10-15 Thread 'Brian Candler' via golang-nuts
On Monday 14 October 2024 at 22:57:07 UTC+1 Peter Bočan wrote: What is the recommended way of reading whatever is on the buffer and return back without blocking? If you just want to poll, and get whatever data is available: set a deadline of "just after now", and read. https://go.dev/play/p/bF