0xfaded / eval

BSD 3-Clause "New" or "Revised" License
34 stars 7 forks source link

Showing Kind (versus type) in demo/eval.go results #8

Closed rocky closed 10 years ago

rocky commented 10 years ago

Why this?

$ ./eval
./eval
go> 1+2
1+2
Kind = int64
Results[0] = 3
go> Results[0]
Results[0]
Kind = interface
^^^^^^^^^^^^^^^! what's this? 
Results[1] = 3
go> Results
Results
Kind = slice
Results[2] = [3 3]
go> Results
Results
Kind = slice
Results[3] = [3 3 [3 3]]
go>

I don't understand why this comes back interface rather than some sort of int. And should we be showing Kind or the type? Thoughts?

rocky commented 10 years ago

I'm pretty sure this is my fault https://github.com/0xfaded/go-interactive/blob/master/interpreter.go#L51

I converted to an Interface() as a workaround so I could use the append() function. I didn't understand the error message when the straight reflect.Value was in there.

0xfaded commented 10 years ago

I think I would find knowing both the kind and type useful when playing with third party libraries. Up to you though

rocky commented 10 years ago

type information is a superset of kind isn't it?

0xfaded commented 10 years ago

Well, strictly speaking a type is a set of values, and a kind is a set of types. So yes, information about a type could also imply it's kind. But for practical purposes, I would like to see something like

type = Named(int)

for named types.

rocky commented 10 years ago

This is now done in the demo code in those cases where Kind is not the same thing as Type.