On Sun, Aug 11, 2024 at 5:35 AM 'Brian Candler' via golang-nuts
wrote:
>
> Are there many instances where interpretation (1) is useful?
Yes.
> I would also observe: if Go implemented case (2) for "==", this doesn't
> prevent the user from implementing case (1) using a separate function, as
> t
Hi Brian,
One instance where (1) would be useful is, when trying to implement a
PostScript interpreter. The Postscript "eq" operator has to test whether
two PostScript arrays share the same storage, rather than whether they
contain the same values [*]. If you can do (1), you can use Go slices
Hi Ian,
Just out of interest: if I choose that I mean equality 1 (same length and
same underlying storage), how would I perform the test for equality? Does
this require unsafe.Pointer, or is there a more proper way?
All the best,
Jochen
On Sunday 11 August 2024 at 00:08:26 UTC+1 Ian Lance Tay
Are there many instances where interpretation (1) is useful?
I would also observe: if Go implemented case (2) for "==", this doesn't
prevent the user from implementing case (1) using a separate function, as
today.
Supplementary question: does the Go standard library even expose a function
for
On Fri, Aug 9, 2024 at 9:03 PM 'Brian Candler' via golang-nuts
wrote:
>
> I would agree, except there is no == operator defined on slices, and I'm not
> really sure why that is. The semantics I would expect are straightforward:
> i.e. length is the same, and the first 'len' slice elements compar
@Gergely Brautigam its .com not .con as in your post , pls edit
On Friday, August 9, 2024 at 6:57:33 AM UTC+1 Gergely Brautigam wrote:
Hello.
I actually implemented a Tupke logic here https://github.con/Skarlso/tuple.
I find this a much better way to deal with tuples instead of the indexing
I think when discussing tuples one should consider the [...]any type as an
alternative to []any. Arrays supports comparison, aren't boxed and are
generally more tuple-like. They can be used as map keys.
Of course, they're still not really type-safe. Structs solve that and also
support access by
I add nested tuple (slice) support:
a := []any{"abc", 123, 3.14, 100, []any{"abc", 123, 3.14, 100}}
b := []any{"abc", 123, 3.14, 100, []any{"abc", 123, 3.14, 100}}
c, ok := tuple2.Cmp(a, b)
fmt.Println(c, ok)
```
package tuple2
import (
"cmp"
"reflect"
)
func Cmp
On Friday 9 August 2024 at 06:19:22 UTC+6 Jolyon Direnko-Smith wrote:
Second, you don't need to implement a custom == operator to compare custom
struct types; the implementation of == in Golang already covers the
comparison of structured value types in a logical, intuitive and type-safe
manner.
Hi community,
I have got this now.
It handles only built-in types: string, int, float64.
The tuples (slices) should be the same size.
Type of elements in same position should be the same.
I still need help on this:
The part involves cmp.Compare repeates three times for string, int, float64.
I
My apologies the link is incorrect. It should be
https://github.com/Skarlso/tuple
Hopefully it’s somewhat of a help in pursuing this topic.
On Friday 9 August 2024 at 07:57:33 UTC+2 Gergely Brautigam wrote:
> Hello.
>
> I actually implemented a Tupke logic here https://github.con/Skarlso/tuple
My apologies for the link. Google groups on mobile isn’t really working.
https://girhub.com/Skarlso/tuple
On Friday 9 August 2024 at 07:57:33 UTC+2 Gergely Brautigam wrote:
> Hello.
>
> I actually implemented a Tupke logic here https://github.con/Skarlso/tuple
> .
>
> I find this a much better
Hello.
I actually implemented a Tupke logic here https://github.con/Skarlso/tuple.
I find this a much better way to deal with tuples instead of the indexing
logic. And it’s using generics as well. Feel free to borrow stuff. 😊
On Friday 9 August 2024 at 02:19:22 UTC+2 Jolyon Direnko-Smith wrote
My $0.02 on this
First, to address the use cases in your question, Golang does not have
custom operators so the value of tuples in assisting with their
implementation is moot. (and, IMHO, should resist incorporating them;
someone should not have to consult the source for a type to understand
w
On Thu, Aug 8, 2024 at 9:35 PM 'lijh8' via golang-nuts
wrote:
> I try to use slice of any to imitate the tuple type,
> and use this function to compare two slices: a, b.
>
> How can I improve it?
Take a look at https://pkg.go.dev/slices#Compare if it can fit your use case.
--
You received this
Hi community,
I try to use slice of any to imitate the tuple type,
and use this function to compare two slices: a, b.
How can I improve it?
Thanks
```
package tuple2
func Cmp(a, b []any) (int, bool) {
for i := 0; i != min(len(a), len(b)); i++ {
if a[i] == nil && b[i]
16 matches
Mail list logo