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

Allow custom in-place-operators #729

Open
yggdr opened this issue Apr 16, 2023 · 2 comments
Open

Allow custom in-place-operators #729

yggdr opened this issue Apr 16, 2023 · 2 comments
Labels

Comments

@yggdr
Copy link

yggdr commented Apr 16, 2023

Currently we have the possibility to create our own custom operators like so:

operator ~~
def left ~~ right = dostuff(right) - dostuff(left)

but we don't seem to have a possibility to create in-place versions. I propose an additional language-construct like

in-place-operator ~~=

that takes an already defined operator ~~ (like above) and creates new functionality allowing left ~~= right to be syntactic sugar for left = left ~~ right.

@evhub evhub added the feature label Apr 16, 2023
@evhub evhub modified the milestone: v3.0.0 Apr 16, 2023
@evhub
Copy link
Owner

evhub commented Apr 16, 2023

You can always do

operator ~~
(~~) = (,)
x = 1
x |>= (. ~~ 2)
assert x == (1, 2)

which even compiles down to remove the partial and give you the exact code you'd want for an in-place operator:

_coconut_op_U7e_U7e = (_coconut_comma_op)
x = 1
x = (_coconut_op_U7e_U7e)(x, 2)
assert x == (1, 2)

@soupierre
Copy link

Hello, I am going to try and do that.

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

No branches or pull requests

3 participants