Closed aaaaalbert closed 8 years ago
The existing behavior was confusing to many users who wrote print "hello world" or similar and was two lines of output. So, we removed it in RepyV2.
callfunc == 'initialize' lets us have the equivalent of name == "main" so that code can be used as either a library or the main program.
On Wed, Oct 14, 2015 at 8:49 AM, aaaaalbert notifications@github.com wrote:
In RepyV1, the global callfunc variable is set to "initialize" https://github.com/SeattleTestbed/repy_v1/blob/master/repy.py#L204 when a program is started, and "exit" https://github.com/SeattleTestbed/repy_v1/blob/master/repy.py#L237 after its execution ended. See also the RepyV1 API docs on callfunc https://seattle.poly.edu/wiki/RepyApi#callfunc. (This allows one to emulate Python's sys.exitfunc https://docs.python.org/2/library/sys.html#sys.exitfunc, or the atexit module https://docs.python.org/2/library/atexit.html functionality.)
RepyV2 still has callfunc, but it's only ever set to "initialize" as far as I can tell https://github.com/SeattleTestbed/repy_v2/blob/master/repy.py#L129. "exit" isn't ever used; only the dylink lib sets it to "import" https://github.com/SeattleTestbed/seattlelib_v2/blob/master/dylink.r2py#L196 when it imports a module. (This can be used to replicate Python's if name == "main": idiom.)
I don't know how widely used callfunc != "initialize" ever was, nor why RepyV2 behaves the way it does. I do notice that "exit" was intentionally removed https://seattle.poly.edu/changeset/3416/seattle/branches/repy_v2/repy/repy.py, but the RepyV2 API docs mention it in one place https://seattle.poly.edu/wiki/RepyV2API#exitall. @JustinCappos https://github.com/JustinCappos, can you perhaps provide additional historical context?
— Reply to this email directly or view it on GitHub https://github.com/SeattleTestbed/repy_v2/issues/106.
Thanks!
This means we'll leave things as is:
callfunc == "initialize"
for starting a program,dylink
can set callfunc
as desired/required, andcallfunc == "exit"
in RepyV2.
In RepyV1, the global
callfunc
variable is set to"initialize"
when a program is started, and"exit"
after its execution ended. See also the RepyV1 API docs oncallfunc
. (This allows one to emulate Python'ssys.exitfunc
, or theatexit
module functionality.)RepyV2 still has
callfunc
, but it's only ever set to"initialize"
as far as I can tell."exit"
isn't ever used; only thedylink
lib sets it to"import"
when it imports a module. (This can be used to replicate Python'sif __name__ == "__main__":
idiom.)I don't know how widely used
callfunc != "initialize"
ever was, nor why RepyV2 behaves the way it does. I do notice that"exit"
was intentionally removed, but the RepyV2 API docs mention it in one place. @JustinCappos, can you perhaps provide additional historical context?