-
Notifications
You must be signed in to change notification settings - Fork 0
Fix list to tuple #1
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improve, please
@@ -6,15 +6,15 @@ | |||
def _rangeImpl(start): | |||
def ap(end): | |||
step = 1 if start <= end else -1 | |||
return list(_buitins["range"](start, end + step, step)) | |||
return tuple(_buitins["range"](start, end + step, step)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_builtins["range"]
is very slow. please directly load range
instead. You can give an alias to range in global context, like
_glob = global
.
|
||
return ap | ||
|
||
|
||
globals()["range"] = _rangeImpl | ||
|
||
|
||
replicate = lambda count: lambda value: [value for _ in _buitins["range"](count)] | ||
replicate = lambda count: lambda value: tuple([value for _ in _buitins["range"](count)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not bind lambda to variable, use def.
also, avoid _builtins["range"]
.
@@ -37,7 +37,7 @@ def listToArray(lst): | |||
while xs is not None: | |||
result.append(xs.head) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result_app = result.append
for ...:
result_app(xs.head)
fromFoldableImpl = _mkFromFoldableImpl() | ||
|
||
length = lambda xs: len(xs) | ||
|
||
cons = lambda e: lambda l: [e, *l] | ||
cons = lambda e: lambda l: (e, *l) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use def
ll = list(l) | ||
ll.insert(i, a) | ||
return just(ll) | ||
return just(tuple(ll)) | ||
|
||
|
||
_insertAt = lambda just: lambda nothing: lambda i: lambda a: lambda l: _insertAtImpl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use def
@@ -137,24 +142,24 @@ def _updateAtImpl(just, nothing, i, a, l): | |||
return nothing | |||
ll = list(l) | |||
ll[i] = a | |||
return just(ll) | |||
return just(tuple(ll)) | |||
|
|||
|
|||
_updateAt = lambda just: lambda nothing: lambda i: lambda a: lambda l: _updateAtImpl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use def
|
||
|
||
_updateAt = lambda just: lambda nothing: lambda i: lambda a: lambda l: _updateAtImpl( | ||
just, nothing, i, a, l | ||
) | ||
|
||
reverse = lambda xs: list(reversed(xs)) | ||
reverse = lambda xs: tuple(reversed(xs)) | ||
|
||
|
||
def concat(xss): | ||
result = [] | ||
for x in xss: | ||
result.extend(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bind extend = result.extend
outside the loop.
There're a lot of same places you'd follow my above review to change
trying to fix:
purescript-python/purescript-prelude.py#2