Re: [go-nuts] Hoogle for Go

437 views
Skip to first unread message

andrey mirtchovski

unread,
Feb 20, 2013, 6:31:23 PM2/20/13
to jos...@poehls.me, golang-nuts
something like this (example search restricted to Go below)?

http://code.google.com/codesearch
http://code.google.com/codesearch#search/&q=%5Efunc%20isOddInt%20lang:%5Ego$&type=cs

that is restricted to projects hosted on code.google.com, but I
imagine the people behind godoc.org could add a codesearch option if
they're storing all the projects locally.

Damian Gryski

unread,
Feb 21, 2013, 7:46:26 AM2/21/13
to golan...@googlegroups.com, jos...@poehls.me
Or something like http://codesearch.debian.net/ ?  It's based on Russ's codesearch tool, but with an web front-end.  Source code at: https://github.com/debiancodesearch/dcs .

Damian

Joshua Poehls

unread,
Feb 21, 2013, 8:25:14 AM2/21/13
to Damian Gryski, mirtc...@gmail.com, golan...@googlegroups.com
Similar, but I was actually referring to the approximate type signature search that Hoogle offers.

Here are some example queries with syntax slightly tweaked from Hoogle.

"_a -> _a" to find any func that takes 1 argument and returns 1 value with the same type as the argument. This would match the math Abs func: func Abs(x float64) float64

"float64 -> float64" to find any func that takes 1 float64 arg and returns 1 float64 value. Also matches math Abs func.

"([Writer], string) -> (int, error)" to find any func that takes 2 args, the first being any type that implements the Writer interface, the 2nd being a string, and returns a tuple of an int and error. This would find strings  func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error)

"(_a, _b) -> (int, error)" to find any func that takes 2 args of different types (any types) and returns a tuple of int and error. Would also match WriteString.

Barring insanely crafty regex searches, I don't believe it's currently possible to do these types of searches over Go packages. I'm mostly wondering if this is something people would find useful.

I think Hoogle is insanely useful for Haskell but that could be due to the nature of the Haskell language.

--
Joshua Poehls

Jeremy Wall

unread,
Feb 21, 2013, 1:51:55 PM2/21/13
to Joshua Poehls, Damian Gryski, mirtc...@gmail.com, golang-nuts
you might be able to get similar functionality using go fmt -r 'pattern -> pattern' -l to list matches to a rewrite rule.


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

Rémy Oudompheng

unread,
Feb 21, 2013, 6:07:52 PM2/21/13
to Joshua Poehls, Damian Gryski, mirtc...@gmail.com, golan...@googlegroups.com
On 2013/2/21 Joshua Poehls <jos...@poehls.me> wrote:
> Similar, but I was actually referring to the approximate type signature
> search that Hoogle offers.
>
> Here are some example queries with syntax slightly tweaked from Hoogle.
>
> "_a -> _a" to find any func that takes 1 argument and returns 1 value with
> the same type as the argument. This would match the math Abs func: func
> Abs(x float64) float64
>
> "float64 -> float64" to find any func that takes 1 float64 arg and returns 1
> float64 value. Also matches math Abs func.
>
> "([Writer], string) -> (int, error)" to find any func that takes 2 args, the
> first being any type that implements the Writer interface, the 2nd being a
> string, and returns a tuple of an int and error. This would find strings
> func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error)
>
> "(_a, _b) -> (int, error)" to find any func that takes 2 args of different
> types (any types) and returns a tuple of int and error. Would also match
> WriteString.
>
> Barring insanely crafty regex searches, I don't believe it's currently
> possible to do these types of searches over Go packages. I'm mostly
> wondering if this is something people would find useful.
>
> I think Hoogle is insanely useful for Haskell but that could be due to the
> nature of the Haskell language.

I took some time to write such a tool that searches in the Go API file
(so it works for the standard library or anything you run through the
api tool).
To fetch it:
go get github.com/remyoudompheng/go-misc/apisearch

By default it looks into the Go 1 API file. Here are some examples:

$ ./apisearch -e "func ([]a, a) int"
using pattern: func([]a, a) int
looking in "/opt/remy/go/api/go1.txt"
bytes.IndexByte: func ([]uint8, uint8) int
sort.SearchFloat64s: func ([]float64, float64) int
sort.SearchInts: func ([]int, int) int
sort.SearchStrings: func ([]string, string) int

$ ./apisearch -e "func(io.Reader) a"
using pattern: func(io.Reader) a
looking in "/opt/remy/go/api/go1.txt"
archive/tar.NewReader: func (io.Reader) *Reader
bufio.NewReader: func (io.Reader) *Reader
compress/bzip2.NewReader: func (io.Reader) io.Reader
compress/flate.NewReader: func (io.Reader) io.ReadCloser
encoding/ascii85.NewDecoder: func (io.Reader) io.Reader
encoding/csv.NewReader: func (io.Reader) *Reader
encoding/gob.NewDecoder: func (io.Reader) *Decoder
encoding/json.NewDecoder: func (io.Reader) *Decoder
encoding/xml.NewDecoder: func (io.Reader) *Decoder
io/ioutil.NopCloser: func (io.Reader) io.ReadCloser
net/http/httputil.NewChunkedReader: func (io.Reader) io.Reader
testing/iotest.DataErrReader: func (io.Reader) io.Reader
testing/iotest.HalfReader: func (io.Reader) io.Reader
testing/iotest.OneByteReader: func (io.Reader) io.Reader
testing/iotest.TimeoutReader: func (io.Reader) io.Reader

$ ./apisearch -e "func (...a) a"
using pattern: func(...a) a
looking in "/opt/remy/go/api/go1.txt"
io.MultiReader: func (...Reader) Reader
io.MultiWriter: func (...Writer) Writer
path.Join: func (...string) string
path/filepath.Join: func (...string) string

$ ./apisearch -e "func(string, ...interface{}) a"
using pattern: func(string, ...interface{}) a
looking in "/opt/remy/go/api/go1.txt"
fmt.Errorf: func (string, ...interface{}) error
fmt.Sprintf: func (string, ...interface{}) string

A few corner cases are not implemented, have fun!

Rémy.

Joshua Poehls

unread,
Feb 21, 2013, 10:00:54 PM2/21/13
to Rémy Oudompheng, golan...@googlegroups.com
Whoa, that's great! Thanks!

--
Joshua Poehls
Reply all
Reply to author
Forward
0 new messages