On Thu, Aug 30, 2018 at 11:34 AM Eric Raymond <e...@thyrsus.com> wrote:
>
>
>
> On Thursday, August 30, 2018 at 1:14:25 PM UTC-4, Jan Mercl wrote:
>>
>> On Thu, Aug 30, 2018, 18:57 Eric Raymond <e...@thyrsus.com> wrote:
>>>
>>> I'm trying to translate this to Go in a type-safe way. To do this, I need 
>>> to be able to write two declarations: "Slice of pointers to objects 
>>> satisfying the Event interface"
>>
>>
>> []*Event, but quite probably []Event is what is really needed.
>>
>>> and "map of string keys to pointers to objects satisfying the Event 
>>> interface".
>>
>>
>> map[string]*Event, but once again, my bet is on map[string]Event.
>>
>>> My attempts so far have yielded very cryptic error messages and no success.
>>
>>
>> It would probably help your case if you could provide some self-contained 
>> example reproducing the errors and post a link to the Go Playground.
>
>
> That's hard.  The structures are intertwingled parts of ab only partly 
> translated 14KLOC program  But I can isolate some key declarations.  If Event 
> is my interface type, and I write
>
>     events []Event
>     _mark_to_object  map[string]*Event


If Event is your interface and EventImpl is your struct, what you need
is a map[string]Event, not map[string]*Event. Make sure you put
&EvenImpl{} to your slices and maps, not EventImpl{}

>
> as member declarations in the Repository class, and b is a pointer to a 
> just-allocated instance of a Blob object satisfying the Event interface, and  
> I write this
>
>  b.repo._mark_to_object[mark] = b
>
> I get this message:
>
> cannot use b (type *Blob) as type *Event in assignment:
> *Event is pointer to interface, not interface
>
> Note that the map values really do need to be pointers, because I need the 
> map to refer to the mutable data in the event list, not a local copy of it in 
> the map.  What's stumping me is how to communicate this to the compiler.
>
> --
> 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.

Reply via email to