Re: [go-nuts] Library for printing a struct as a compiler recognized version

2022-08-16 Thread 'Dan Kortschak' via golang-nuts
On Mon, 2022-08-15 at 21:23 -0700, John wrote:
> Thank you everyone who responded.  Gave utter a look and its pretty
> decent.  I found litter a bit more developed around the circular
> reference area.  But both were great suggestions and just what I was
> looking for.


I would be careful with litter, it does not properly handle unexported
types or types in interface contexts.

https://go.dev/play/p/QM6zLUz0sx-
https://go.dev/play/p/hnazQoef1qP

I'd also be interested to know what you think utter is lacking in
handling circular references.

Dan

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9442090daecb9362bf38ee7dbcfdcf39430e13bf.camel%40kortschak.io.


Re: [go-nuts] Library for printing a struct as a compiler recognized version

2022-08-15 Thread John
Thank you everyone who responded.  Gave utter a look and its pretty 
decent.  I found litter a bit more developed around the circular reference 
area.  But both were great suggestions and just what I was looking for.

Again, thank you for helping me find these!

On Monday, August 15, 2022 at 3:59:05 PM UTC-7 kortschak wrote:

> On Mon, 2022-08-15 at 07:26 -0700, John wrote:
> > I know we have plenty of pretty printing out there, but i'm looking
> > for a package that can print the Go representation of a Struct out to
> > screen.
> >
> > So given:
> >
> > var x := {
> >   A: "hello"
> > }
> >
> > someLib.Print(x)
> >
> > I get:
> >
> > {
> >   A: "hello"
> > }
> >
> > I'm sure someone has used reflection to do this and figured out how
> > they want to deal with recursive pointers, so don't want to go
> > recreate the wheel here.
> >
> > Thanks.
>
> github.com/kortschak/utter will do this for most values (there are
> cases that are not possible due to requiring programmatic construction
> — pointers to strings, ints etc, and filled channels being examples).
>
> Dan
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/666011b3-d5ed-4528-9a41-e626ac84ab8bn%40googlegroups.com.


Re: [go-nuts] Library for printing a struct as a compiler recognized version

2022-08-15 Thread 'Dan Kortschak' via golang-nuts
On Mon, 2022-08-15 at 07:26 -0700, John wrote:
> I know we have plenty of pretty printing out there, but i'm looking
> for a package that can print the Go representation of a Struct out to
> screen.
>
> So given:
>
> var x := {
>   A: "hello"
> }
>
> someLib.Print(x)
>
> I get:
>
> {
>   A: "hello"
> }
>
> I'm sure someone has used reflection to do this and figured out how
> they want to deal with recursive pointers, so don't want to go
> recreate the wheel here.
>
> Thanks.

github.com/kortschak/utter will do this for most values (there are
cases that are not possible due to requiring programmatic construction
— pointers to strings, ints etc, and filled channels being examples).

Dan

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ed0ddac2db3db8fdccfedb252bdc66ef29685c80.camel%40kortschak.io.


Re: [go-nuts] Library for printing a struct as a compiler recognized version

2022-08-15 Thread Ian Davis
Perhaps https://github.com/kortschak/utter might suit your needs?

