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

Implicit application doesn't work if the function's first token is a string literal #821

Closed
GolfingSuccess opened this issue Jan 18, 2024 · 2 comments

Comments

@GolfingSuccess
Copy link

GolfingSuccess commented Jan 18, 2024

This snippet doesn't work as I'd expect it to:

x = 'b'
print('abc'.find x)

I would expect it to print 1; instead, it fails like this:

$ cat test.coco
x = 'b'
print('abc'.find x)
$ ./coconut test.coco
Compiling         test.coco ...
CoconutParseError: parsing failed (line 2 in 'test.coco')
  print('abc'.find x)
Coconut exiting with error: CoconutParseError
$ ./coconut --version
Coconut: Version 3.0.4 running on Python 3.10.12 and Cython cPyparsing v2.4.7.2.3.2
$

An interesting behavior appears if I try it in the REPL:

Coconut Interpreter v3.0.4 (Python 3.10):
(enter 'exit()' or press Ctrl-D to end)
>>> x = 'b'
>>> print('abc'.find x)

CoconutParseError: parsing failed (line 1)
  print('abc'.find x)
  \~~~~~~~~~~~~~~~~^
>>>

Notice the empty line above the error: it actually waited for me to "continue" writing, so I just pressed Enter and the error appeared.

If I add parentheses, as in print(('abc').find x) or print(('abc'.find) x), it does print 1.

Edit: This blocking behavior also occurs if I type something nonsensical, like ('abc'.'find') x, or just 'abc'.'find' (that last one spits a CoconutSyntaxWarning before blocking, but then fails anyway).

evhub added a commit that referenced this issue Jan 18, 2024
@evhub evhub added the resolved label Jan 18, 2024
@evhub
Copy link
Owner

evhub commented Jan 18, 2024

I had disabled this exact case for some reason because it was causing some parsing inconsistencies and I didn't think anyone was using it, but reenabling it now doesn't seem to break any tests anymore, and I don't think this is super confusing or anything, so I'll bless this syntax as allowed. This should be reenabled as of coconut-develop>=3.0.4-post_dev16 (pip install -U coconut-develop>=3.0.4-post_dev16 to get the fix).

@evhub evhub closed this as completed Jan 18, 2024
@GolfingSuccess
Copy link
Author

GolfingSuccess commented Jan 18, 2024

Ah, well to be fair I've come across it due to code golf, so I'm not the perfect example of "everyday usage"... 😂 Thanks a lot!!!

@evhub evhub added this to the v3.1.0 milestone Feb 25, 2024
@evhub evhub mentioned this issue Mar 1, 2024
evhub added a commit that referenced this issue Mar 2, 2024
See Coconut's
[documentation](http://coconut.readthedocs.io/en/develop/DOCS.html) for
more information on all of the features listed below.

Language changes:
* #814: Changes to statement lambda scoping rules, including capturing
names introduced in the surrounding expression.
* #618: Changes to handling of pattern-matching function defaults
including support for e.g. `match def f(x, y=x) = (x, y)`.
* #809: New array concatenation implicit partials (e.g. `[. ; a]`).
* #823: New `(x := .)` implicit partial syntax (only available in
pipes).
* #807: New `lift_apart` built-in combinator.
* #813: New `(if)` operator function.
* #826 (thanks @JayXon!): Better universalization and `fmap` support for
`bytes` and `bytearray`.
* #816: Support for `xarray` to match existing `numpy`/`pandas` support.
* #817: New `to` argument to `all_equal`.
* #821 (thanks @GolfingSuccess!): Expanded implicit function application
syntax to support string literal methods.

Compiler changes:
* #799: `coconut-run` and `coconut --run` now work on packages rather
than just files.
* #812: Better formatting of Coconut exceptions.

Bugfixes:
* #810: Fixed an issue compiling certain syntax constructs in the
Coconut Jupyter kernel.
* #818, #825 (thanks @kg583, @dokutan!): Fixed parsing of different
Unicode line break characters.
* #822 (thanks @JayXon!): Fixed parsing of Unicode backward pipe
operators.
* #819, #820 (thanks @kg583!): Fixed some incompatibilities between
Python and Coconut syntax.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants