Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 12 18:27
    evhub closed #667
  • Aug 12 18:27
    evhub labeled #667
  • Aug 12 09:37
    tom-a-horrocks commented #667
  • Aug 12 08:29
    evhub commented #667
  • Aug 12 08:29
    evhub commented #667
  • Aug 12 08:09
    evhub commented #667
  • Aug 12 07:59
    evhub milestoned #667
  • Aug 12 07:59
    evhub labeled #667
  • Aug 12 04:23
    tom-a-horrocks edited #667
  • Aug 12 04:22
    tom-a-horrocks opened #667
  • Jul 18 19:21
    evhub labeled #666
  • Jul 18 19:21
    evhub closed #666
  • Jul 18 19:21
    evhub commented #666
  • Jul 18 19:20
    evhub labeled #666
  • Jul 18 19:20
    evhub edited #666
  • Jul 15 13:28
    timgates42 opened #666
  • Jul 05 00:31
    evhub labeled #665
  • Jul 04 12:07
    geezmolycos opened #665
  • May 27 09:13
    evhub closed #663
  • May 27 09:13
    evhub labeled #663
dontmindmehere
@dontmindmehere
I started learning Rust and now I'm missing the functional stuff in python xd
Evan Hubinger
@evhub
@dontmindmehere Ah, yes. Coconut handles whitespace just like Python, which means you can escape newlines with backslashes, but the preferred way is just to use parentheses, as in
num = (nums
    |> filter$((i -> i<3), ?)
    |> next$(?, 0))
dontmindmehere
@dontmindmehere
oh nice, didn't know you could do that
Aaron Virshup
@avirshup

Hi - I was wondering if there's any way to reproduce the functionality of pip install -e for a project with coconut files in it.

My guess is that you'd need to set up a file watcher (e.g., watchdog) to handle recompiling files when they're changed? But was wondering whether there might be alternative strategies

Evan Hubinger
@evhub
@avirshup Like you were saying, you could use coconut --watch—but better might be to use automatic compilation. If you make sure in the root of your project (e.g. the top-level __init__.coco) you import coconut.convenience then compile fully once, pip install -e should do what you want. Also, if you're using coconut-develop (which you can get via pip install -U coconut-develop), you can run coconut --site-install which will make coconut.convenience imported automatically on Python start so you don't have to import it in the project root.
Aaron Virshup
@avirshup
@evhub - Ah, apologies - I completely missed that in the documentation. That looks excellent, I'll try it out. Thanks!!!
Peter Henry
@mosbasik

Just heard of this via the recent HN thread; started going through the interactive tutorial. The pattern matching "now you try it" page (https://hmcfabfive.github.io/coconut-tutorial/Patternmatch/Patternmatch_p3.html) is a little rough around the edges, imo. I get that its purpose is to teach pattern matching syntax, but the solution makes a lot of choices the motivations behind which I don't understand.

fwiw, my solution was

from collections import Counter
items |> Counter |> print

(which btw I was pretty tickled to hit on, coconut makes that pretty darn clean :) )

  1. Why the choice to make itemsan iterator? Seems like it'd be fine to leave it as a list.
  2. Relatedly, later we could use a for loop instead of a whileloop and avoid manually defining a stop condition, manually calling next(), etc.
  3. Why mess around with a current variable inside the match branches? wouldn't an aluminums[0] += 1 work?
  4. I get that you need to pass mutable structure(s) into countItems() to accumulate results, which explains the single-element lists. One could use a single dict instead (arguably more Pythonic), but then of course you actually don't need the pattern matching at all because you just use the item string as the key and you only need to write a single case (which is how I hit on using Counter in the end).

I was surprised enough at these choices that I was expecting another page saying things like "we prefer to use iterators in coconut because...", but that was the end of the pattern matching section. So I was considering thinking for a little bit to come up with a toy problem that really demonstrates how pattern matching can improve on vanilla python's approach - but I hesitated because I haven't gone through the whole tutorial yet and wanted to make sure I wasn't being totally oblivious to something.

Peter Henry
@mosbasik
(some minutes later) naturally, of course, the tutorial continued to expand on pattern matching and showed off some meatier uses for it - so my point 4 is maybe moot.
Evan Hubinger
@evhub
@mosbasik The real answer is that the interactive tutorial was written by a group of non-core Coconut contributors (which is to say, not me), so I can't really comment on the particular choices that it makes. The non-interactive tutorial was written by me, but it's also pretty old and obviously non-interactive. If you wanted to make some changes to the interactive tutorial, I'd be happy to pull them in and put them up.
Peter Henry
@mosbasik
cool, thanks for the response. I'll read with an eye to how I might improve things then.
Juan Castillo
@cfuendesign
image.png

Hey! I tried installing coconut through "pypy3 -mpip install coconut" and, despite the install looking like it went well, "coconut -h" isn't recognized as a command.

I'm an absolute beginner in both pypy3 and coconut, so feel free to correct me.

Juan Castillo
@cfuendesign
Ah, running coconut -h directly from pypy3's scripts folder did the trick.
image.png
Evan Hubinger
@evhub
@cfuendesign Yeah, you need to add the scripts folder to your PATH environment variable. See: https://datatofish.com/add-python-to-windows-path/
Alternatively, you can always just do pypy3 -m coconut -h.
Ivan Cheung
@ivanmkc

Beginner here!

Looking forward to using Coconut but am stumped by something simple.

I'm trying to unpack my parameters (key, value) passed into the map function:

{"A": 1, "B": 2, "C": 3}.items() |*> map$((key, value) -> value) |> list |> print

This works but is "uglier":

{"A": 1, "B": 2, "C": 3}.items() |> map$(key_value -> key_value[1]) |> list |> print
Expected output: [1, 2, 3]
Any help is appreciated :) I'm using Python 3 btw since I know tuple deconstruction changed at one point.
Ivan Cheung
@ivanmkc
Here's another version using a statement lambda, but also not quite as nice as I'd like:
(
{"A": 1, "B": 2, "C": 3}.items() 
    |> map$(def (key_value) -> key, value = key_value; value) 
    |> list 
    |> print
)
Ivan Cheung
@ivanmkc
I know this would work, but I actually want the parameters to be named and unpacked so I can reference either of them (even though I only use "value" in this example):
{"A": 1, "B": 2, "C": 3}.items() |> map$(-> _[1]) |> list |> print
Evan Hubinger
@evhub
@ivanmkc Here are some options that you might like:
d = {"A": 1, "B": 2, "C": 3}
d.items() |> starmap$((k, v) -> v) |> list |> print
d.items() |> map$(def ((k, v)) -> v) |> list |> print
d.items() |> map$(.[1]) |> list |> print
Ivan Cheung
@ivanmkc
Thanks! This is perfect.
Thurston Sexton
@tbsexton

@GianpieroCea Saw your question about data science.

I haven't seen any but I will say that, barring the lack of LSP that keeps me mostly using coconut for prototyping in the notebook, i use coconut constantly for data science. I love what it's done for the maintainability of my code, as well.

So with that, though I've avoided using coconut for codebases that require collaboration (since not many folks can write/read it right away), I would love to start a coconut-for-data-science tutorial.

Been learning/using jupyter book and that could be a great way to do something fast and pretty. let me know if you want to join a repo where we can plan out e.g. key contents and case studies, and I can help adding code based on my irl experience.

same goes for anyone else! :)
pigs
@pigs:riot.firechicken.net
[m]

I'm trying to setup coconut inside Databricks and came across a bug when trying to use the coconut magics:

TypeError: run_cell() missing 1 required positional argument: 'raw_cell
`

However, looking at the backtrace it is clear that the positional argument was given ipython.run_cell(compiled, shell_futures=False)

Evan Hubinger
@evhub
@pigs:riot.firechicken.net Strange. Can you raise an issue and include the traceback and ipykernel version (also anything else that might help me replicate it)?
Jason O.
@puruzio
I am trying coconut as the kernel_name for Papermill and it complains like this. Is there a way to fix this? coconut3 does show up in jupyter kernelspec list.
No parameter translator functions specified for kernel "coconut3' or language 'coconut'
Evan Hubinger
@evhub
@puruzio Should be fixed if you pip install -U coconut-develop (see #658).
Jason O.
@puruzio
Thank you, but the issue still persists for some reason. Same error message.
Evan Hubinger
@evhub
@puruzio Can you put exactly what you did and what versions you were on in the linked issue?
Jason O.
@puruzio
@evhub Sure. I uninstalled the Coconut 1.6 version, and installed coconut-dev 2.0 using the command you mentioned above.
Jason O.
@puruzio
@evhub Never mind. It's working! I accidentally installed coconut outside of venv.
dincio
@dincio:matrix.org
[m]
hello all
I'm very interested in learning coconut, so I was wandering if it works with poetry
Evan Hubinger
@evhub
@dincio:matrix.org should work fine—just compile your coconut to python before you run whatever poetry commands you want to run
ShalokShalom
@ShalokShalom
Hi there
I see that Coconut has no immutable data structures - which ones do you use?
Pyrsistent seems to be the only maintained library for this use case - is this true?
ShalokShalom
@ShalokShalom
Oh, Expression had some. Do you think, the library will be 100% compatible with Coconut?
Evan Hubinger
@evhub
Coconut data types are immutable, though you're also welcome to use pyrsistent or whatever else you want in Coconut as well.
ShalokShalom
@ShalokShalom
Oh, I havent seen data types as a replacement for casual containers. Have you shown this in the documentation?
JakartaLaw
@JakartaLaw

Hi,

I think coconut is a great language. However, usually when programming in python (especially doing datascience stuff) I will use VS code and interactive cells:

# %%

print("hello")

# %%

Utilizing the iPython kernel.

Is this possible to do with the .coco extension? I have not found any solution to it yet.

Evan Hubinger
@evhub
@JakartaLaw yep—coconut has a Jupyter kernel. see: https://coconut.readthedocs.io/en/latest/DOCS.html#ipython-jupyter-support
JakartaLaw
@JakartaLaw

Thanks so much for the answer. I'm aware of the kernel, and I can get that to work. Concretely, what I am able to do is, starting the kernel, and then running cells from python files.

I.e. I have a file somefile.py in VS Code, I can run the cells:

# %%
"hello" |> print
# %%

However, if I am working from a somefile.coco, I am not able to run cells. That is, the cell above cannot be executed by Cmd+Enter.

I hope my question makes sense?

All the best!

Evan Hubinger
@evhub
just create a .ipynb with Coconut as the kernel and then open that in VS code
JakartaLaw
@JakartaLaw
Yes, I am aware, that I can do it using an ipynb/notebook. But my point is, that I would like not to do that, since ipynb is hard to chain, and use in bigger workflow situations.
Evan Hubinger
@evhub
@JakartaLaw I see. Can you open an issue for this? Also: Do you know how this feature is implemented in VS Code? Is it an extension, built-in feature, etc.?