cosmos72 / gomacro Goto Github PK
View Code? Open in Web Editor NEWInteractive Go interpreter and debugger with REPL, Eval, generics and Lisp-like macros
License: Mozilla Public License 2.0
Interactive Go interpreter and debugger with REPL, Eval, generics and Lisp-like macros
License: Mozilla Public License 2.0
Right now, the tab complete requires that you tab through to see options. fmt.
+tab,tab,tab,tab,shift+tab
. That is a fantastic start. It would be even more awesome if a dropdown showed up or similar so you can see a list of autocomplete suggestions. Great for discoverability.
gomacro> fmt.Print<tab>
[Print Println Printf]
(with an underline on the current position, so underlined Print
)
currently types, constants, variables and functions must be declared before using them.
Compiled Go does not have this restriction - top level declarations can appear in any order.
It would be useful to have a "batch" mode that reproduces the same behaviour, to execute stock Go source files/packages in the interpreter
When I import my custom package, gomacro will report "gomacro compiled without support to load plugins - requires Go 1.8+ and Linux - cannot import packages at runtime".
How can I fix this problem?
My go version is: go version go1.9 darwin/amd64
OS version is macOS Sierra
We are building with Go 1.11 beta on Fedora Rawhide in preparation for the next release, and gomacro fails in TestInterfaceIoReader
. The output is not too verbose, so I'm not sure if it's a bug in Go 1.11, or something that needs to be fixed here:
Testing: "/builddir/build/BUILD/gomacro-2.7/_build/src/github.com/cosmos72/gomacro/xreflect"
+ GOPATH=/builddir/build/BUILD/gomacro-2.7/_build:/usr/share/gocode
+ go test -buildmode pie -compiler gc -ldflags '-extldflags '\''-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '\'''
// debug: importer: cannot find package "github.com/cosmos72/gomacro/xreflect" metadata, approximating it with reflection
// debug: struct xreflect.Request4Test
// debug: . map map[string]string
// debug: . ptr *xreflect.Response4Test
// debug: . . struct xreflect.Response4Test
// debug: . . . ptr *xreflect.Request4Test
--- FAIL: TestInterfaceIoReader (0.01s)
type_test.go:33: expecting true <bool>, found false <bool>
type_test.go:33: expecting true <bool>, found false <bool>
It would great to have a easy way to read and interpret a file full of expressions and declarations.
Perhaps there is always a way I'm not finding. The opposite of :write
. One could ideally :write
the current set of definitions and types, then :source
them back in later, in a different session.
Repro below assumes a local Redis server running on default port
// GOMACRO, an interactive Go interpreter with generics and macros
// Copyright (C) 2017-2018 Massimiliano Ghilardi <https://github.com/cosmos72/gomacro>
// License MPL v2.0+: Mozilla Public License version 2.0 or later <http://mozilla.org/MPL/2.0/>
// This is free software with ABSOLUTELY NO WARRANTY.
//
// Type :help for help
import "github.com/go-redis/redis"
// debug: created file "~/go/src/gomacro_imports/github.com/go-redis/redis/redis.go"...
// debug: compiling "~/go/src/gomacro_imports/github.com/go-redis/redis/redis.go" ...
client := redis.NewClient(&redis.Options{
. . . . Addr: "localhost:6379",
. . . . Password: "", // no password set
. . . . DB: 0, // use default DB
. . . . })
client
// Redis<localhost:6379 db:0> // *github.com/go-redis/redis.Client
pong, err := client.Ping().Result()
// reflect: Field index out of range
woot := client.Ping()
//reflect: Field index out of range
Should this "just work"? I don't even know where to start here...
I discovered this using GopherNotes, but just the bare CLI REPL shows the same errors.
Thanks for this great package and any help!
Zsh:
$ gomacro
[1] 7956 killed gomacro
Would be great to run commands prefixed with !
in a shell like in ipython (and others?), eg
gomacro> !ls -la
drwxr-xr-x 6 peter staff 204 12 Jul 22:49 .
drwxr-xr-x 3 peter staff 102 12 Apr 2014 ..
drwxr-xr-x 140 peter staff 4760 19 Mar 2016 5072f70927f95a13e54e775676c51ee144a14dd7
drwxr-xr-x 264 peter staff 8976 13 Aug 2017 5a774f194ac60210f83ba3cfa6c7a769f5600dee
More examples https://jakevdp.github.io/PythonDataScienceHandbook/01.05-ipython-and-shell-commands.html#Shell-Commands-in-IPython
This program, a first-order test of select and channel work, works fine under regular go, but not under gomacro.
package main
import "fmt"
var ch = make(chan string)
func a() {for {select {case b := <-ch: fmt.Printf("got from ch a= '%v'\n", b); if b == "q\
uit" { return }}}}
func main() {
go a()
ch <- "hi"
ch <- "quit"
}
under gomacro:
jaten@jatens-MacBook-Pro ~ $ gomacro
// GOMACRO, an interactive Go interpreter with generics and macros
// Copyright (C) 2017-2018 Massimiliano Ghilardi <https://github.com/cosmos72/gomacro>
// License MPL v2.0+: Mozilla Public License version 2.0 or later <http://mozilla.org/MPL/2.0/>
// This is free software with ABSOLUTELY NO WARRANTY.
//
// Type :help for help
gomacro> import "fmt"
gomacro> var ch = make(chan string)
gomacro> func a() {for {select {case b := <-ch: fmt.Printf("got from ch a= '%v'\n", b); if b == "quit" { return }}}}
repl.go:1:97: internal error: containLocalBinds() returned false, but block actually defined 1 Binds and 0 IntBinds:
Binds = map[]
Block =
{
select {
case b := <-ch:
fmt.Printf("got from ch a= '%v'\n", b)
if b == "quit" {
return
}
}
}
gomacro>
This is a complex and challenging task.
The idea is to use gomacro as a playground to experiment with Go language extensions, since in many cases it's much easier to add new features to gomacro than to one of the Go compilers.
Generics in Go are a very discussed proposal, and many programmers would like to have them, but their complexity and the miriad of possible variations don't offer a clear solution. Implementing an official but suboptimal solution with warts and issues means that everybody will be stuck with them for a long time due to the need to preserve language compatibility.
Gomacro offers an escape hatch: it's an unofficial Go interpreter, and gives no guarantees analogous to the Go compatibity promise. It merely does a best-effort attempt to implement Go language, and already contains several extensions to it. In the author's opinion, it's a very good environment where to experiment further language extensions.
Combine it with gomacro author's love-hate relationship with C++ templates (love for the power, hate for the syntax) and his dislike for protracted programming discussions with no code to show for them, and you can imagine the outcome.
This issue exists to track progress of the generics implementation in gomacro. Feel free to comment.
I tried to :env inspect a large package (not publicly available) and got this error, readsig.go:66: unknown SigElemType: '9'
, followed by gomacro stopping.
$ gomacro
gomacro
// GOMACRO, an interactive Go interpreter with generics and macros
// Copyright (C) 2017-2018 Massimiliano Ghilardi <https://github.com/cosmos72/gomacro>
// License MPL v2.0+: Mozilla Public License version 2.0 or later <http://mozilla.org/MPL/2.0/>
// This is free software with ABSOLUTELY NO WARRANTY.
//
// Type :help for help
gomacro> :package "github.com/my/private/pkg"
...
gomacro> :env
:env
// ----- builtin binds -----
Eval = {0x47df830 ...
...
// ----- "github.com/my/private/pkg" binds -----
...
readsig.go:66: unknown SigElemType: '9'
$
Have to commend this work.
This is really amazing stuff.
The notebook integration is fab.
Now I am thinking about a 100% golang / web notebook like thing when you can write experiments and get benchmarking graphs , Venn diagrams to help with ML and other things where you need diagrams to cognitively understand the quantitative results.
Also i see another big ysecase here.
Slot of orgs will write their top layer of server code in nodejs because be it's fast to twiddle with etc but gomacro could fill its place nicely.
Also with the debugger. Now that's really powerful. This would mean you could attach to a running server, drain the connections off to another server in the cluster and degub a tough problem that requires live production data. Not having the data to reproduce a bug can be the source of lots of slow downs in fixing bugs.
If we could make a quasi IDE using a shall then it allows all these amazing possibilities.
There are a few out there I think....
as highlighted by @morangorin in #42. He also adds:
would it be possible to have a smaller and simpler version of gomacro ? (perhaps at the cost of performance and/or features ?)
go get -v -d github.com/cosmos72/gomacro/...
tries to compile everything in gomacro which results with the following error:
package github.com/cosmos72/gomacro/experiments/jit/template/arm64: C source files
not allowed when not using cgo or SWIG: bitmask_immediate.c set.c
go build github.com/cosmos72/gomacro/...
returns the same error.
Adding import "C"
in one of the go file in experiments/jit/template/arm64
fixes the errors but then many others are triggered like:
# github.com/cosmos72/gomacro/experiments/jit/template/arm64
add.s:8:2: error: unknown use of instruction mnemonic without a size suffix
add x0,x0,x0
^
add.s:9:2: error: unknown use of instruction mnemonic without a size suffix
add x0,x0,x1
^
Would it be possible to have a version where everything compile in the master branch ?
For the classic interpreter (haven't tested with fast but looks to be the same)
When writing a composite literal array, slice, or map where the element (or key) is also a composite literal where the type is omitted the interpreter raised a nil
pointer dereference as the type inference doesn't yet look complete.
The following gives the error message runtime error: invalid memory address or nil pointer dereference
var p = map[string][]string{"world":{"hello"}}
where as the same expression with the type written explicitly evaluates fine
var p = map[string][]string{"world":[]string{"hello"}}
At classic/type.go#L175 the branch for handling the inference case looks to be empty and then evalType2
returns nil
. I understand that this is not a trivial implementation but a better error message from evalCompositeLiteral
in the event where evalType2
returns nil
would be appreciated. Or perhaps directly in evalType2
. Something along the lines of type inference not supported
?
github.com/peterh/liner is a linenoise-like terminal implementation with features like history, line editing and autocompletion. Adding this to the repl would make it significantly easier to use.
Ideally with the application's functions available. Do you think that can be done ?
import "context"
_, cancel := context.WithCancel(context.Background())
cancel()
will produce error:
interface conversion: interface {} is context.CancelFunc, not func()
Hey,
This is my first or second day using gomacro.
I got the following error today.
Steele232s-MacBook-Air:Desktop steele232 $ go install github.com/cosmos72/gomacro
github.com/cosmos72/gomacro
ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//Security.framework/Security.tbd and library file /System/Library/Frameworks//Security.framework/Security are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//IOKit.framework/Versions/A/IOKit.tbd and library file /System/Library/Frameworks//IOKit.framework/Versions/A/IOKit are out of sync. Falling back to library file for linking.
Steele232s-MacBook-Air:Desktop steele232 $ gomacro -bash: gomacro: command not found
I got the same error when I did the install command (like above) and when I do
go get -u github.com/cosmos72/gomacro
I am pretty sure I had gomacro working yesterday.. or at least I did the go get command from the README.md . But I don't really remember.
I installed this on my windows work computer and it was working great.
The docs say that things work better on iOS than they do on Windows, so I was surprised when I got this error. None of the codes looked remotely familiar, so I thought I'd bring it to you guys and see what you think.
Other System Details:
OS: macOS High Sierra version 10.13.6
PS I haven't restarted my computer, but I could do that if you think it would help 😛
Howdy,
I'm playing with this insane tool for the first time, and I've got a question. I'm thinking of embedding gomacro into my codebase and exposing a hook to drop into the interpreter. And so I'm wondering about the limits of the interpreter (if any!). Can the interpreter give access to unexported fields / call unexported methods (also on unexported types)? I have not been able to do it.
Thanks!
As Gomacro author,
I recently discovered that the current LGPL license is more restrictive than I want.
Thanks to @glycerine for pointing it out.
LGPL 3.0, section 4. Combined Works imposes the following when someone wants to distribute a commercial program that includes a (modified or unmodified) copy of LGPL code:
[you must] Do one of the following:
Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
Unluckily, dynamic linking in Go is cumbersome and extremely limited - the plugin module is more similar to dlopen()
than to dynamic linking, and currently only works on Linux and Go 1.8+ (support on Mac OS X and Go 1.10 is still alpha-quality in my opinion, and other platforms don't have it at all). In my opinion, dynamic linking is not a viable solution for Go code.
LGPL allows static linking (the norm for Go) of LGPL code with commercial code, but then the commercial code must be also provided as object files that can be relinked with a newer version of LGPL code. Again, this is very cumbersome. I have no wish to impose such a restriction on commercial programs that use gomacro.
I am looking for a license that
Suggestions welcome :)
Ideally, there would be a function available on fast.Interp
like:
Complete(prefix string) []string
which would return the list of possible completions. It seems that such list could be returned to liner using line.SetCompleter
to improve the REPL provided in gomacro.
First - wow! This is a great solution for Lisp-style interactive programming in Go. I'm very impressed.
Now I'm hoping to duplicate even more of the experience of programming in Lisp. When running in Emacs, I can reload either all of the definitions in the entire file, or single variable/function definitions. Trying this now with EvalFile in cmd.go results in issues with the package declaration.
I'm thinking of a workflow like:
How feasible is this?
Minimal reproduction:
type foo struct {
bar []foo
}
fooslice := make([]foo, 8)
fooslice[0].bar = fooslice[1:2] // Error
Running the above returns:
// GOMACRO, an interactive Go interpreter with generics and macros
// Copyright (C) 2017-2018 Massimiliano Ghilardi <https://github.com/cosmos72/gomacro>
// License MPL v2.0+: Mozilla Public License version 2.0 or later <http://mozilla.org/MPL/2.0/>
// This is free software with ABSOLUTELY NO WARRANTY.
//
// Type :help for help
gomacro> type foo struct {
. . . . bar []foo
. . . . }
gomacro> fooslice := make([]foo, 8)
gomacro> fooslice[0].bar = fooslice[1:2] // Error
reflect.Value.Convert: value of type []struct { 𒀸bar []xreflect.Forward } cannot be converted to type []xreflect.Forward
Thanks for any assistance!
While map elements are not themselves addressable, if the element is a pointer the pointee should be modifiable directly via map access as shown in this playground snippet.
gomacro> import "reflect" // Just a package with a handy struct.
gomacro> m := make(map[string]*reflect.SliceHeader)
gomacro> m["a"] = &reflect.SliceHeader{}
gomacro> m["a"].Len = 2
repl.go:1:1: cannot assign to m["a"].Len
repl.go:1:1: cannot take the address of a map element: m["a"]
I'm not sure if this is supposed to work; the README suggests that it should be.
Attempt to run the interpreted equivalent of the code here which outputs 2.
gomacro> var i interface{}
gomacro> i = 1
gomacro> import "fmt"
gomacro> fmt.Println(i.(int)+1)
// warning: expression returns 2 values, using only the first one: [int bool]
interface conversion: fast.I is func(*fast.Env) (reflect.Value, []reflect.Value), not func(*fast.Env) int
complex() of untyped constants should return an untyped complex, not a complex128:
gomacro> complex(1,2)
(1+2i) // complex128
should return instead (1+2i) // untyped.Lit
similarly, << of untyped floats exactly representable as untyped ints should not fail, see https://golang.org/ref/spec#Constant_expressions
gomacro> 1<<3.0
repl.go:1:4: invalid shift: 1 << 3
should return instead {int 8} // untyped.Lit
Reported by @korewayume in gopherdata/gophernotes#119
type Integer int
func (a Integer) Less(b Integer) bool {
return a < b
}
func (a *Integer) Add(b Integer) {
*a += b
}
type LessAdder1 interface {
Add(b Integer)
Less(b Integer) bool
}
type LessAdder2 interface {
Less(b Integer) bool
Add(b Integer)
}
var a Integer = 1
var b LessAdder1 = &a // ok
var c LessAdder2 = &a // error: reflect.Set: value of type func(int) is not assignable to type func(int) bool
In theory go-1.10 adds plugin support, i.e. go build -buildmode-plugin
also on Mac OS X.
In practice, trying to use it causes a panic... maybe the darwin implementation of plugins is not yet mature enough? See also golang/go#23369
Tests in go 1.9.2 fail because StrGensymInterface has invalid name (in base/constants.go, classic/interface.go, xreflect/gensym.go).
partially functional, working on it :)
To try the debugger, insert a statement (an expression is not enough) "break"
or _ = "break"
in some interpreted code, then execute the code.
Execution will stop at the "break"
, and the usual debugger commands will be available (type ? for help):
continue, finish, next, step, list, print ARG
The argument of print can be an expression, a statement or a declaration. Function calls and statements with side effects are supported.
Currently, step is a bit unreliable
When $GOPATH is a list, import statements in gomacro create erroneous directories in the filesystem. For example, /a:/b:/c/gomacro_imports/{pkg}.
I have a PR for this with more details.
I tried the following code using gomacro and got the following result:
gomacro> import (
. . . . "fmt"
. . . . "encoding/json"
. . . . )
gomacro> type Person struct {
. . . . Name string `json:"name"`
. . . . Age int `json:"age"`
. . . . }
gomacro> a := Person{Name: "Bob", Age: 10}
gomacro> b, _ := json.Marshal(a)
gomacro> fmt.Printf("%s", b)
{"Name":"Bob","Age":10}23 // int
<nil> // error
It seems like the field tags are not being picked up/processed correctly.
Here is a go playground reproduction to show the expected behaviour:
@novikk commented on Dec 19, 2017 in gopherdata/gophernotes#93
If I import a package and then make changes to a function in this package, these changes won't take any effect if I do not restart the kernel. Running the import again doesn't solve the issue, I need to restart the kernel, and re-run the imports.
@cosmos72 note: in gophernotes context, the kernel is gophernotes, which contains a vendored copy of gomacro
Just tried to install and got the error below. The error is followed by my setup. Ideas?
$ go version
go version go1.9.2 windows/amd64
$ go get -u github.com/cosmos72/gomacro
# github.com/cosmos72/gomacro/base/dep
C:\Users\mando\go\src\github.com\cosmos72\gomacro\base\dep\graph.go:238:10: undefined: strings.Builder
$ go env
set GOARCH=amd64
set GOBIN=C:/Users/mando/bin
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\mando\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
gomacro> import github.com/out001a/go-consistent
There are two errors when executing above line:
consistent
but not go-consistent
, so we must give it an alias go_consistent
or consistent
.go-consistent
, which is not a valid name.Having just been bitten by stale dependencies, I wonder if gomacro could add a flag to do this part of package import:
import _i "import/path/for/your/application"
under command from a go generate
run. In other words, if there was a flag (call it -genimport for discussion) to the gomacro
binary that caused import _i
output to be generated for the current working directory, then a
go:generate gomacro -genimport
line could be added to a file in the package we wish to keep up to date. Upon every build I always run go generate to keep the other parts up to date, and this would result in the x_package.go file also being kept up to date at the same time.
Would that make sense? I didn't see such a flag already but maybe there is already a way? Thanks for considering it.
Currently tests fail due to an invalid struct name generated by xreflect.approxInterfaceHeader
from StrGensymInterface
. Is this expected behaviour? The restriction on struct names was enforced in go1.9 in to fix golang/go#20600.
$ go test ./...
panic: reflect.StructOf: field 0 has invalid name
goroutine 1 [running]:
reflect.StructOf(0xc420176680, 0x2, 0x2, 0x0, 0x0)
/home/daniel/Development/go/src/reflect/type.go:2404 +0x33e2
github.com/cosmos72/gomacro.init()
/home/daniel/Development/src/github.com/cosmos72/gomacro/all_test.go:145 +0x226
main.init()
<autogenerated>:1 +0x53
FAIL github.com/cosmos72/gomacro 0.010s
? github.com/cosmos72/gomacro/ast2 [no test files]
? github.com/cosmos72/gomacro/base [no test files]
? github.com/cosmos72/gomacro/classic [no test files]
? github.com/cosmos72/gomacro/example [no test files]
? github.com/cosmos72/gomacro/example/earljwagner1 [no test files]
? github.com/cosmos72/gomacro/example/earljwagner2 [no test files]
ok github.com/cosmos72/gomacro/experiments 0.001s [no tests to run]
? github.com/cosmos72/gomacro/experiments/bytecode_interfaces [no test files]
? github.com/cosmos72/gomacro/experiments/bytecode_values [no test files]
? github.com/cosmos72/gomacro/experiments/closure_interfaces [no test files]
? github.com/cosmos72/gomacro/experiments/closure_maps [no test files]
? github.com/cosmos72/gomacro/experiments/closure_values [no test files]
? github.com/cosmos72/gomacro/fast [no test files]
? github.com/cosmos72/gomacro/imports [no test files]
? github.com/cosmos72/gomacro/parser [no test files]
? github.com/cosmos72/gomacro/scanner [no test files]
? github.com/cosmos72/gomacro/token [no test files]
? github.com/cosmos72/gomacro/typeutil [no test files]
--- FAIL: TestInterface1 (0.00s)
panic: reflect.StructOf: field 0 has invalid name [recovered]
panic: reflect.StructOf: field 0 has invalid name
goroutine 38 [running]:
testing.tRunner.func1(0xc4201cc4b0)
/home/daniel/Development/go/src/testing/testing.go:711 +0x2d2
panic(0xf64380, 0xc42018c460)
/home/daniel/Development/go/src/runtime/panic.go:491 +0x283
reflect.StructOf(0xc42028e000, 0x3, 0x3, 0x0, 0x0)
/home/daniel/Development/go/src/reflect/type.go:2404 +0x33e2
github.com/cosmos72/gomacro/xreflect.(*Universe).InterfaceOf(0xc4202042c0, 0xc420042ce0, 0x2, 0x2, 0xc420042d00, 0x2, 0x2, 0x0, 0x0, 0x0, ...)
/home/daniel/Development/src/github.com/cosmos72/gomacro/xreflect/interface.go:81 +0x5c7
github.com/cosmos72/gomacro/xreflect.InterfaceOf(0xc420042ce0, 0x2, 0x2, 0xc420042d00, 0x2, 0x2, 0x0, 0x0, 0x0, 0x1, ...)
/home/daniel/Development/src/github.com/cosmos72/gomacro/xreflect/interface.go:100 +0xc9
github.com/cosmos72/gomacro/xreflect.TestInterface1(0xc4201cc4b0)
/home/daniel/Development/src/github.com/cosmos72/gomacro/xreflect/type_test.go:109 +0x1c6
testing.tRunner(0xc4201cc4b0, 0x10b5488)
/home/daniel/Development/go/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
/home/daniel/Development/go/src/testing/testing.go:789 +0x2de
FAIL github.com/cosmos72/gomacro/xreflect 0.010s
it's a tricky corner case, but needed nevertheless.
For compiled interfaces, i.e. interfaces imported from compiled packages, it works already.
Looking to improve my resume with the contribution to golang open-source projects. I'm an experienced lisper, so the idea of this thing is clear and attractive. Made two contributions to gitql recently. Also I have my own slime-based IDE for CL, written in tcl/tk.
It would make scripting easier if missing imports for standard libraries are automatically added. I have found the behaviour provided by this tool very helpful while scripting: https://godoc.org/golang.org/x/tools/cmd/goimports . The feature can be optional or only available for an interactive shell. Just an idea.
Hi, I'm having difficulty getting the aws-sdk working with gomacro.
jovyan@6ee76cc0911e:~$ go version
go version go1.12 linux/amd64
jovyan@6ee76cc0911e:~$ go get github.com/aws/aws-sdk-go/...
jovyan@6ee76cc0911e:~$ gomacro
// GOMACRO, an interactive Go interpreter with generics and macros
// Copyright (C) 2018-2019 Massimiliano Ghilardi <https://github.com/cosmos72/gomacro>
// License MPL v2.0+: Mozilla Public License version 2.0 or later <http://mozilla.org/MPL/2.0/>
// This is free software with ABSOLUTELY NO WARRANTY.
//
// Type :help for help
gomacro> import "github.com/aws/aws-sdk-go/aws"
// debug: created file "/go/src/gomacro_imports/github.com/aws/aws-sdk-go/aws/aws.go"...
// debug: compiling "/go/src/gomacro_imports/github.com/aws/aws-sdk-go/aws/aws.go" ...
# gomacro_imports/github.com/aws/aws-sdk-go/aws
./aws.go:8:2: imported and not used: "context"
error executing "/usr/local/go/bin/go build -buildmode=plugin" in directory "/go/src/gomacro_imports/github.com/aws/aws-sdk-go/aws/": exit status 2
It would be nice to be able to import packages from Go module in current directory.
My use case is launching gomacro from project directory to interactively test functions.
What do you think?
Due to golang/go#23733 for Go 1.10~1.11, delve is unable to debug a Go app if "plugin" is imported, err like:
API server listening at: 127.0.0.1:64634
could not launch process: decoding dwarf section info at offset 0x0: too short
Debugger finished with exit code 1
Debug will be normal if imports/plugin.go
is removed. And dynamic imports work just fine per my run (OSX 10.11 Go1.11).
As golang/go#23733 will seemingly only go into Go1.12 in the future, I would suggest stop shipping imports/plugin.go
by default.
Problem:
Question:
would it be possible to have a smaller and simpler version of gomacro ? (perhaps at the cost of performance and/or features ?)
most test failures seem to be caused by gomacro incorrectly believing that time.Duration.String
needs a pointer receiver i.e. a *time.Duration
Hello,
I'd like to know where is the problem with this piece of code:
package main
import(
"fmt"
"bytes"
"github.com/cosmos72/gomacro/fast"
)
const source = `type T struct{}
func (*T) F() {}
`
func main(){
src := bytes.NewReader([]byte(source))
it := fast.New()
if _, err := it.EvalReader(src); err != nil { panic(err) }
v, _ := it.Eval1("new(T)")
fmt.Println(v.NumMethod())
}
It prints «0» (zéro). So that's mean that with a type with methods when a value is created from this type, it don't have the methods.
The strings.Builder type is apparently not being properly recognized by gomacro.
The example code from the go documentation: https://play.golang.org/p/Dv96oDHG0tF
Does not correctly run in gomacro:
$ gomacro
// GOMACRO, an interactive Go interpreter with generics and macros
// Copyright (C) 2017-2018 Massimiliano Ghilardi <https://github.com/cosmos72/gomacro>
// License MPL v2.0+: Mozilla Public License version 2.0 or later <http://mozilla.org/MPL/2.0/>
// This is free software with ABSOLUTELY NO WARRANTY.
//
// Type :help for help
gomacro> package main
// debug: package main has no effect. To switch to a different package, use package "PACKAGE/FULL/PATH" - note the quotes
gomacro>
gomacro> import (
. . . . "fmt"
. . . . "strings"
. . . . )
gomacro>
gomacro> func main() {
. . . . var b strings.Builder
. . . . for i := 3; i >= 1; i-- {
. . . . fmt.Fprintf(&b, "%d...", i)
. . . . }
. . . . b.WriteString("ignition")
. . . . fmt.Println(b.String())
. . . .
. . . . }
repl.go:2:7: not a type: strings.Builder <*ast.SelectorExpr>
gomacro>
The builtin len() function fails on the following:
gomacro> a := [...]int{1,2,3}
gomacro> a
[1 2 3] // [3]int
gomacro> cap(a)
3 // int
gomacro> len(a)
runtime error: invalid memory address or nil pointer dereference
This is on an x86-64 Linux system running kernel 4.14.60. Doubt the system I'm running has much to do with this error but if so just let me know and I can provide further details.
Thanks,
Jason
I've just installed gomacro. built with go-1.10 on linux/amd64.
While the command works for once-off evaluating expressions being passed to it, if I run gomacro with no flags, to get the repl, the program hangs indefinitely and I have to manually kill it by pid. An strace on the process shows it blocked on a pselect.
Are there any known issues running the repl on linux (specifically Ubuntu 16.04)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.