Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement set operation #76

Closed
corona10 opened this issue Sep 10, 2019 · 6 comments
Closed

Implement set operation #76

corona10 opened this issue Sep 10, 2019 · 6 comments
Assignees

Comments

@corona10
Copy link
Collaborator

These operations should be implemented

>>> a = {1, 2, 3}
>>> b = {2, 3, 4, 5}
>>> a | b
{1, 2, 3, 4, 5}
>>> a & b
{2, 3}
>>> a - b
{1}
>>> a ^ b
{1, 4, 5}
>>>
@corona10
Copy link
Collaborator Author

corona10 commented Sep 10, 2019

These operations can be implemented on here based on below code.

https://github.com/go-python/gpython/blob/master/py/set.go#L65

func (s *Set) M__and__(other Object) (Object, error) {
        // TODO: Implement
       return ret, nil
}

@DoDaek
Copy link
Contributor

DoDaek commented Sep 10, 2019

I want to implement this issue

@corona10
Copy link
Collaborator Author

@DoDaek
I 'd like to recommend implementing M__and__ first.

@ncw
Copy link
Collaborator

ncw commented Sep 15, 2019

I wrote the set primitives for gotemplate here: https://github.com/ncw/gotemplate/blob/master/set/set.go

These were based off the python primitives so should work with very little modification other than changing the types.

Feel free to use those here :-)

@SanggiHong
Copy link
Contributor

SanggiHong commented Sep 29, 2019

Hi Team,

I found another operation to implement.

# python 3.7.4
>>> a = set([1,2,3])
>>> for ai in a:
...   print(ai)
...
1
2
3
# gpython
>>> a = set([1,2,3])
panic: interface conversion: py.Object is *py.List, not py.Tuple

goroutine 1 [running]:
github.com/go-python/gpython/py.SetNew(0xc0000ed290, 0xc00013ead0, 0x1, 0x3, 0x0, 0x14bc828, 0x0, 0x0, 0x42152e0)
	/Users/sanggihong/go/src/github.com/go-python/gpython/py/set.go:63 +0x20d
github.com/go-python/gpython/py.(*Type).M__call__(0xc0000ed290, 0xc00013ead0, 0x1, 0x3, 0x0, 0xc000115301, 0x104491e, 0xc0000f0ec0, 0xc00009db70)
	/Users/sanggihong/go/src/github.com/go-python/gpython/py/type.go:380 +0x82
github.com/go-python/gpython/py.Call(0x12f9f40, 0xc0000ed290, 0xc00013ead0, 0x1, 0x3, 0x0, 0x1279040, 0x1, 0xc0002a1e40, 0xc000115448)
	/Users/sanggihong/go/src/github.com/go-python/gpython/py/internal.go:169 +0x299
github.com/go-python/gpython/vm.callInternal(0x12f9f40, 0xc0000ed290, 0xc00013ead0, 0x1, 0x3, 0x0, 0xc0000cc370, 0xc0000f4e40, 0x0, 0x0, ...)
	/Users/sanggihong/go/src/github.com/go-python/gpython/vm/eval.go:1606 +0xcf
github.com/go-python/gpython/vm.(*Vm).Call(0xc00010c930, 0x1, 0x0, 0x0, 0x0, 0x0, 0xc0000f0ee0, 0xc00013eac0)
	/Users/sanggihong/go/src/github.com/go-python/gpython/vm/eval.go:1689 +0xf44
github.com/go-python/gpython/vm.do_CALL_FUNCTION(0xc00010c930, 0xc000000001, 0x0, 0x0)
	/Users/sanggihong/go/src/github.com/go-python/gpython/vm/eval.go:1428 +0x40
github.com/go-python/gpython/vm.RunFrame(0xc0000cc370, 0x0, 0xc000115a20, 0xc00013eac0, 0x0)
	/Users/sanggihong/go/src/github.com/go-python/gpython/vm/eval.go:1785 +0x338
github.com/go-python/gpython/vm.EvalCodeEx(0xc0000e4200, 0xc000140000, 0xc000140000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/sanggihong/go/src/github.com/go-python/gpython/vm/eval.go:2162 +0x1014
github.com/go-python/gpython/vm.Run(...)
	/Users/sanggihong/go/src/github.com/go-python/gpython/vm/eval.go:2182
github.com/go-python/gpython/repl.(*REPL).Run(0xc000146000, 0xc0002ad580, 0x10)
	/Users/sanggihong/go/src/github.com/go-python/gpython/repl/repl.go:99 +0x397
github.com/go-python/gpython/repl/cli.RunREPL()
	/Users/sanggihong/go/src/github.com/go-python/gpython/repl/cli/cli.go:147 +0x295
main.main()
	/Users/sanggihong/go/src/github.com/go-python/gpython/main.go:73 +0xf51

Would it be better to make a new issue?

@skx
Copy link

skx commented Jan 1, 2020

Looks like this bug is can be closed; the appropriate pull-requests linked here were merged :)

@corona10 corona10 closed this as completed Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants