gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
842 stars 343 forks source link

`sort.Slice` implementation #750

Open schollz opened 1 year ago

schollz commented 1 year ago

Hi all! I still getting used to gno and noticed that I'm getting a panic when using sort.Slice:

panic: name Slice not declared [recovered]
        panic: ./examples/gno.land/p/demo/microblog/microblog.gno:154: name Slice not declared

I looked through the codebase and can see that this seems not to be available in gno, and I was wondering whether this is correct, and if there is a reason. I'm happy to attempt adding it to gno, unless there is a particular reason its left out.

thehowl commented 1 year ago

As far as I know, the same reason ufmt.Sprintf doesn't match fmt.Sprintf - they require reflection, and whether or not to have a reflect package in Gno is up for debate.

I recall having already stumbled upon this issue in the past, and since I was in Go before sort.Slice was implemented and would never go back, I think that even if we decide to not implement reflection in Gno, the Slice function is so immensely useful it ought to be implemented as a native binding.

schollz commented 1 year ago

Thanks. Its not a deal breaker for me not to have sort.Slice - I was able to write Go code pre1.8 without it and I can do it again 😄 , but it might be worth leaving the issue open to track it?

Also, is there an ongoing debate about reflection? It would be useful to link a reflection discussion to this issue (and also for my own edification about its pros/cons re: gno)

thehowl commented 1 year ago

Not as far as I know. @moul do you think it's worth making an issue to discuss this, or is reflection more in the ballpark of "we want it, just didn't do it yet"?

moul commented 1 year ago

Let's keep the discussion open until we create a meta issue to gather everything and establish a backlink. Ultimately, we need to find practical solutions to support both fmt and sort.Slice.