On Mon, 15 Aug 2022, at 4:07 PM, John wrote:
> Hey axel,
> 
> I recognize the problem space you are discussing. There are a couple 
> strategies I could implement to try and solve the problems.  And I'm not 100% 
> sure you can solve all of them.  But I certainly don't want to jump down the 
> rabbit hole of reflection myself if I don't have to.  So I'm looking for a 
> package that has attempted to do this.  I'd certainly take something that 
> can't handle every case.
> 
> So far my googlefoo hasn't found the key words that differentiate this from 
> pretty printing, or this type of package doesn't exist.
> 
> Thanks for your response axel.
> 
> 
> 
> On Monday, August 15, 2022 at 7:53:16 AM UTC-7 axel.wa...@googlemail.com 
> wrote:
>> I don't believe this is possible, in general. For example, consider
>> 
>> type S struct {
>> A *int
>> B *int
>> }
>> var x S
>> x.A = new(int)
>> x.B = x.A
>> 
>> There is no single expression for the value of x. Or
>> 
>> type P *P
>> x := new(P)
>> *x = x
>> 
>> Then you have values which represent more than just their plain memory 
>> resources. For example, an *os.File - restoring that would not give you the 
>> same thing.
>> 
>> There's lots of design space here and I don't think you can solve it in full 
>> generality. So, at the very least, you have to be very deliberate about what 
>> you want and what you are willing to give up.
>> 
>> But. Maybe someone else has suggestions for a library doing an approximation 
>> of this you'd like better.
>> 
>> 
>> 
>> On Mon, Aug 15, 2022 at 4:42 PM John  wrote:
>>> Hey axel,
>>> 
>>> Thanks for the reply, but unfortunately not. Because that is going to 
>>> simply print pointer values out.  I want it to unwind all of that (and 
>>> handle the difficulty of recursive references).  I want to be able to take 
>>> what is printed and simply paste it into a file assigned to a variable, add 
>>> the needed imports and have it compile.
>>> On Monday, August 15, 2022 at 7:34:08 AM UTC-7 axel.wa...@googlemail.com 
>>> wrote:
 Does fmt.Printf("%#v", v) do what you want?
 
 
 On Mon, Aug 15, 2022 at 4:27 PM John  wrote:
> I know we have plenty of pretty printing out there, but i'm looking for a 
> package that can print the Go representation of a Struct out to screen.
> 
> So given:
> 
> var x := {
>   A: "hello"
> }
> 
> someLib.Print(x)
> 
> I get:
> 
> {
>   A: "hello"
> }
> 
> I'm sure someone has used reflection to do this and figured out how they 
> want to deal with recursive pointers, so don't want to go recreate the 
> wheel here.
> 
> Thanks.
> 
> 
> 
> 
> -- 
> 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...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/f4fa3f7b-318e-407b-96ef-16102db1e037n%40googlegroups.com
>  
> .
>>> 
>>> 
>>> -- 
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/2029ba81-dbf5-44c2-ac9f-228dcb7837f4n%40googlegroups.com
>>>  
>>> .
> 
> 
> -- 
> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/0e2af167-4bad-49a1-8a12-e5218204b47fn%40googlegroups.com
>  
> .

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/bf70fe87-7d83-4b28-9401-3ef846def9be%40www.fastmail.com.


Re: [go-nuts] Library for printing a struct as a compiler recognized version

2022-08-15 Thread John
Hey axel,

I recognize the problem space you are discussing. There are a couple 
strategies I could implement to try and solve the problems.  And I'm not 
100% sure you can solve all of them.  But I certainly don't want to jump 
down the rabbit hole of reflection myself if I don't have to.  So I'm 
looking for a package that has attempted to do this.  I'd certainly take 
something that can't handle every case.

So far my googlefoo hasn't found the key words that differentiate this from 
pretty printing, or this type of package doesn't exist.

Thanks for your response axel.



On Monday, August 15, 2022 at 7:53:16 AM UTC-7 axel.wa...@googlemail.com 
wrote:

> I don't believe this is possible, in general. For example, consider
>
> type S struct {
> A *int
> B *int
> }
> var x S
> x.A = new(int)
> x.B = x.A
>
> There is no single expression for the value of x. Or
>
> type P *P
> x := new(P)
> *x = x
>
> Then you have values which represent more than just their plain memory 
> resources. For example, an *os.File - restoring that would not give you the 
> same thing.
>
> There's lots of design space here and I don't think you can solve it in 
> full generality. So, at the very least, you have to be very deliberate 
> about what you want and what you are willing to give up.
>
> But. Maybe someone else has suggestions for a library doing an 
> approximation of this you'd like better.
>
>
> On Mon, Aug 15, 2022 at 4:42 PM John  wrote:
>
>> Hey axel,
>>
>> Thanks for the reply, but unfortunately not. Because that is going to 
>> simply print pointer values out.  I want it to unwind all of that (and 
>> handle the difficulty of recursive references).  I want to be able to take 
>> what is printed and simply paste it into a file assigned to a variable, add 
>> the needed imports and have it compile.
>>
>> On Monday, August 15, 2022 at 7:34:08 AM UTC-7 axel.wa...@googlemail.com 
>> wrote:
>>
>>> Does fmt.Printf("%#v", v) do what you want?
>>>
>>> On Mon, Aug 15, 2022 at 4:27 PM John  wrote:
>>>
 I know we have plenty of pretty printing out there, but i'm looking for 
 a package that can print the Go representation of a Struct out to screen.

 So given:

 var x := {
   A: "hello"
 }

 someLib.Print(x)

 I get:

 {
   A: "hello"
 }

 I'm sure someone has used reflection to do this and figured out how 
 they want to deal with recursive pointers, so don't want to go recreate 
 the 
 wheel here.

 Thanks.


 -- 
 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...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/golang-nuts/f4fa3f7b-318e-407b-96ef-16102db1e037n%40googlegroups.com
  
 
 .

