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

Support // division conversion #54

Open
596050 opened this issue Nov 27, 2020 · 1 comment
Open

Support // division conversion #54

596050 opened this issue Nov 27, 2020 · 1 comment

Comments

@596050
Copy link

596050 commented Nov 27, 2020

When trying to convert this python code:

def binary_search_recursive(array, element, start, end):
    if start > end:
        return -1

    mid = (start + end) // 2
    if element == array[mid]:
        return mid

    if element < array[mid]:
        return binary_search_recursive(array, element, start, mid-1)
    else:
        return binary_search_recursive(array, element, mid+1, end)

An error is thrown, which seems to mean the // operator in python is not supported:
"An error occurred while compiling source file '/tmp/source/source.py'\r\n" "TransformationError: Node type 'FloorDiv': Line: n. a., column: n. a.. No transformation for the node\r\n"

Would it be possible to support this?
in metapensiero.pj/src/metapensiero/pj/transformations/special.py

# <code>2//3</code> &rarr; <code>Math.floor(2/3)</code>
def BinOp_floor(t, x):
    if isinstance(x.op, ast.FloorDiv):
        return JSCall(
            JSAttribute(
                JSName('Math'),
                'floor'),
                JSBinOp(x.left, JSOpDiv(), x.right)
            )
BinOp = [BinOp_floor, BinOp_pow, BinOp_default]
@azazel75
Copy link
Collaborator

If you are so kind to submit this together with a small test there's no problem, thanks! Otherwise i'll add it next time I've some time to dedicate to this project. Thanks!

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

No branches or pull requests

2 participants