Re: [go-nuts] Re: [Go2] Reflect

2017-08-07 Thread roger peppe
On 7 Aug 2017 20:35, "Gert"  wrote:


On Monday, August 7, 2017 at 5:59:15 PM UTC+2, rog wrote:
>
> What is this supposed to do? What does it do if the value
> isn't an integer?


Same error as you do int("4")


Um, have you tried that? It's a compiler error.



> Are you thinking that it would be the same as fmt.Println("value:",
> r.Interface().(int)) ?
>

Nope more that it acts as a basic type like a int(4) so that reflect is the
same as any other basic types float int byte string etc


What do you mean by that? The same in what respects?

-- 
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.
For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: [Go2] Reflect

2017-08-07 Thread Gert

On Monday, August 7, 2017 at 5:59:15 PM UTC+2, rog wrote: 
>
> What is this supposed to do? What does it do if the value 
> isn't an integer? 


Same error as you do int("4") 
  

> Are you thinking that it would be the same as fmt.Println("value:", 
> r.Interface().(int)) ? 
>

Nope more that it acts as a basic type like a int(4) so that reflect is the 
same as any other basic types float int byte string etc

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: [Go2] Reflect

2017-08-07 Thread roger peppe
On 7 August 2017 at 16:22, Gert Cuykens  wrote:
> On Mon, Aug 7, 2017 at 12:03 PM, roger peppe  wrote:
>> ISTM that the only thing you're suggesting is to change
>> the spelling of "reflect.ValueOf" to "reflect".
>>
>> I don't understand what semantics you'd expect
>>
>> fmt.Println("value:", r.Value(int))
>>
>> to have. What's the parameter to that Value method?
>>
>
> Merge ValueOf and TypeOf into one reflect() build in

reflect.TypeOf is strictly a convenience anyway - you can
always write reflect.ValueOf(x).Type() instead.

So this suggestion is just equivalent to doing:

   func reflect(x interface{}) reflect.Value {
return reflect.ValueOf(x)
   }

(except you can't do that, because reflect is the name of the
package, which is an issue with your suggestion too).

> (and make the
> reflect type transform easier with other types fmt.Println("value:",
> int(r.Value))

What is this supposed to do? What does it do if the value
isn't an integer?

Are you thinking that it would be the same as fmt.Println("value:",
r.Interface().(int)) ?

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: [Go2] Reflect

2017-08-07 Thread Gert Cuykens
On Mon, Aug 7, 2017 at 12:03 PM, roger peppe  wrote:
> ISTM that the only thing you're suggesting is to change
> the spelling of "reflect.ValueOf" to "reflect".
>
> I don't understand what semantics you'd expect
>
> fmt.Println("value:", r.Value(int))
>
> to have. What's the parameter to that Value method?
>

Merge ValueOf and TypeOf into one reflect() build in and make the
reflect type transform easier with other types fmt.Println("value:",
int(r.Value))

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: [Go2] Reflect

2017-08-07 Thread roger peppe
On 6 August 2017 at 21:51, Gert  wrote:
> Yes but its the way it's done that i think could be made more
> straightforward, why not merge ValueOf and TypeOf in a build in intermediate
> reflect type as in for example int(4) but then reflect(4)

ISTM that the only thing you're suggesting is to change
the spelling of "reflect.ValueOf" to "reflect".

I don't understand what semantics you'd expect

fmt.Println("value:", r.Value(int))

to have. What's the parameter to that Value method?

>
> On Sunday, August 6, 2017 at 5:57:40 PM UTC+2, Rich wrote:
>>
>> I don't understand... doesn't Reflect already do this?
>> https://play.golang.org/p/CIm7aISztv
>>
>>
>> On Saturday, August 5, 2017 at 12:58:52 PM UTC-4, Gert wrote:
>>>
>>> package main
>>>
>>> import (
>>> "fmt"
>>> "reflect"
>>> )
>>>
>>> func main() {
>>> x := 4
>>> v1 := reflect.ValueOf(x)
>>> fmt.Println("type:", v1.Type())
>>> v2 := reflect.TypeOf(x)
>>> fmt.Println("type:", v2)
>>> }
>>>
>>> Kan we have something like this instead please
>>>
>>> package main
>>>
>>> import (
>>> "fmt"
>>> "reflect"
>>> )
>>>
>>> func main() {
>>> x := 4
>>> r := reflect(x)
>>> fmt.Println("type:", r.Type())
>>> fmt.Println("value:", r.Value(int))
>>> }
>>>
>>> Reflect should be a generic way of Go2, but everytime i need to reflect
>>> around a Go1 interface i want to go on a vacation...
>>>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: [Go2] Reflect

2017-08-06 Thread Gert


On Monday, August 7, 2017 at 12:41:18 AM UTC+2, kortschak wrote:
>
> The reflect package is not mentioned in the spec (except once to 
> discuss struct tags), adding a built-in would require its definition 
> there, and complicate the language. Making it easier to use would also 
> have the disadvantage of increasing its use, packages with heavy 
> reflect use tend to be harder to reason about by virtue of having 
> reduced type constraints. 
>
> https://blog.golang.org/laws-of-reflection 
>
>
 I agree but so is cgo and disabling reflect by default i would not mind, 
but the fact is sometimes you have to use it. And when you need to use it 
you already drowning in complicated code to begin with, no need to make it 
even more complicated. Lets meet in the middle by only allowing reflect 
with a build flag.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: [Go2] Reflect

2017-08-06 Thread Dan Kortschak
>From the Laws of Reflection[1]:

> It's a powerful tool that should be used with care and avoided unless
> strictly necessary. 

The reflect package is not mentioned in the spec (except once to
discuss struct tags), adding a built-in would require its definition
there, and complicate the language. Making it easier to use would also
have the disadvantage of increasing its use, packages with heavy
reflect use tend to be harder to reason about by virtue of having
reduced type constraints.

[1]https://blog.golang.org/laws-of-reflection

On Sun, 2017-08-06 at 13:51 -0700, Gert wrote:
> Yes but its the way it's done that i think could be made more 
> straightforward, why not merge ValueOf and TypeOf in a build in 
> intermediate reflect type as in for example int(4) but then
> reflect(4)

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: [Go2] Reflect

2017-08-06 Thread Gert
Yes but its the way it's done that i think could be made more 
straightforward, why not merge ValueOf and TypeOf in a build in 
intermediate reflect type as in for example int(4) but then reflect(4)

On Sunday, August 6, 2017 at 5:57:40 PM UTC+2, Rich wrote:
>
> I don't understand... doesn't Reflect already do this?
> https://play.golang.org/p/CIm7aISztv
>
>
> On Saturday, August 5, 2017 at 12:58:52 PM UTC-4, Gert wrote:
>>
>> package main
>>
>> import (
>> "fmt"
>> "reflect"
>> )
>>
>> func main() {
>> x := 4
>> v1 := reflect.ValueOf(x)
>> fmt.Println("type:", v1.Type())
>> v2 := reflect.TypeOf(x)
>> fmt.Println("type:", v2)
>> }
>>
>> Kan we have something like this instead please
>>
>> package main
>>
>> import (
>> "fmt"
>> "reflect"
>> )
>>
>> func main() {
>> x := 4
>> r := reflect(x)
>> fmt.Println("type:", r.Type())
>> fmt.Println("value:", r.Value(int))
>> }
>>
>> Reflect should be a generic way of Go2, but everytime i need to reflect 
>> around a Go1 interface i want to go on a vacation...
>>
>>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: [Go2] Reflect

2017-08-06 Thread Rich
I don't understand... doesn't Reflect already do this?
https://play.golang.org/p/CIm7aISztv


On Saturday, August 5, 2017 at 12:58:52 PM UTC-4, Gert wrote:
>
> package main
>
> import (
> "fmt"
> "reflect"
> )
>
> func main() {
> x := 4
> v1 := reflect.ValueOf(x)
> fmt.Println("type:", v1.Type())
> v2 := reflect.TypeOf(x)
> fmt.Println("type:", v2)
> }
>
> Kan we have something like this instead please
>
> package main
>
> import (
> "fmt"
> "reflect"
> )
>
> func main() {
> x := 4
> r := reflect(x)
> fmt.Println("type:", r.Type())
> fmt.Println("value:", r.Value(int))
> }
>
> Reflect should be a generic way of Go2, but everytime i need to reflect 
> around a Go1 interface i want to go on a vacation...
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.