>>> -- 
>> 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...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/2029ba81-dbf5-44c2-ac9f-228dcb7837f4n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0e2af167-4bad-49a1-8a12-e5218204b47fn%40googlegroups.com.


Re: [go-nuts] Library for printing a struct as a compiler recognized version

2022-08-15 Thread John
Hey axel,

Thanks for the reply, but unfortunately not. Because that is going to 
simply print pointer values out.  I want it to unwind all of that (and 
handle the difficulty of recursive references).  I want to be able to take 
what is printed and simply paste it into a file assigned to a variable, add 
the needed imports and have it compile.

On Monday, August 15, 2022 at 7:34:08 AM UTC-7 axel.wa...@googlemail.com 
wrote:

> Does fmt.Printf("%#v", v) do what you want?
>
> On Mon, Aug 15, 2022 at 4:27 PM John  wrote:
>
>> I know we have plenty of pretty printing out there, but i'm looking for a 
>> package that can print the Go representation of a Struct out to screen.
>>
>> So given:
>>
>> var x := {
>>   A: "hello"
>> }
>>
>> someLib.Print(x)
>>
>> I get:
>>
>> {
>>   A: "hello"
>> }
>>
>> I'm sure someone has used reflection to do this and figured out how they 
>> want to deal with recursive pointers, so don't want to go recreate the 
>> wheel here.
>>
>> Thanks.
>>
>>
>> -- 
>> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/f4fa3f7b-318e-407b-96ef-16102db1e037n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2029ba81-dbf5-44c2-ac9f-228dcb7837f4n%40googlegroups.com.


Re: [go-nuts] Library for printing a struct as a compiler recognized version

2022-08-15 Thread 'Axel Wagner' via golang-nuts
Does fmt.Printf("%#v", v) do what you want?

On Mon, Aug 15, 2022 at 4:27 PM John  wrote:

> I know we have plenty of pretty printing out there, but i'm looking for a
> package that can print the Go representation of a Struct out to screen.
>
> So given:
>
> var x := {
>   A: "hello"
> }
>
> someLib.Print(x)
>
> I get:
>
> {
>   A: "hello"
> }
>
> I'm sure someone has used reflection to do this and figured out how they
> want to deal with recursive pointers, so don't want to go recreate the
> wheel here.
>
> Thanks.
>
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/f4fa3f7b-318e-407b-96ef-16102db1e037n%40googlegroups.com
> 
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfHnEbgaGEqh7_k-p%3DO%3D_PA8gVtQpV9TQCO%3D0zTP4%3DUhmQ%40mail.gmail.com.


[go-nuts] Library for printing a struct as a compiler recognized version

2022-08-15 Thread John
I know we have plenty of pretty printing out there, but i'm looking for a 
package that can print the Go representation of a Struct out to screen.

So given:

var x := {
  A: "hello"
}

someLib.Print(x)

I get:

{
  A: "hello"
}

I'm sure someone has used reflection to do this and figured out how they 
want to deal with recursive pointers, so don't want to go recreate the 
wheel here.

Thanks.


-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f4fa3f7b-318e-407b-96ef-16102db1e037n%40googlegroups.com.