]> Cypherpunks repositories - gostls13.git/commit
new command gotry.
authorRob Pike <r@golang.org>
Mon, 11 Oct 2010 19:40:13 +0000 (12:40 -0700)
committerRob Pike <r@golang.org>
Mon, 11 Oct 2010 19:40:13 +0000 (12:40 -0700)
commit570f59c1090b8c2f67f1f0426fd8decd650bd2f6
treef626d9c2af4dcf6fc51970859ae9a715e1029f40
parent17c9c01912f392f2c73678ad96e0c86b436c4c76
new command gotry.
An exercise in reflection and an unusual tool.

From the usage message:

usage: gotry [packagedirectory] expression ...
Given one expression, gotry attempts to evaluate that expression.
Given multiple expressions, gotry treats them as a list of arguments
and result values and attempts to find a function in the package
that, given the first few expressions as arguments, evaluates to
the remaining expressions as results.  If the first expression has
methods, it will also search for applicable methods.

If there are multiple expressions, a package directory must be
specified. If there is a package argument, the expressions are
evaluated in an environment that includes
import . "packagedirectory"

Examples:
gotry 3+4
# evaluates to 7
gotry strings '"abc"' '"c"' 7-5
# finds strings.Index etc.
gotry regexp 'MustCompile("^[0-9]+")' '"12345"' true
# finds Regexp.MatchString

R=rsc, PeterGo, r2
CC=golang-dev
https://golang.org/cl/2352043
src/cmd/gotest/Makefile
src/cmd/gotest/gotry [new file with mode: 0755]
src/pkg/Makefile
src/pkg/try/Makefile [new file with mode: 0644]
src/pkg/try/try.go [new file with mode: 0644]
src/pkg/try/try_test.go [new file with mode: 0644]