Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Implement sorted() builtin #16

Closed
trotterdylan opened this issue Jan 4, 2017 · 4 comments
Closed

Implement sorted() builtin #16

trotterdylan opened this issue Jan 4, 2017 · 4 comments

Comments

@trotterdylan
Copy link
Contributor

No description provided.

@MirkoDziadzka
Copy link
Contributor

Just curious, is there a way in grumpy to implement a builtin function in Python?

My naïve approach of adding a Python implementation of sorted() to lib/__buildin__.py does not work (see https://github.com/MirkoDziadzka/grumpy/commit/0fe34aea09691d26a3ad6c31b4ab323638de270c)

@trotterdylan
Copy link
Contributor Author

This limitation is briefly discussed here: #50

I haven't given it a whole lot of thought but I think it's actually a bit of a pain to make this work. The basic issue is that the __builtin__ Go package would need to import grumpy (the runtime package) to work properly, and the runtime package would need to import __builtin__ so that it could populate it with the stuff implemented in Go. So there's a circular dependency.

Unfortunately, we do need to get this working because there is Python code out there that adds its own functions to __builtin__.

One possible approach would be to have __builtin__.py replace its own module __dict__ with __go__.grumpy.Builtins. I don't think this would work as-is, but something along these lines:

# __builtin__.py
from __go__.grumpy import Builtins
import sys
sys.modules['__builtin__'].__dict__ = Builtins

@MirkoDziadzka
Copy link
Contributor

MirkoDziadzka commented Jan 17, 2017

looks like sorted() is already implemented in #100 via 384954e

@trotterdylan
Copy link
Contributor Author

Whoops, sorry about that Mirko. Closing this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants