Re: [go-nuts] Reflecting on an outer struct from a method of an inner one.

2018-09-07 Thread ianbruene
On Friday, September 7, 2018 at 3:01:23 AM UTC-5, Nigel Tao wrote: > > Building on Todd's example, you can add a little more type safety > (having the map value type be a "func etc" instead of "reflect.Value) > by Curry'ing the receiver: https://play.golang.org/p/n3sDpxfd2td > > I've also

Re: [go-nuts] Reflecting on an outer struct from a method of an inner one.

2018-09-07 Thread roger peppe
Ha, I wrote this version before I saw that response: https://play.golang.org/p/vO2TI7OeJk_E On 7 September 2018 at 09:00, Nigel Tao wrote: > Building on Todd's example, you can add a little more type safety > (having the map value type be a "func etc" instead of "reflect.Value) > by Curry'ing

Re: [go-nuts] Reflecting on an outer struct from a method of an inner one.

2018-09-07 Thread Nigel Tao
Building on Todd's example, you can add a little more type safety (having the map value type be a "func etc" instead of "reflect.Value) by Curry'ing the receiver: https://play.golang.org/p/n3sDpxfd2td I've also split up the single run function into two: one binds strings to functions, the second

Re: [go-nuts] Reflecting on an outer struct from a method of an inner one.

2018-09-06 Thread Nigel Tao
On Fri, Sep 7, 2018 at 1:53 PM Eric Raymond wrote: > ...provided, that is, that it's possible to get from the member name to a > function pointer that can be called like a closure. Does the reflection > system support such a call-indirect method? Yep. No embedding or other inheritance-like

Re: [go-nuts] Reflecting on an outer struct from a method of an inner one.

2018-09-06 Thread Todd Neal
Eric Raymond writes: > Obviously we can't use inheritance in the normal sense here, but I was > hoping that if an embedded instance of Cmd could discover the struct > instance it's part of, a similar thing could be pulled off. Alas, your > answer that this can't be done is unsurprising and

Re: [go-nuts] Reflecting on an outer struct from a method of an inner one.

2018-09-06 Thread Eric Raymond
On Thursday, September 6, 2018 at 9:45:37 PM UTC-4, Nigel Tao wrote: > > Asking about embedding and reflection sounds like an XY problem > (http://xyproblem.info/). Can you elaborate on what "walk through the > user-defined methods of a Cmd-like interpreter instance" is? > Sure. My

Re: [go-nuts] Reflecting on an outer struct from a method of an inner one.

2018-09-06 Thread Nigel Tao
On Fri, Sep 7, 2018 at 9:34 AM Eric Raymond wrote: > The attached program lists For future reference, it would probably be easier for the mailing list to discuss example code via a link to the Go playground, especially for runnable code. In this case: https://play.golang.org/p/IripNZNYIgo > In

[go-nuts] Reflecting on an outer struct from a method of an inner one.

2018-09-06 Thread Eric Raymond
This question is intended to assist implementation of a Go workalike for the Python Cmd library. This workalike will be made publicly available, The attached program lists Inner id as expected - that is, the fieldnames of the Outer structure. But ListFields is a method of Inner. In the