[pypy-dev] Application-level helpers
Guido van Rossum
guido at python.org
Wed Jul 9 17:39:23 MEST 2003
> [...] For example, dictobject.py currently contains the magic code:
>
> def dict_update__Dict_Dict(space, w_self, w_other):
> w_self.space.gethelper(applicationfile).call("dict_update", [w_self,
> w_other])
>
> Instead it could directly contain:
>
> def app_dict_update(d,o):
> for k in o.keys():
> d[k] = o[k]
> dict_update__Dict_Dict = appfunction(app_dict_update)
Hurray! Wonderful!!
> This means that app_dict_update() is a helper function that you
> write at application-level (hence the app_ prefix), whereas
> dict_update__Dict_Dict is a wrapper around it that you can call from
> interpreter-level with an extra "space" first argument.
>
> The change seems to be minor, but consider that helpers would now be
> together with the place they really belong to. They could be used
> directly as methods in classes, too. In short they make the bridge
> between interpreter-level and application-level code much
> smaller. The application-level code can also be allowed to call not
> only other application-level code, but interpreter-level one, all
> transparently (because they essentially live in the same globals).
So e.g. if there was another function, app_dict_merge(d, o), it could
call app_dict_update(d, o) directly, right? Great!
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the pypy-dev
mailing list